Read files with cat/less, edit with nano, search with grep and find, and chain commands with pipes.
Files: Reading, Writing, Searching is one of the most important topics in Linux in 5 Days. This lesson builds the foundation you need before moving to more advanced concepts — take time with each example and run the code yourself.
cat file.txt # print entire file less file.txt # paginated view (q to quit) head -n 20 file.txt # first 20 lines tail -n 20 file.txt # last 20 lines tail -f /var/log/syslog # follow in real-time
nano file.txt # Ctrl+O = save # Ctrl+X = exit # Ctrl+W = search # Ctrl+K = cut line # Ctrl+U = paste
grep 'error' app.log # lines containing 'error' grep -i 'error' app.log # case-insensitive grep -r 'TODO' ./src/ # recursive search grep -n 'error' app.log # show line numbers grep -v 'DEBUG' app.log # lines NOT matching grep -E 'error|warning' app.log # regex: error OR warning grep -c 'error' app.log # count matching lines
find . -name '*.txt' # by name
find . -name '*.log' -newer config.txt # modified after
find /var/log -size +10M # files over 10MB
find . -type f -name '*.py' -exec grep -l 'import os' {} \; # | passes output of one command as input to the next cat app.log | grep 'error' | wc -l # count error lines ls -la | sort -k5 -n # sort by file size ps aux | grep nginx # find nginx processes cat /etc/passwd | cut -d: -f1 | sort # list usernames, sorted
Before moving on, make sure you can answer these without looking: