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

Output a file to standard output.

bashANYcatview
bash
cat /etc/hosts

Open file with pager

Scroll through a file interactively.

bashANYlessviewpager
bash
less /var/log/syslog

Show first 20 lines

Preview top of file.

bashANYheadview
bash
head -20 app.log

Follow appended log lines

Watch file growth in real time.

bashANYtaillogsfollow
bash
tail -f /var/log/nginx/access.log

Create, touch, truncate

Create empty file or update timestamp

Touch a file path.

bashANYtouchtimestamps
bash
touch notes.txt

Empty a file without deleting it

Reset file length to zero bytes.

bashANYtruncatelogs
bash
truncate -s 0 app.log

Write output to file and stdout

Save command output while still printing it.

bashANYteeoutput
bash
echo 'hello' | tee hello.txt

Compare and Combine

Show unified diff

Compare two files in patch-friendly format.

bashANYdiffcompare
bash
diff -u old.conf new.conf

Compare files byte-by-byte

Find first differing byte.

bashANYcmpcomparebinary
bash
cmp file1.bin file2.bin

Compare sorted line sets

Show common and unique lines between two sorted files.

bashANYcommcomparelines
bash
comm file1.sorted file2.sorted

Concatenate multiple files

Combine files into one output file.

bashANYcatcombine
bash
cat part1.txt part2.txt > combined.txt

Split and Verify

Split file into chunks

Split a large file into 100 MB parts.

bashANYsplitlarge-files
bash
split -b 100M archive.tar.gz archive.part.

Split file by pattern

Split a file at regex boundaries.

bashANYcsplitsplittext
bash
csplit -f section- doc.txt '/^# /' '{*}'

Create SHA256 checksum

Compute a checksum for integrity verification.

bashANYsha256sumchecksum
bash
sha256sum file.iso > file.iso.sha256

Verify SHA256 checksum

Check file contents against checksum list.

bashANYsha256sumverify
bash
sha256sum -c file.iso.sha256

More in Linux Text and File Operations

No other published sheets yet.

Recommended next

No recommendations yet.