Connect commands into pipelines — redirect output into files, send output and errors where you want, pipe one command into the next, then search with grep and slice, sort, count, and transform text.
By default a command prints its result to the screen ("standard output"). The > operator redirects that into a file instead — but it overwrites the file completely, so use it carefully. >> appends to the end instead, which is the safe choice when you want to add to a file rather than replace it.
Send output INTO a file (overwrites whatever was there!)
echo "first line" > notes.txtAppend to the end of the file instead (safe — keeps existing content)
echo "second line" >> notes.txtConfirm what's in the file now
cat notes.txtEvery command actually has two output streams: normal results (stdout, channel 1) and error messages (stderr, channel 2). Keeping them apart lets you save real output while still seeing errors — or silence errors you do not care about. 2> redirects only errors; 2>/dev/null throws them away (/dev/null is the system's trash can).
Send errors to their own file, separate from normal output
find / -name "*.conf" 1>found.txt 2>errors.txtThe pipe | is the heart of the Linux command line: it feeds the output of one command straight into the next as its input, with no temporary file in between. You chain small, single-purpose tools into exactly the result you want. Read a pipeline left to right, like a sentence.
List files, then page through the result
ls -la /etc | lessCount how many files are in a folder (wc -l counts lines)
ls /usr/bin | wc -lShow all running processes, then keep only the lines mentioning "ssh"
ps aux | grep sshgrep prints only the lines that match a pattern — the workhorse for digging through files and logs. -i ignores case, -r searches a whole folder recursively, -n adds line numbers, and -v inverts the match to show lines that do NOT match. It is most powerful at the end of a pipe, filtering another command's output.
Lines in a file that mention "error" (case-insensitive)
grep -i error /var/log/syslogSearch every file under a folder, showing file name + line number
grep -rn "TODO" project/Filter another command's output (only ssh-related processes)
ps aux | grep sshInvert: every line that does NOT contain "#" (skip comments)
grep -v "#" /etc/hostsA handful of small tools combine to reshape any text. cut pulls out columns, sort orders lines (sort -u also removes duplicates), uniq -c counts repeats, and tr swaps or deletes characters. This classic pipeline — cut a column, sort it, count uniques, sort by count — answers "what are the most common values?" for almost any data.
Pull the 1st field of each line, using ":" as the separator (usernames)
cut -d: -f1 /etc/passwdSort lines alphabetically; -u also drops duplicates
sort -u names.txtClassic combo: which login shells are used, and how often?
cut -d: -f7 /etc/passwd | sort | uniq -c | sort -rnTranslate characters: turn lowercase into uppercase
echo "hello" | tr 'a-z' 'A-Z'