Linux Text and File Operations Cheat Sheet

Core Linux commands for viewing files, comparing content, touching, truncating, splitting, and combining files.

View
StandardDetailedCompact
Export
Copy the compact sheet, download it, or print it.
Download
`D` dense toggle · `C` copy all
## Viewing Files
Print file content
cat /etc/hosts

# Output a file to standard output.

Open file with pager
less /var/log/syslog

# Scroll through a file interactively.

Show first 20 lines
head -20 app.log

# Preview top of file.

Follow appended log lines
tail -f /var/log/nginx/access.log

# Watch file growth in real time.

## Create, touch, truncate
Create empty file or update timestamp
touch notes.txt

# Touch a file path.

Empty a file without deleting it
truncate -s 0 app.log

# Reset file length to zero bytes.

Write output to file and stdout
echo 'hello' | tee hello.txt

# Save command output while still printing it.

## Compare and Combine
Show unified diff
diff -u old.conf new.conf

# Compare two files in patch-friendly format.

Compare files byte-by-byte
cmp file1.bin file2.bin

# Find first differing byte.

Compare sorted line sets
comm file1.sorted file2.sorted

# Show common and unique lines between two sorted files.

Concatenate multiple files
cat part1.txt part2.txt > combined.txt

# Combine files into one output file.

## Split and Verify
Split file into chunks
split -b 100M archive.tar.gz archive.part.

# Split a large file into 100 MB parts.

Split file by pattern
csplit -f section- doc.txt '/^# /' '{*}'

# Split a file at regex boundaries.

Create SHA256 checksum
sha256sum file.iso > file.iso.sha256

# Compute a checksum for integrity verification.

Verify SHA256 checksum
sha256sum -c file.iso.sha256

# Check file contents against checksum list.

More in Linux Text and File Operations

No other published sheets yet.

Recommended next

No recommendations yet.