Linux Bash have different ways to run command and get output of the command or redirect the output. In this tutorial we will look different ways to redirect commands output.
Writing Multiple Commands Same Line
Command line can be terminated with ; to write commands same line
In this example first clean command runs and after the execution ends what ever the command result is second command ls runs.
Redirect one command output to other command
To redirect one command output to the other command use |. | named as pipe. The standard output is redirected. In this example we run ls command which will print file and directory names in working directory. By using pipe we redirect ls output into sort command as input. sort as name suggests used to sorting alphabetically.
$ ls | sort bin boot dev etc home ...
Check Previous Command Exit Status
When commands are chained together commands exit status which means the result of the command is important. For example copy a folder and change directory into new folder may chained together. If the the first command cannot be completed there is no need to run second command.
$ ls && ls bin boot dev etc home lib lib64 lost+found media mnt opt proc root run sbin srv sys tmp usr var bin boot dev etc home lib lib64 lost+found media mnt opt proc root run sbin srv sys tmp usr var