Linux / Bash
Beginner
1 min read
Viewing and Editing File Content
Example
# Display entire file
cat /etc/hosts
# Display with line numbers
cat -n /etc/os-release
# Paginate through a large file
less /var/log/syslog
# Inside less: /pattern search | n next | q quit | G end | g start
# Show first 10 lines (default)
head /var/log/syslog
# Show first 20 lines
head -n 20 /var/log/syslog
# Show last 10 lines
tail /var/log/syslog
# Follow a log file in real time
tail -f /var/log/auth.log
# Follow and show last 50 lines
tail -n 50 -f /var/log/syslog
# Count lines, words, characters
wc /etc/passwd
wc -l /etc/passwd # lines only
# Identify file type
file /bin/bash
# /bin/bash: ELF 64-bit LSB pie executable, x86-64 ...
file image.png
# image.png: PNG image data, 800 x 600, 8-bit/color RGB
# Detailed file metadata
stat /etc/hosts
# Edit with nano (beginner-friendly)
nano /tmp/test.txt
# Ctrl+O save | Ctrl+X exit
# Quick vim cheat-sheet (as comments)
# vim file.txt
# i — enter insert mode
# Esc — return to normal mode
# :w — save
# :q — quit
# :wq — save and quit
# :q! — quit without saving
# dd — delete current line
Related Resources
Linux / Bash Reference
Complete tag & property list
Linux / Bash How-To Guides
Step-by-step practical guides
Linux / Bash Exercises
Practice what you've learned
More in Linux / Bash