Lexicon
⌘K
Explore
GuidesNotes
QuestionsWriteMy LibraryBooks
Sign in

Lexicon

a personal knowledge base

← Back to note

Version history

No earlier versions yet — history builds up each time this note is edited.

Current version1 of 1

Linux

Useful Linux filesystem commands

A compact cheat sheet of filesystem commands I keep coming back to on the terminal.

Moving around

pwd            # where am I
ls -lah        # long list, human sizes, include hidden files
cd -           # jump back to the previous directory

Finding things

find . -name '*.log'          # by name
find . -type f -size +100M    # files larger than 100MB
grep -rn 'TODO' src/          # recursive search with line numbers

Disk usage

du -sh *          # size of each item in the current directory
du -sh * | sort -h# same, sorted smallest to largest
df -h             # free space per mounted filesystem

When a disk fills up, du -sh * | sort -h from the root of the offending mount finds the culprit fast.

Permissions

chmod +x script.sh   # make executable
chmod 644 file       # owner read/write, everyone else read
chown user:group file

Copy, move, link

cp -r src/ backup/       # recursive copy
rsync -av src/ dest/     # efficient copy, only changed files
ln -s target linkname    # symbolic link

rsync beats cp for anything large or repeated because it only transfers what changed.