Interview Prep/Linux/Packages, Shell & Text Tools

Explain pipes and redirection, including `tee` and here-strings.

BeginnerConceptPackages, Shell & Text Tools
Answer

A pipe | connects stdout of one command to stdin of the next. > overwrites, >> appends, < reads input. tee writes to a file and stdout at once, which is how you write root-owned files with sudo.

journalctl -u api | grep -i timeout | wc -l
echo "vm.swappiness=10" | sudo tee /etc/sysctl.d/99-swap.conf
grep -c x <<< "$text"      # here-string

sudo echo x > /etc/file fails because the redirection runs in your unprivileged shell.

All Linux questions Roadmap: Linux

More on Packages, Shell & Text Tools