Linux Pipelines, xargs, split, diff, and Practical Recipes Cheat Sheet

Build practical shell pipelines, batch commands with xargs, compare files, and split or reshape data.

View
StandardDetailedCompact
Export
Copy the compact sheet, download it, or print it.
Download
`D` dense toggle · `C` copy all

xargs

Turn input lines into command arguments safely and efficiently.

Pass stdin items as arguments

Convert lines into command arguments.

bashANYxargsarguments
bash
printf '%s
' file1 file2 file3 | xargs rm

`xargs` is often used when one command produces a list of items and another command needs them as arguments.

Use null-delimited input

Handle spaces and special characters safely.

bashANYxargsnull-delimitedsafety
bash
find . -type f -print0 | xargs -0 rm

Prefer `-print0` plus `xargs -0` for safe file-name handling.

Run one item per command

Invoke the command once per input line.

bashANYxargsbatching
bash
printf '%s
' a b c | xargs -n 1 echo item:

`-n 1` is useful for debugging and command isolation.

Use a placeholder in the command

Insert each item into a custom position.

bashANYxargsplaceholder
bash
printf '%s
' app1 app2 | xargs -I{} kubectl logs {}

`-I{}` substitutes each input item wherever the placeholder appears.

Run commands in parallel

Process multiple input items concurrently.

bashANYxargsparallel
bash
printf '%s
' url1 url2 url3 | xargs -n 1 -P 4 curl -I

`-P` can speed up independent network or file operations.

split and csplit

Break large files into smaller pieces.

Split a file by line count

Create chunks of 1000 lines each.

bashANYsplitlines
bash
split -l 1000 bigfile.txt chunk_

Useful for processing or shipping large text files in smaller pieces.

Split a file by size

Create 50 MB chunks.

bashANYsplitsize
bash
split -b 50M archive.log log_

Size-based splitting is common when moving large files through constrained systems.

Use numeric suffixes

Create chunks with numeric names.

bashANYsplitnaming
bash
split -d -l 1000 bigfile.txt chunk_

Numeric suffixes can be easier to sort and reason about than alphabetic ones.

Split using regex boundaries

Break a file at repeated pattern boundaries.

bashANYcsplitregexsections
bash
csplit -f part_ report.txt '/^SECTION:/' '{*}'

`csplit` is powerful when file structure is driven by heading markers or section delimiters.

diff, cmp, and patch-Oriented Comparison

Compare files and inspect textual differences.

Show unified diff

Compare two text files with context.

bashANYdiffcompare
bash
diff -u old.conf new.conf

Unified diff format is the most common comparison output for reviews and patches.

Compare directories recursively

Find differences across two directory trees.

bashANYdiffdirectoriesrecursive
bash
diff -ruN dir1 dir2

A common way to inspect configuration or source tree differences.

Compare files byte by byte

Detect exact byte-level differences.

bashANYcmpbinary
bash
cmp file1.bin file2.bin

`cmp` is simpler than diff when you only need to know whether files differ and where the first difference occurs.

Show side-by-side diff

Compare files in two visual columns.

bashANYsdiffcompare
bash
sdiff file1.txt file2.txt

Side-by-side comparison is useful for quick visual inspection.

Practical Recipes

Real-world pipelines for logs, configs, code, and reports.

Show most frequent error messages

Count and rank repeated lines in a log.

bashANYrecipelogscounting
bash
grep ERROR app.log | sort | uniq -c | sort -nr | head

One of the most useful Linux text-processing recipes for logs and incident triage.

Show effective config lines only

Remove comments and blank lines from a config file.

bashANYrecipeconfiggrep
bash
grep -Ev '^[[:space:]]*($|#)' nginx.conf

This makes configuration files much easier to inspect quickly.

Sum a CSV column

Compute the total of a numeric CSV field after skipping the header.

bashANYrecipecsvawk
bash
awk -F, 'NR>1 {sum += $3} END {print sum}' sales.csv

Great for quick ad hoc analysis without opening a spreadsheet.

Find the largest files in a tree

List the top 20 largest files by size.

bashANYrecipefilessize
bash
find . -type f -printf '%s %p
' | sort -nr | head -20

Useful for disk cleanup and packaging investigations.

Extract unique IP addresses

Print unique IPs from a log file.

bashANYrecipelogsip-addresses
bash
grep -Eo '([0-9]{1,3}.){3}[0-9]{1,3}' access.log | sort -u

A fast shell approach for rough IP extraction from logs.

Replace text across many files safely

Search files first, then edit in place.

bashANYreciperefactorxargssed
bash
rg -l 'old-service-name' . | xargs sed -i 's/old-service-name/new-service-name/g'

A practical codebase refactor pattern when you understand the scope of the match set.

Recommended next

No recommendations yet.