Files
-
cat — print a whole file
The cat command prints a file's contents to the terminal and joins several files into one stream.
5 mincatcat -ncat -A -
mkfs — create a filesystem
The mkfs command creates an empty ext4 or xfs filesystem on a partition; the old data on it becomes unreachable.
7 minlsblk -fmkfs.ext4mkfs.ext4 -L -
/proc: processes and the kernel as files
/proc is a filesystem where the kernel shows processes (/proc/<pid>) and its own state: memory, load, parameters.
11 minlsgrep -Els -l -
Basic file commands
Navigation and files — ls, cd, cp, mv, rm, cat, less, head, tail, terminal copy-paste.
8 minls -lahcd dirpwd -
Mounting and fstab
Mounting filesystems: the mount command, persistent mounts in /etc/fstab, UUIDs and options.
7 minlsblk -ffindmntblkid -
File permissions
The Unix permission model — read/write/execute, owner/group/other, special bits.
6 minls -lnamei -lchmod -
cd — changing directory
Moving around the filesystem: cd, cd -, cd ~, cd .., pushd/popd, CDPATH.
4 mincd dircdpushd dir -
ls — list directory contents
The ls command lists files and directories with permissions, owner, size and modification time, hidden ones too.
6 minlsls -lls -la -
mkdir — creating directories
Creating directories: -p (with parents), -m (permissions right away), brace expansion, rmdir.
3 minmkdir -pmkdir -mrmdir empty -
mc — a terminal file manager4 min
A two-panel file manager for the terminal: navigation, copying, an editor, SFTP.
-
stat — file metadata
Full file information — size, permissions, owner, timestamps (atime/mtime/ctime), inode.
4 minstat filestat -cls -lc -
Loop device — a file as a disk
A loop device shows a regular file to the system as a disk: you can partition, format and mount it.
5 mintruncate -slosetup -flosetup -fP -
file — determining file type
Figuring out what's inside a file (text, ELF, archive, image) by content, not by extension.
3 minfile ffile -ifile -b -
namei — permissions at every step of a path
The namei command walks a path part by part and shows the type, mode and owner of each directory down to the file.
5 minnamei -lnamei -mnamei -o -
cp — copy files and directories
The cp command copies files and directories, with overwrite prompts, preserved permissions and times, recursively.
5 mincpcp -rcp -a -
mv — move or rename
The mv command renames a file or directory and moves it elsewhere; it silently replaces an existing target.
5 minmvmv projectmv -i -
rm — remove files and directories
The rm command deletes files and directories at once, with no trash; -i and -I ask first, -r removes a tree.
6 minrmrm -irm -I -
ln — symbolic and hard links
Symlinks (ln -s) and hard links: how they differ, when to use which, common mistakes with relative paths.
4 minln -sln -sfreadlink -f -
test, [ ] and [[ ]] — checking conditions7 min
test and [ ] check a file, a string or a number and answer with a code: 0 is yes, 1 is no; [[ ]] is the bash version.
-
grep — searching text
The grep command finds lines matching a pattern in files and command output: regex, recursion, context.
4 mingrep -igrep -rngrep -v -
Disk space: df, du, inode
Where the space and inodes went — df, du, finding large files, pitfalls.
4 mindf -hdf -idu -xh -
Paths — basename, dirname, realpath
Splitting a path into a name and a directory, getting an absolute path; a script's own directory.
3 minbasenamedirnamerealpath -
Glob patterns and brace expansion
Shell substitutions — * ? [] {} — and how they differ from regular expressions.
4 minmkdir -pcpecho -
find — searching for files
Finding files by name, size, time, permissions; acting on what's found.
4 minfind -
lsof — open files and ports of processes
lsof shows which process holds a file, a port, or a deleted file that is still open.
6 minlsof -ilsoflsof -p -
Symbolic and hard links
The difference between a symlink and a hard link, when to use which, broken links.
4 minln -sln -sfnreadlink -f -
chmod / chown — permissions and ownership
Changing permissions (chmod) and owner/group (chown) — numeric and symbolic syntax, umask, chgrp.
6 minchmodchownchown -R -
Filesystems: ext4, xfs, fsck
Filesystems: creating one with mkfs, labels and UUIDs, fsck checks, choosing between ext4 and xfs.
7 minlsblk -fmkfs.ext4 -Ltune2fs -m -
umask — the mask for new files and directories
umask is a process mask: which permissions to remove from a new file (from 666) and directory (from 777).
6 minumaskumask -Stouch -
Special permission bits: setuid, setgid, sticky
Special permission bits: setuid and setgid run a program as its owner; setgid and sticky shape shared directories.
7 minls -ldchmodstat -c -
tar — archiving and extracting files
Packs files into a compressed archive; an archive with no top directory dumps its files into the current directory.
4 mintar czftar xzftar tvzf -
Extended permissions (ACL)
Flexible rights beyond rwx — getfacl/setfacl, per-user and per-group grants.
4 mingetfacl filesetfacl -msetfacl -d -
NFS network filesystem
Network directories over NFS — exporting on the server, mounting on the client, permissions.
4 minexportfs -raexportfs -vshowmount -e -
rsync — file synchronization and copying
Copies only the differences between trees; --delete mirrors the source into the destination, removing anything extra.
4 minrsync -avzPrsync -avznrsync -avz -
xargs — building arguments from a stream
Turns stdin lines into a command's arguments; without -0, file names with spaces and newlines break the parsing.
3 minfind -
qemu-img — virtual machine disk images
Creating and maintaining qcow2 disks — overlays, conversion, resizing.
6 minqemu-img infoqemu-img createqemu-img convert -
restic — deduplicated backups
Incremental encrypted backups with snapshots; without the password the repository cannot be decrypted at all.
4 minrestic initrestic backuprestic snapshots -
diff and patch — comparing and applying changes
Comparing files and applying patches: diff two configs, see what changed, apply a patch.
4 mindiff -udiff -qrdiff -
wget — downloading files over the network
Downloads files with resume and recursion; -r without -np and -l has no brakes and can mirror a whole site.
4 minwgetwget -Owget -c -
Disk quotas
Limiting space and file counts per user/group — enabling, configuring, reports.
4 minsetquota -uedquota -uedquota -t -
git: change history, undo and a remote repository
A version control system: who changed what in the files, how to get back a working version and exchange changes.
15 mingit statusgit diffgit add -
GPG — encryption and signatures
GnuPG: GPG keys, encrypting files, signing and verifying, symmetric mode with a passphrase.
5 mingpg -cgpg -dgpg -e -
Dockerfile — an image recipe and docker build
A Dockerfile is an image recipe: base, files, build and start commands; docker build turns it into an image.
14 mindocker builddocker historydocker image -
Samba — file sharing over SMB
An SMB server for Windows-compatible shares; the SMB password is separate from the system one, easy to forget to set.
5 minsmbpasswd -atestparmsmbstatus