When you execute a shell command line in Linux, you usually open three standard files, standard input files (stdin), which usually correspond to the terminal's keyboard; standard output files (stdout) and standards. Error file (stderr), both of which correspond to the screen of the terminal. The process will get the input data from the standard input file, output the normal output data to the standard output file, and send the error information to the standard error file.
The standard input (stdin) file code is 0, the standard output (stdout) file code is 1, and the standard error (stderr) file code is 2. A major feature of Linux is that standard input/output can be redirected.
First, the output redirection output redirection refers to redirecting the standard output or standard error of the command (or executable program) to the specified file. Use the > symbol.
Example: 1, # echo "hellohello" > 1.txt There is no output on the screen at this time, the content of the 1.txt file generated in the current directory is the echo output statement.
Second, input redirection Input redirection refers to redirecting the standard input of a command (or executable program) to a specified file. That is, the input can come from a specified file without coming from the keyboard. Use the < symbol.
Example: 1, # wc -l < /etc/passwd counts the number of lines in the /etc/passwd file. The standard input for the wc command comes from the /etc/passwd file.
Three, turn to the additional use output to redirect to a file, if the file already exists, it will first clear the contents of the file, and then write the information. If you want to keep the contents of the original file, you can use the >> symbol to add an effect.
Example: 1, # echo "test1" > 2.txt# echo "test2" >> 2.txt# cat 2.txttest1test2
4. Combination use steering The combination of input and steering outputs enables more functionality.
Example: 1, # cat < 1.txt > 3.txt specifies that the standard input of the cat command comes from 1.txt, and the standard output is diverted to 3.txt. The result is the same as 3.txt and 1.txt.
2, #cat > 4.txt < 3.txt specifies that the standard output of the cat command is diverted to 4.txt, and the standard input is from 3.txt. The result is the same as 4.txt and 3.txt.
The effect is the same from the above two examples, indicating that there is no order for standard input/output redirection.
3,<< Symbol# cat > 6.sh << EOF> #! /bin/bash> echo "hello world!"> EOF Description: > The standard output is redirected to 6.sh, and the standard input is still from the default keyboard. The << symbol is used to define the terminator. Any character can be used as a terminator, generally defined as EOF. Here, when input to EOF, the input is over.
5,>/dev/null 2>&1 & What does it mean? Often seen in the shell script: > /dev /null 2 > & 1 & Description: 1) /dev/null stands for empty device. 2)>/dev/null means to redirect the standard output after the previous command is executed, all of which are thrown into the empty device. 3) & means equivalent, 2>&1 means that 2's output redirection is equivalent to 1, redirecting standard error to standard output, since standard output has been redirected to /dev/null, standard error is also Will redirect to /dev/null. 4) The last & indicates that the background is running.
Executing programs are called processes. When a program is stored in an executable file and is runni
nmap is a network port scanner. Its main function is to check a group of target hosts to see which
Today I made a simple ftp server for the company, and it was the first time I actually did the serv
When I maintain the blog file today, I found that I cant delete some folders and files in the websi
Share the method of viewing dd progress
Precise timing and hibernation under Linux
Teach you completely free self-built Linux firewall
Virtualbox command line sharing CentOS directory
Linux using NTP service management /synchronization server time
The 20 advantages of Linux and Windows
Linux shell string operation (length, find, replace) detailed
How to do a lot of removable disks when the win7 system computer is plugged into a USB flash drive
Hidden partition Quest in Windows 7 - related to system startup
What should I do if the win8.1 system can't sleep?
The difference between CPU standard voltage and low voltage in notebook win7 system
Win8 dedicated software for girls
Win10 closes Cortana voice assistant method
Let you easily learn to install Windows XP operating system
Microsoft: Win10 Preview 10547 is being tested in