E-learning module "Linux Basics"
Combinations of Commands
|
→ pipe. This can be used to forward the output of a command as input for another.
$ history | sort | less
→ forward the output of history
to sort
. Then forward the sorted output as input to less
.
Linux has three standard in- or output handles:
stdout
→ Standard output (e.g. the monitor).stdin
→ Standard input (e.g. the keyboard or a file).stderr
→ Standard error output.
Instead of forwarding output to another command using
|
, the output can be redirected into a file:>
→ Redirectstdout
into a file. The file is either generated or overwritten.2>
→ Redirectstderr
into a file. The file is either generated or overwritten.2>&1
→ Redirectstdout
andstderr
into a file. The file is either generated or overwritten.>>
→ Redirect output and append to a file.<
→ Redirect the input.
$ history | sort >> filename.txt
→ Append the sorted output of the command history
to the file filename.txt
.$ nano -w filename.txt
→ Edit filename.txt
.
Commands can be run in a sequence, depending on the result of the preceeding command:
&&
→ Execute the subsequent command if the preceeding command was executed successfully.||
→ Execute the subsequent command if the preceeding command failed.;
→ Execute the commands in a sequence, no matter what the results are.
$ tee
→ The output of a command can be forwarded simultaneously into a file and to standard output.
$ history | sort | tee sortiert.txt | less
→ Redirect the sorted command history
into file sortiert.txt
and forward it to less
.
![]() | The content of this e-learning module is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Germany license (CC BY-NC-SA 3.0 DE). |