files
Working with files and directories
-
cat
Tested cat examples: joining rotated logs, numbering lines with -n and -b, and using cat -A to find the carriage returns stopping a script from running.
-
cd
Tested cd examples: why no program could do this job, what cd - and $OLDPWD hold, and the two different answers cd .. gives under a symlink.
-
chmod
Tested chmod examples: numeric and symbolic modes, recursive changes, setuid/setgid/sticky bits, permission audits, and troubleshooting.
-
chown
Tested chown examples: setting owner and group, -R over a tree, why a glob misses the dotfiles, and the reason you cannot give away a file you own.
-
cp
Tested cp examples: copying files and whole trees, why a second cp -r nests the directory inside itself, and what -a preserves that a plain copy loses.
-
df
Tested df examples: reading the output, asking about the filesystem a path is on, choosing columns and units, and the full disk that still reports free space.
-
diff
Tested diff examples: unified and context formats, directory comparison, ignoring whitespace or case, and generating a patch file with patch to apply it.
-
du
Tested du examples: -sh totals, --max-depth, apparent size versus allocated blocks, sparse files, hard links, excludes, and sorting the output.
-
find
Tested find examples: name and type filters, size and age, permissions, -exec vs -delete, and safe scripting patterns.
-
head
Tested head examples: -n and -c, multiple files and their headers, the -n -N form that drops the last lines, and stopping a pipeline early.
-
less
Tested less examples: the keys that move and search, why a piped less turns into cat, and how lesspipe lets it open a compressed file directly.
-
ln
Tested ln examples: why a symlink's target is resolved from the link's own directory, what a hard link shares, and the -n that stops a relink landing inside.
-
ls
Tested ls examples: the long format column by column, hidden files, sorting by time and size, symlinks, time styles, and why piped output looks different.
-
mkdir
Tested mkdir examples: the two separate things -p does, why an existing file still fails it, and why -m never reaches the parents it invents.
-
mv
Tested mv examples: renaming and moving files, why a second mv nests a directory inside itself, and what changes once the destination is another filesystem.
-
rm
Tested rm examples: -r and -rf, why a directory's permissions decide what you may delete, and three ways a command removes more than the files you named.
-
tar
Tested tar examples: create, list, and extract archives, back up incrementally, stream over ssh, and verify integrity.
-
touch
Tested touch examples: creating a file without truncating an existing one, setting access and modification times separately, and the timestamp nothing can set.
-
wget
Tested wget examples: downloading, resuming, retries, authentication, recursive mirroring, and scripting with exit codes.
-
xargs
Tested xargs examples: batching with -n, placeholders with -I, NUL-separated input from find -print0, parallel runs with -P, and what its exit codes mean.
-
Bulk rename a batch of files
Rename many files at once with a plain bash loop, safely handling spaces and previewing changes before committing.
-
Copy files between two machines over SSH
Transfer a file or directory tree between two machines with scp or rsync, and resume an interrupted transfer without starting over.
-
Find and replace across many files
Replace a string across a directory tree with grep -rl and sed -i, safely for filenames containing spaces, with a dry run and a backup first.
-
Find files without the permission denied noise
Why 2>/dev/null is the wrong fix for find's permission denied errors, and what -readable -prune does instead, including what happens to the exit status.