Files and directories cheat sheet
The most useful files and directories commands on one printable page, every line checked by running it.
basename Strip the directory part (and optionally a suffix) from a path, leaving the file name.
cd Change the shell's current working directory.
chown Change the owner and/or group of files and directories.
cp Copy files and directories, optionally keeping their timestamps, permissions and links.
cp notes.txt notes-backup.txt ls -l notes*- Copy a file output
mkdir backup cp todo.txt notes.txt backup/ ls backup- Copy files into a directory output
cp -r src src-copy find src-copy- Copy a whole directory output
cp -a . ../demo-copy ls -l ../demo-copy/link-to-notes- Copy a tree exactly, links included output
dirname Strip the last component from a path, leaving the directory part.
file Guess what kind of data a file holds by looking at its contents, not its name.
install Copy files into place and set their mode, owner and group in one step; can also create directories.
mkdir -p bin install scripts/greet.sh bin/greet ls -l bin/greet bin/greet installer- Install a script as an executable output
mkdir conf install -m 644 data/settings.conf conf/ install -m 600 .env conf/ ls -lA conf- Install a config file with a specific mode output
install -d -m 750 deploy/releases deploy/shared/logs ls -ld deploy/releases deploy/shared deploy/shared/logs- Create directories with a given mode output
install -D -m 644 src/lib/helpers.py dist/lib/python/helpers.py find dist- Copy into a path that does not exist yet output
ln Make links between files, symbolic (-s) or hard.
ln -s data/config.json config.json ls -l config.json head -3 config.json- Create a symbolic link output
ln todo.txt tasks.txt ls -li todo.txt tasks.txt- Create a hard link output
ln -sr data/users.csv src/users.csv ls -l src/users.csv head -2 src/users.csv- Let ln compute the relative path output
ln -s logs/app.log current.log ln -sfn logs/error.log current.log ls -l current.log- Repoint an existing symlink output
ls List the contents of directories, or the details of individual files.
mkdir Create directories, optionally with all missing parents.
mkdir reports ls -ld reports- Create a directory output
mkdir -p build/output/logs mkdir -p build/output/logs find build- Create a whole path with -p output
mkdir -p webapp/{src/{api,ui},tests,docs} tree webapp- Lay out a project tree in one command output
mkdir -m 700 secrets ls -ld secrets- Create a private directory output
mktemp Create a temporary file or directory with a unique, unpredictable name and print that name.
mv Move or rename files and directories.
mv todo.txt tasks.txt ls *.txt- Rename a file output
mkdir archive mv logs/app.log.1 logs/error.log archive/ ls archive logs- Move files into a directory output
mv -n todo.txt notes.txt ls todo.txt notes.txt- Refuse to overwrite with -n output
for f in report-*.txt; do mv -- "$f" "${f%.txt}.md" done ls report-*- Rename many files by pattern output
pwd Print the full path of the current working directory.
readlink Print where a symbolic link points, or with -f the fully resolved path of any file.
realpath Print the absolute, canonical path of a file, with symlinks, . and .. resolved.
rm Delete files, and with -r whole directory trees. There is no undo.
rmdir Remove empty directories, and refuse if they are not empty.
stat Show a file's metadata (size, permissions, owner, inode, timestamps), or print chosen fields in your own format.
touch Update a file's timestamps, creating it empty if it does not exist.
touch new.txt ls -l new.txt- Create an empty file output
ls -l todo.txt touch todo.txt ls -l todo.txt- Bump the modification time of an existing file output
touch -d "2025-12-31 23:59" report.txt ls -l --time-style=long-iso report.txt- Set a specific date and time output
cp notes.txt notes-copy.txt touch -r notes.txt notes-copy.txt ls -l notes.txt notes-copy.txt- Copy timestamps from another file output
tree Draw a directory and everything below it as an indented tree.
From https://opscape.vip/cheatsheets/files/ · checked 2026-10-31