Redirect command application and its syntax under Linux operating system

  
                  

1. Control of standard input

Syntax: Command The file sends the execution result of the command to the specified file.

Example:

ls -l > list Writes the result of executing the "ls -l" command to the file list.

Syntax: Command>! The file sends the execution result of the command to the specified file, and overwrites if the file already exists.

Example:

ls -lg >! list Overwrites the result of executing the "ls - lg" command into the file list.

Syntax: Command>& File Writes any information generated on the screen when the command is executed to the specified file.

Example:

cc file1.c >& error Write any information generated when compiling the file1.c file to the file error.

Syntax: Command>> The file appends the results of the command execution to the specified file.

Example:

ls - lag >> list Appends the result of executing the "ls - lag" command to the file list.

Syntax: Commands>>& Files Append any information generated on the screen when the command is executed to the specified file.

Example:

cc file2.c >>& error Append any information generated by the screen when compiling the file2.c file to the file error.

3. Command syntax

command > filename Redirect standard output to a new file

command >> filename Redirect standard output to a file Medium (append)

command 1 > fielname redirects standard output to a file

command > filename 2>&1 redirects standard output along with standard error to a

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 along with standard error to a file (append)

command filename2 Put the command command with the filename file as the standard input to filename2 File as standard output

command &m redirects standard output to file descriptor m

command

Copyright © Windows knowledge All Rights Reserved