Ravindra BagaleCourses & study guides

Chapter 3: Linux Basic Commands

3.4 Viewing files

Command Use
cat file Print entire file
less file Scroll page by page (Space next, b back, /word search, q quit)
more file Older, simpler pager
head -n 20 file First 20 lines
tail -n 20 file Last 20 lines
tail -​f /​var/​log/​nginx/​access.​log Follow a log live (Ctrl+C to stop)
wc -l file Count lines (-w words, -c bytes)
diff a b Show differences between two files
cat /etc/os-release          # which Linux distribution and version?
head -5 /etc/passwd
sudo tail -f /var/log/messages      # Amazon Linux / CentOS system log
sudo tail -f /var/log/syslog        # Ubuntu system log