3 Basic Commands and Simple Shell Scripts Once you have your first Red Hat Enterprise Linux rhel


Understanding IO redirection on the command line



Download 1.85 Mb.
View original pdf
Page13/67
Date26.02.2024
Size1.85 Mb.
#63678
1   ...   9   10   11   12   13   14   15   16   ...   67
Pablo Iranzo Gómez, Pedro Ibáñez Requena, Miguel Pérez Colino, Scott McCarty - Red Hat Enterprise Linux 9 Administration-Packt Publishing (2022) -chap 3 82 - 180
Understanding IO redirection on the command line
We have already run several commands to ascertain information about the system, such as listing files with ls, and we have got some information, or the output, from the running command, including, for example, filenames and file sizes. That information (or output) can be useful, and we want to be able to work with it, store it, and manage it properly.
When talking about command output and also input, there are three sources or targets for them that need to be understood STDOUT: Also known as Standard Output, this is where commands will put their regular messages to provide information on what they are doing. Ina terminal, on an interactive shell as with the ones we are using so far, this output will show onscreen. This will be the main output managed by us STDERR: Also known as Standard Error, this is where the commands will put their error messages to be processed. In our interactive shells, this output will also be shown onscreen together with the standard output unless we specifically redirect it STDIN: Also known as Standard Input, this is where the commands get data to be processed.
We will cover these in the following paragraphs to understand them better.
The way that the command input and output are used is defined by the following operators |: Ab pipeb operator is used to get the output from one command and make it the input of the next command. It channels data from one command to another >: Ab redirectb operator is used to redirect the entire output of a command into a file. If the file exists, it will be overwritten. Be careful with this, as you might clobber a file that could be important <: Reverse redirect can be applied to use a file as the input fora command. Using it won’t delete the file that is used as input >>: Ab redirect and add
operator is used to append the output of a command into a file. If the file does not exist, it will be created with the output provided to it 2>: Ab redirect STDERR
operator will only redirect the output sent to the error message handler. (Note that no space should be included between 2 and > in order for this to work!)

Basic Commands and Simple Shell Scripts 1>: Ab redirect STDOUT operator will only redirect the output sent to the standard output and not to the error message handler >&2: Ab redirect to STDERR operator will redirect the output to the standard error handler >&1: Ab redirect to STDOUT operator will redirect the output to the standard output handler.
To better understand these, we will go through several examples in this section and the following one.
Let’s get a list of files and put it in a file. First, we list the files in var, using them option to separate entries with commas:

Download 1.85 Mb.

Share with your friends:
1   ...   9   10   11   12   13   14   15   16   ...   67




The database is protected by copyright ©ininet.org 2024
send message

    Main page