Linux & shell: Shell operators (how combinations work)
6 Linux & shell commands: Shell operators (how combinations work). Click a command to see what each part does.
Linux & shell: Shell operators (how combinations work)Index
- Whole sheet251
- Navigate & list13
- Create, copy, move, delete13
- View & compare files9
- Permissions & ownership31
- Help & shell basics11
- Users & groups6
- Install packages7
- Package & software versions29
- System info9
- Network basics & SSH10
- Zip & compress4
- Shell operators6
- Processes6
- Files & search8
- Text processing pipelines4
- Disk3
- Network5
- Services & logs6
- Archives & copying4
- Firewall7
- Scheduling: cron & systemd timers6
- Storage, mounts & LVM10
- Kernel, hardware & limits8
- Performance & tracing10
- TLS & certificates8
- Packet capture & network debugging10
- Terminal tools8
Shell operators (how combinations work)6
cmd1 | cmd2Send the output of one command into anotherWhat each part does
cmd1first command; its normal output (stdout) is captured|pipe: stdout of the left command becomes the input (stdin) of the right onecmd2second command, reads that input (e.g. grep, sort, head)
cmd > out.txt; cmd >> out.txtSave output to a file (overwrite / append)What each part does
>redirect stdout to a file, creating it or truncating it to empty first;run the next command after the first, whatever its result>>append stdout to the end of the file (creates it if missing)
cmd > out.log 2>&1Capture errors together with normal outputWhat each part does
> out.logstdout (file descriptor 1) goes to out.log2>&1make stderr (fd 2) point where stdout points. Order matters: it must come after > out.log
Tip Short bash form: cmd &> out.log
make build && make deploy || echo "failed"Run the next command only if the previous one succeeded / failedWhat each part does
make buildfirst command&&run the next command only if the previous exited with code 0 (success)make deployruns only after a successful build||run the next command only if the previous exited non-zero (failure)echo "failed"fallback message
kill $(pgrep -f <name>)Use the output of a command as an argumentWhat each part does
killsend a signal (TERM by default) to process IDs$( … )command substitution: run the inner command and paste its output herepgrep -f <name>print PIDs whose full command line matches <name>
cat <list-file> | xargs -r -n 1 <cmd>Pass input lines as arguments to another commandWhat each part does
cat <list-file>print the file (one item per line)|pipe into xargsxargsbuild and run command lines from its input-rdon't run the command at all if the input is empty (GNU xargs)-n 1one input item per command invocation<cmd>the command to run with each item appended
Nothing matches.
My DevOps Playbook by Angelo John Calleja