How to redirect linux commands
Editor to share with you how to redirect the linux command, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
1. Control of standard input
Syntax: the command file sends the execution results of the command to the specified file.
For example: ls-l > list writes the result of the "ls-l" command to the file list.
Syntax: command >! The file sends the execution result of the command to the specified file, and if the file already exists, it is overwritten.
For example: ls-lg >! List overwrites the results of the "ls-lg" command to the file list.
Syntax: command > & File writes any information generated on the screen when the command is executed to the specified file.
For example: cc file1.c > & error writes any information generated when compiling the file1.c file to the file error.
Syntax: command > > file appends the result of command execution to the specified file.
For example: ls-lag > > list appends the result of executing the "ls-lag" command to the file list.
Syntax: command > > & File appends any information generated on the screen when the command is executed to the specified file.
For example: cc file2.c > > & error appends any information generated by the screen when compiling the file2.c file to the file error.
2 command syntax
Command > filename redirects standard output to a new file
Command > > filename redirects standard output to a file (append)
Command 1 > fielname redirects standard output to a file
Command > filename 2 > & 1 redirect standard output and standard error to a file together
Command 2 > filename redirects standard error to a file
Command 2 > > filename redirects standard output to a file (append)
Command > > filename 2 > & 1 redirect standard output and standard error to a file (append)
Command filename2 uses filename files as standard input and filename2 files as standard output for command commands.
Command & m redirects standard output to the file descriptor m
The above is all the contents of the article "how to redirect linux commands". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!