elefcode
← All cheat sheets

Tools

Bash & Linux Command Cheat Sheet

The Linux and Bash commands that cover most day-to-day terminal work, grouped by task.

Put it into practice with the matching tool.

Calculate chmod permissions

Advertisement

Navigating

pwdPrint the current directory
ls -lahList files: long, all (incl. hidden), human sizes
cd /pathChange directory
cd -Jump back to the previous directory
treeShow a directory tree

Files & directories

cp src destCopy a file (use -r for directories)
mv src destMove or rename
rm fileDelete a file (-r for directories, careful)
mkdir -p a/b/cCreate nested directories
touch fileCreate an empty file / update its timestamp
ln -s target linkCreate a symbolic link

Viewing & searching

cat filePrint a whole file
less filePage through a file (q to quit)
head -n 20 fileFirst 20 lines (tail for the last)
tail -f logFollow a log file live
grep -r "text" .Search recursively for text
find . -name "*.js"Find files by name pattern
wc -l fileCount lines

Permissions & ownership

chmod 755 fileSet permissions (owner rwx, others rx)
chmod +x script.shMake a file executable
chown user:group fileChange owner and group
sudo commandRun a command as superuser

Processes & system

ps aux | grep nodeFind running processes
top / htopLive process and resource monitor
kill -9 <pid>Force-terminate a process
df -hDisk space used and free
du -sh *Size of each item in this directory

Pipes, redirection & archives

cmd > fileWrite output to a file (overwrite)
cmd >> fileAppend output to a file
cmd1 | cmd2Pipe output of one command into another
cmd 2>&1Redirect errors into standard output
tar -czf out.tar.gz dir/Create a gzipped archive
tar -xzf file.tar.gzExtract a gzipped archive

More cheat sheets