Skip to main content
CalcChef

Shell Commands Cheat Sheet

Search or filter 83 common shell commands by level, topic and platform, and copy a name or example. 12 are tagged as Linux tools or not on a default Mac. How it works

Use the Shell Commands Cheat Sheet

Skill Level

Topics

Platform

A fixed list of 83 common shell commands. Commands marked as not on a default macOS install are Linux tools or need a separate install.

Showing 83 commands
CommandDescriptionExampleTopicPlatformCopy
lsList directory contentsls -la /home/userFile OperationsLinux and macOS (flags can differ)
cdChange current directorycd /var/logFile OperationsLinux and macOS (flags can differ)
pwdPrint working directorypwdFile OperationsLinux and macOS (flags can differ)
cpCopy files or directoriescp source.txt dest.txtFile OperationsLinux and macOS (flags can differ)
mvMove or rename filesmv oldname.txt newname.txtFile OperationsLinux and macOS (flags can differ)
rmRemove files or directoriesrm -rf tempdir/File OperationsLinux and macOS (flags can differ)
mkdirCreate a directorymkdir -p project/srcFile OperationsLinux and macOS (flags can differ)
touchCreate empty file or update timestamptouch newfile.txtFile OperationsLinux and macOS (flags can differ)
catConcatenate and display file contentcat file.txtText ProcessingLinux and macOS (flags can differ)
echoPrint text to stdoutecho "Hello World"Text ProcessingLinux and macOS (flags can differ)
lessView file content page by pageless largefile.logText ProcessingLinux and macOS (flags can differ)
headDisplay first lines of a filehead -n 20 file.txtText ProcessingLinux and macOS (flags can differ)
tailDisplay last lines of a filetail -f app.logText ProcessingLinux and macOS (flags can differ)
grepSearch text using patternsgrep -i "error" logfile.logText ProcessingLinux and macOS (flags can differ)
chmodChange file permissionschmod 755 script.shPermissionsLinux and macOS (flags can differ)
chownChange file ownerchown user:group file.txtPermissionsLinux and macOS (flags can differ)
psList running processesps auxProcess ManagementLinux and macOS (flags can differ)
topShow live process activitytop -u usernameProcess ManagementLinux and macOS (flags can differ)The example is written for Linux; on macOS the options differ.
killTerminate a process by PIDkill -9 1234Process ManagementLinux and macOS (flags can differ)
dfShow disk space usagedf -hDisk UsageLinux and macOS (flags can differ)
duShow directory space usagedu -sh /home/userDisk UsageLinux and macOS (flags can differ)
tarCreate/extract tar archivestar -czf archive.tar.gz dir/ArchivingLinux and macOS (flags can differ)
gzipCompress or decompress filesgzip largefile.logArchivingLinux and macOS (flags can differ)
sshConnect to remote hostssh [email protected]SSHLinux and macOS (flags can differ)
git cloneClone a repositorygit clone https://github.com/user/repo.gitGitLinux and macOS (flags can differ)On a Mac, git comes with the Xcode Command Line Tools or a separate install.
git addStage changes for commitgit add .GitLinux and macOS (flags can differ)On a Mac, git comes with the Xcode Command Line Tools or a separate install.
git commitCommit staged changesgit commit -m "Fix bug"GitLinux and macOS (flags can differ)On a Mac, git comes with the Xcode Command Line Tools or a separate install.
git pushPush commits to remotegit push origin mainGitLinux and macOS (flags can differ)On a Mac, git comes with the Xcode Command Line Tools or a separate install.
git statusShow working tree statusgit statusGitLinux and macOS (flags can differ)On a Mac, git comes with the Xcode Command Line Tools or a separate install.
git logShow commit historygit log --onelineGitLinux and macOS (flags can differ)On a Mac, git comes with the Xcode Command Line Tools or a separate install.
unamePrint system informationuname -aSystem InfoLinux and macOS (flags can differ)
whoamiPrint current user namewhoamiSystem InfoLinux and macOS (flags can differ)
dateDisplay current date and timedate "+%Y-%m-%d"System InfoLinux and macOS (flags can differ)
uptimeShow system uptimeuptimeSystem InfoLinux and macOS (flags can differ)
findSearch for files in a hierarchyfind /home -name "*.txt"File OperationsLinux and macOS (flags can differ)
lnCreate hard or symbolic linksln -s /usr/local/bin/node nodeFile OperationsLinux and macOS (flags can differ)
rsyncSync files locally or remotelyrsync -avz src/ user@host:/dest/File OperationsLinux and macOS (flags can differ)
sedStream editor for text transformationsed 's/old/new/g' file.txtText ProcessingLinux and macOS (flags can differ)
awkPattern scanning and processingawk '{print $1}' file.txtText ProcessingLinux and macOS (flags can differ)
sortSort lines of textsort -k2,2 -n data.csvText ProcessingLinux and macOS (flags can differ)
uniqReport or omit repeated linessort file.txt | uniq -cText ProcessingLinux and macOS (flags can differ)
wcCount lines, words, and characterswc -l file.txtText ProcessingLinux and macOS (flags can differ)
pingTest network connectivityping -c 4 google.comNetworkingLinux and macOS (flags can differ)
curlTransfer data from/to serverscurl -I https://example.comNetworkingLinux and macOS (flags can differ)
wgetDownload files from the webwget https://example.com/file.zipNetworkingNot on a default macOS install
ssShow socket statisticsss -tulnNetworkingNot on a default macOS install
umaskSet default file permissionsumask 022PermissionsLinux and macOS (flags can differ)
nohupRun command immune to hangupsnohup longtask.sh &Process ManagementLinux and macOS (flags can differ)
niceSet process prioritynice -n 10 slowtask.shProcess ManagementLinux and macOS (flags can differ)
lsblkList block deviceslsblk -fDisk UsageNot on a default macOS install
mountMount a filesystemmount /dev/sdb1 /mnt/dataDisk UsageLinux and macOS (flags can differ)The example is written for Linux; on macOS the options differ.
zipCreate/extract ZIP archiveszip -r archive.zip folder/ArchivingLinux and macOS (flags can differ)
unzipExtract ZIP archivesunzip archive.zip -d target/ArchivingLinux and macOS (flags can differ)
scpCopy files over SSHscp file.txt user@host:/remote/SSHLinux and macOS (flags can differ)
ssh-keygenGenerate SSH key pairsssh-keygen -t ed25519SSHLinux and macOS (flags can differ)
ssh-copy-idInstall SSH public key on remotessh-copy-id user@hostSSHLinux and macOS (flags can differ)
git diffShow changes between commitsgit diff HEAD~1GitLinux and macOS (flags can differ)On a Mac, git comes with the Xcode Command Line Tools or a separate install.
git branchList or create branchesgit branch feature-xGitLinux and macOS (flags can differ)On a Mac, git comes with the Xcode Command Line Tools or a separate install.
git mergeMerge a branch into currentgit merge feature-xGitLinux and macOS (flags can differ)On a Mac, git comes with the Xcode Command Line Tools or a separate install.
git stashTemporarily save changesgit stash push -m "WIP"GitLinux and macOS (flags can differ)On a Mac, git comes with the Xcode Command Line Tools or a separate install.
git resetReset current HEAD to a stategit reset --soft HEAD~1GitLinux and macOS (flags can differ)On a Mac, git comes with the Xcode Command Line Tools or a separate install.
freeShow memory usagefree -hSystem InfoNot on a default macOS install
lscpuShow CPU architecture infolscpuSystem InfoNot on a default macOS install
lspciList PCI deviceslspci -vSystem InfoNot on a default macOS install
fdfindFast file search (fd alternative)fdfind -e md -t fFile OperationsNot on a default macOS install
xargsBuild and execute commands from stdinfind . -name "*.log" | xargs rmText ProcessingLinux and macOS (flags can differ)
jqJSON processor for the shelljq '.name' package.jsonText ProcessingLinux and macOS (flags can differ)
tcpdumpCapture network traffictcpdump -i any port 80NetworkingLinux and macOS (flags can differ)
nmapNetwork exploration and scanningnmap -sV 192.168.1.0/24NetworkingNot on a default macOS install
socatMultipurpose relay toolsocat TCP-LISTEN:8080,fork TCP:localhost:80NetworkingNot on a default macOS install
straceTrace system calls and signalsstrace -e trace=openat,read lsProcess ManagementNot on a default macOS install
perfPerformance analysis toolperf stat ./myappProcess ManagementNot on a default macOS install
iostatCPU and I/O statisticsiostat -x 2 5Disk UsageLinux and macOS (flags can differ)The example is written for Linux; on macOS the options differ.
ddConvert and copy files at block leveldd if=/dev/sda of=backup.img bs=1048576Disk UsageLinux and macOS (flags can differ)
ssh tunnelCreate SSH port forwardingssh -L 8080:localhost:80 user@hostSSHLinux and macOS (flags can differ)
ssh configConfigure SSH hosts in ~/.ssh/configHost myserver HostName 192.168.1.1 User adminSSHLinux and macOS (flags can differ)
git rebaseReapply commits on top of another basegit rebase -i mainGitLinux and macOS (flags can differ)On a Mac, git comes with the Xcode Command Line Tools or a separate install.
git bisectBinary search for a buggy commitgit bisect start HEAD v1.0GitLinux and macOS (flags can differ)On a Mac, git comes with the Xcode Command Line Tools or a separate install.
git reflogShow reference log for recoverygit reflog show HEADGitLinux and macOS (flags can differ)On a Mac, git comes with the Xcode Command Line Tools or a separate install.
git cherry-pickApply specific commits to current branchgit cherry-pick abc123GitLinux and macOS (flags can differ)On a Mac, git comes with the Xcode Command Line Tools or a separate install.
sysctlConfigure kernel parameters at runtimesysctl -w net.ipv4.ip_forward=1System InfoLinux and macOS (flags can differ)The example is written for Linux; on macOS the options differ.
journalctlQuery systemd journal logsjournalctl -u nginx.service -fSystem InfoNot on a default macOS install
dmesgPrint kernel ring buffer messagesdmesg -T | tail -20System InfoLinux and macOS (flags can differ)The example is written for Linux; on macOS the options differ.

About the Shell Commands Cheat Sheet

The cheat sheet holds 83 shell commands: 34 beginner, 30 intermediate and 19 advanced, in ten topics. Filter by one skill level, any topics and a platform; each row has a description, an example to copy and a platform note. 12 of the commands are tagged as not on a default macOS install, and Hide commands not on a default Mac leaves the other 71.

Commands on the cheat sheet by topic

TopicCommands
File Operations12
Text Processing13
Networking7
Permissions3
Process Management7
Disk Usage6
Archiving4
SSH6
Git15
System Info10

Each command sits under one topic and one skill level, so the topic counts add up to 83. Picking several topics shows the commands under any of them.

How to use this tool

  1. Type a word or two in Search commands, such as disk or compress, or pick a skill level, or leave all three showing.
  2. Tick the topics you want. A command shows if it is under any ticked topic and at the chosen level.
  3. On a Mac, set Platform to Hide commands not on a default Mac to drop the 12 commands tagged as not on a default macOS install.
  4. Use Copy command name for the bare name, or Copy example for the example line, then read it before you run it.

Frequently asked questions

Which shell commands are Linux-only and not on macOS?
The tool tags 12 of its 83 commands as not on a default macOS install: ss, lsblk, free, lscpu, lspci, fdfind, strace, perf, journalctl, wget, nmap and socat. That tag is the tool’s own list. A macOS command index (ss64.com) does list mount, sysctl, tcpdump and iostat, so those four are not tagged, and macOS ships its own dmesg, which needs root and has no -T flag. Their flags can still differ from the Linux versions: the iostat, top, sysctl, mount and dmesg examples are written for Linux and say so in the table. The git rows come with the Xcode Command Line Tools on a Mac.
What is the difference between Copy command name and Copy example?
Copy command name copies the bare command, such as grep or git commit. Copy example copies the whole example line, such as grep -i "error" logfile.log. Both report that they copied, or that the browser blocked the clipboard.
Are the examples safe to paste into a terminal?
Read each one first and change the paths. The list includes rm -rf tempdir/, which deletes a folder and everything in it without asking, and kill -9 1234, which stops a process with no chance to clean up. The tool only shows and copies examples; it never runs a command.
How many commands are on the list, and can I search or add to it?
There are 83: 34 beginner, 30 intermediate and 19 advanced, and the list is fixed. The search box narrows it: every word you type must appear in the command, its description, its example or its topic, so disk leaves 6 rows (df, du, lsblk, mount, iostat and dd). The search works with the skill level, topic and platform filters, and the line above the table says how many commands match.
How do I extract a tar.gz file?
tar -xzf archive.tar.gz unpacks it into the current folder: x extracts, z reads gzip and f names the file. The sheet’s Archiving row shows the reverse, tar -czf archive.tar.gz dir/, which packs the folder dir into archive.tar.gz. Add -C target/ to unpack somewhere else. For a .zip file, the unzip row gives unzip archive.zip -d target/.

Related Tools

View all tools