cmd > file.txt cmd >> file.txt cmd < file.txt cmd 2> file.txt cmd > file.txt 2>&1 cmd1 | cmd2 cmd1 2>&1 | cmd2 three gotchas: 1. cmd file.txt > file.txt will delete the contents of file.txt some people use set -o noclobber (in bash/zsh) to avoid this But I just have "never read from and redirect to the same file" seared into my memory. 2. sudo echo blah > /root/file.txt doesn't write to /root/file.txt as root. Instead, do: echo blah | sudo tee /root/file.txt or sudo sh -c 'echo blah > /root/file.txt' 3. cmd 2>&1 > file.txt doesn't write both stdout and stderr to file.txt. Instead, do: cmd > file.txt 2>&1 panel 3: cat vs < I almost always prefer to do: cat file.txt | cmd instead of cmd < file.txt it usually works fine & it feels better to me using cat can be slower if it's a GIANT file though panel 4: &> and &| some shells support &> and &| to redirect/pipe both stdout and stderr (also some shells use |& instead of &|)
https://cdn.masto.host/socialjvnsca/media_attachments/files/114/717/426/615/255/898/original/6eb25d19670f06b2.png