mjl.
← All articles

Linux Shell Pipelines, Redirection, and Archives

linuxshellarchivesscp

Pipelines let one command process another command’s output. Redirection lets you choose where output and errors go. These mechanisms are used repeatedly in the networking and container articles.

Pipes and redirection

journalctl -u ssh | grep -i failed
printf '%s\n' one two three > values.txt
printf '%s\n' four >> values.txt
command-that-may-fail 2> errors.log
command > output.log 2>&1

Use > when replacing a file and >> when appending. A pipeline’s final result may hide an earlier failure; for scripts, consider Bash’s set -o pipefail.

Archives

tar -czf config-backup.tar.gz /etc/ssh
tar -tzf config-backup.tar.gz
mkdir restore-test
tar -xzf config-backup.tar.gz -C restore-test

Inspect an archive before extracting it, especially when it came from another system. Extract into a temporary directory when you are unsure which paths it contains.

Secure transfer

scp config-backup.tar.gz user@server:/tmp/
scp user@server:/tmp/config-backup.tar.gz .

scp uses SSH. It authenticates the remote host and user, but it does not replace backups, checksums, or appropriate file permissions. Follow Linux SSH and Secure File Transfer for key authentication and hardening.

Verification and cleanup

sha256sum config-backup.tar.gz
rm -- config-backup.tar.gz

Do not run rm -rf against a path assembled from an unchecked variable. Confirm pwd and the exact target before deleting anything.