Linux Command Reference
180+ Linux and bash commands with examples — searchable by name, description, or category. Click Copy to grab any command.
lsFilesList directory contents.
ls -lals -lhFilesList with human-readable file sizes.
ls -lh /var/logcpFilesCopy files or directories.
cp file.txt backup.txtcp -rFilesCopy a directory recursively.
cp -r src/ dst/mvFilesMove or rename files and directories.
mv old.txt new.txtrmFilesRemove files.
rm file.txtrm -rfFilesRecursively force-remove a directory and its contents.
rm -rf tmp/touchFilesCreate an empty file or update its timestamp.
touch notes.txtcatFilesPrint file contents to stdout.
cat /etc/hostsheadFilesPrint the first N lines of a file.
head -n 20 log.txttailFilesPrint the last N lines of a file.
tail -n 50 log.txttail -fFilesFollow a file as it grows (live log watching).
tail -f /var/log/sysloglessFilesPage through file contents interactively.
less /etc/nginx/nginx.confmoreFilesPage through file contents (simpler than less).
more file.txtfileFilesDetect the type of a file.
file image.pngstatFilesDisplay file or filesystem status.
stat /etc/passwdln -sFilesCreate a symbolic link.
ln -s /usr/bin/python3 /usr/local/bin/pythonlnFilesCreate a hard link.
ln original.txt hardlink.txtwc -lFilesCount lines in a file.
wc -l /etc/passwdteeFilesRead stdin and write to both stdout and a file.
echo "hello" | tee output.txtpwdDirectoriesPrint the current working directory.
pwdcdDirectoriesChange the current directory.
cd /var/www/htmlcd ~DirectoriesChange to the home directory.
cd ~cd -DirectoriesSwitch to the previous directory.
cd -mkdirDirectoriesCreate a directory.
mkdir projectmkdir -pDirectoriesCreate nested directories.
mkdir -p a/b/crmdirDirectoriesRemove an empty directory.
rmdir emptydirtreeDirectoriesDisplay directory structure as a tree.
tree -L 2du -shDirectoriesShow total disk usage of a directory.
du -sh /home/userdu -sh *DirectoriesShow disk usage of each item in the current directory.
du -sh *grepTextSearch for a pattern in files.
grep "error" /var/log/app.loggrep -iTextCase-insensitive pattern search.
grep -i "warning" app.loggrep -vTextInvert match — print lines NOT matching the pattern.
grep -v "^#" config.confgrep -nTextPrint line numbers with matching lines.
grep -n "TODO" *.tsgrep -rTextRecursively search a directory.
grep -r "API_KEY" ./srcgrep -cTextCount matching lines.
grep -c "GET" access.logsedTextStream editor — substitute text in files.
sed 's/foo/bar/g' file.txtsed -iTextEdit a file in-place.
sed -i 's/localhost/127.0.0.1/g' config.txtawkTextPattern-scanning and text processing language.
awk '{print $1, $3}' data.txtawk -FTextUse a custom field separator.
awk -F: '{print $1}' /etc/passwdcutTextRemove sections from each line of input.
cut -d: -f1 /etc/passwdsortTextSort lines of text.
sort names.txtsort -nTextSort numerically.
sort -n sizes.txtsort -rTextSort in reverse order.
sort -r -n numbers.txtuniqTextRemove duplicate adjacent lines.
sort file.txt | uniquniq -cTextPrefix lines with occurrence count.
sort file.txt | uniq -c | sort -rnwcTextCount lines, words, and bytes.
wc -lwc document.txtdiffTextCompare two files line by line.
diff file1.txt file2.txttrTextTranslate or delete characters.
echo 'Hello' | tr '[:lower:]' '[:upper:]'echoTextDisplay a line of text.
echo "Hello, World!"printfTextFormat and print data.
printf "Name: %s\nAge: %d\n" Alice 30xargsTextBuild and execute commands from stdin.
cat urls.txt | xargs wgetcolumn -tTextFormat input into aligned columns.
cat data.tsv | column -tps auxProcessShow all running processes.
ps aux | grep nginxtopProcessReal-time process viewer.
tophtopProcessInteractive process viewer (requires install).
htopkillProcessSend a signal to a process by PID.
kill -9 1234killallProcessKill processes by name.
killall nodepkillProcessKill processes matching a pattern.
pkill -f "python script.py"pgrepProcessFind process IDs matching a pattern.
pgrep -u www-data nginxbgProcessResume a stopped job in the background.
bg %1fgProcessBring a background job to the foreground.
fg %1jobsProcessList active jobs in the current shell.
jobs -lnohupProcessRun a command immune to hangups.
nohup ./server.sh &niceProcessRun a command with modified scheduling priority.
nice -n 10 ./backup.shreniceProcessAlter the priority of a running process.
renice -n 5 -p 1234lsofProcessList open files and the processes using them.
lsof -i :3000straceProcessTrace system calls made by a process.
strace -p 1234pingNetworkSend ICMP echo requests to a host.
ping -c 4 google.comcurlNetworkTransfer data to or from a server.
curl -s https://api.example.com/datacurl -X POSTNetworkSend an HTTP POST request.
curl -X POST -H 'Content-Type: application/json' -d '{"key":"val"}' https://api.example.comwgetNetworkDownload files from the web.
wget https://example.com/file.tar.gzwget -rNetworkRecursively download a website.
wget -r -np https://example.com/sshNetworkOpen a secure shell connection to a remote host.
ssh user@192.168.1.10scpNetworkCopy files securely between hosts.
scp file.txt user@host:/remote/path/rsyncNetworkEfficiently sync files locally or over a network.
rsync -avz ./src/ user@host:/dst/netstat -tulpnNetworkShow listening TCP/UDP ports and processes.
netstat -tulpnss -tulpnNetworkShow socket statistics (modern netstat replacement).
ss -tulpnip addrNetworkShow all network interfaces and IP addresses.
ip addr show eth0ip routeNetworkDisplay or manipulate the routing table.
ip route showifconfigNetworkDisplay or configure network interfaces (legacy).
ifconfig eth0digNetworkDNS lookup utility.
dig A example.comnslookupNetworkQuery DNS name servers.
nslookup google.com 8.8.8.8tracerouteNetworkPrint the route packets take to a network host.
traceroute google.comnmapNetworkNetwork exploration and port scanner.
nmap -sV 192.168.1.0/24ncNetworkNetcat — read/write TCP/UDP connections.
nc -zv host.com 80chmodPermissionsChange file permissions.
chmod 755 script.shchmod +xPermissionsMake a file executable.
chmod +x deploy.shchmod -RPermissionsRecursively change permissions.
chmod -R 644 /var/www/htmlchownPermissionsChange file owner and group.
chown www-data:www-data /var/wwwchown -RPermissionsRecursively change ownership.
chown -R user:group /home/user/appchgrpPermissionsChange the group ownership of a file.
chgrp developers project/sudoPermissionsExecute a command as another user (typically root).
sudo apt updatesuPermissionsSwitch to another user account.
su - postgrespasswdPermissionsChange a user account password.
passwd usernameumaskPermissionsSet default file creation permissions.
umask 022visudoPermissionsSafely edit the sudoers file.
sudo visudogetfaclPermissionsDisplay ACL (access control list) for a file.
getfacl /etc/secretsetfaclPermissionsSet ACL permissions on a file.
setfacl -m u:alice:rw file.txttar -czfArchivesCreate a gzipped tar archive.
tar -czf archive.tar.gz ./foldertar -xzfArchivesExtract a gzipped tar archive.
tar -xzf archive.tar.gztar -cjfArchivesCreate a bzip2-compressed tar archive.
tar -cjf archive.tar.bz2 ./foldertar -xjfArchivesExtract a bzip2-compressed tar archive.
tar -xjf archive.tar.bz2tar -tfArchivesList contents of a tar archive without extracting.
tar -tf archive.tar.gzzipArchivesCreate a zip archive.
zip -r output.zip ./folderunzipArchivesExtract a zip archive.
unzip output.zip -d /targetgzipArchivesCompress a file using gzip.
gzip file.txtgunzipArchivesDecompress a gzip file.
gunzip file.txt.gzbzip2ArchivesCompress a file using bzip2.
bzip2 file.txt7z aArchivesCreate a 7-zip archive.
7z a archive.7z ./folder7z xArchivesExtract a 7-zip archive.
7z x archive.7z -o/targetdf -hSystemShow disk space usage in human-readable form.
df -hdu -shSystemShow total size of a directory.
du -sh /var/logfree -hSystemDisplay memory usage in human-readable form.
free -huname -aSystemPrint all system information.
uname -ahostnameSystemShow or set the system hostname.
hostname -IuptimeSystemShow how long the system has been running.
uptimewhoamiSystemPrint the current logged-in username.
whoamiidSystemPrint user and group IDs.
id usernamedateSystemDisplay or set the system date and time.
date "+%Y-%m-%d %H:%M:%S"calSystemDisplay a calendar.
cal 2025historySystemShow command history.
history | tail -20envSystemPrint environment variables.
env | grep PATHexportSystemSet an environment variable for the current session.
export NODE_ENV=productionaliasSystemCreate a command shortcut.
alias ll="ls -lah"systemctl statusSystemCheck the status of a systemd service.
systemctl status nginxsystemctl restartSystemRestart a systemd service.
sudo systemctl restart nginxjournalctl -uSystemView logs for a specific systemd service.
journalctl -u nginx --since "1 hour ago"rebootSystemReboot the system.
sudo rebootshutdownSystemShut down or restart the system at a scheduled time.
sudo shutdown -h nowfindSearchFind files and directories matching criteria.
find /var -name "*.log" -mtime +7find -nameSearchFind by filename pattern.
find . -name "*.ts" -type ffind -sizeSearchFind files by size.
find / -size +100M -type ffind -execSearchExecute a command on each found file.
find . -name "*.tmp" -exec rm {} \;locateSearchFind files by name using a prebuilt database.
locate nginx.confwhichSearchShow the full path of a shell command.
which python3whereisSearchLocate binary, source, and manual page files.
whereis nginxtypeSearchDescribe how the shell would interpret a command.
type lsgrep -rnSearchRecursively search with line numbers.
grep -rn "TODO" ./srcfdSearchFast and user-friendly find alternative.
fd "*.js" ./srcsshSSHOpen a secure shell session to a remote host.
ssh user@hostnamessh -pSSHConnect to a non-default SSH port.
ssh -p 2222 user@hostnamessh -iSSHSpecify a private key file for authentication.
ssh -i ~/.ssh/id_rsa user@hostssh -LSSHCreate a local port-forwarding tunnel.
ssh -L 8080:localhost:80 user@hostssh -RSSHCreate a remote port-forwarding tunnel.
ssh -R 9090:localhost:9090 user@hostssh-keygenSSHGenerate an SSH key pair.
ssh-keygen -t ed25519 -C "you@example.com"ssh-copy-idSSHInstall your public key on a remote server.
ssh-copy-id user@hostscpSSHSecure file copy between hosts.
scp -r ./dist user@host:/var/www/sftpSSHInteractive secure file transfer over SSH.
sftp user@hostssh-agentSSHHold private keys in memory for passwordless auth.
eval "$(ssh-agent -s)"ssh-addSSHAdd a private key to the SSH agent.
ssh-add ~/.ssh/id_ed25519apt updatePackageUpdate the package list (Debian/Ubuntu).
sudo apt updateapt upgradePackageUpgrade all installed packages.
sudo apt upgrade -yapt installPackageInstall a package.
sudo apt install nginxapt removePackageRemove a package.
sudo apt remove nginxapt searchPackageSearch for a package in the repository.
apt search "text editor"yum installPackageInstall a package (RHEL/CentOS).
sudo yum install httpddnf installPackageInstall a package (Fedora/newer RHEL).
sudo dnf install nodejsbrew installPackageInstall a Homebrew package (macOS/Linux).
brew install ripgrepbrew updatePackageUpdate Homebrew and all formulae.
brew update && brew upgradepip installPackageInstall a Python package.
pip install requestspip freezePackageOutput installed Python packages.
pip freeze > requirements.txtnpm installPackageInstall Node.js packages.
npm install expressnpm install -gPackageInstall a Node.js package globally.
npm install -g typescriptsnap installPackageInstall a snap package.
sudo snap install code --classic#!/bin/bashScriptingShebang line — declares the script interpreter.
#!/bin/bash
echo "Hello"if [ ... ]ScriptingConditional statement.
if [ "$VAR" = "yes" ]; then echo "yes"; fifor ... inScriptingIterate over a list.
for f in *.txt; do echo "$f"; donewhile readScriptingRead lines from stdin in a loop.
while read line; do echo "$line"; done < file.txtcase ... inScriptingMulti-pattern switch statement.
case "$1" in start) echo "starting";; stop) echo "stopping";; esacfunctionScriptingDefine a reusable bash function.
function greet() { echo "Hello, $1!"; }$?ScriptingExit code of the last executed command.
ls /missing; echo $?$1, $2, ...ScriptingPositional arguments passed to a script.
echo "First arg: $1"$@ScriptingAll positional arguments as separate words.
for arg in "$@"; do echo "$arg"; done&&ScriptingExecute the next command only if the previous succeeded.
make && make install||ScriptingExecute the next command only if the previous failed.
ping -c1 host || echo "offline"set -eScriptingExit immediately if any command fails.
set -e
npm install
npm run buildset -xScriptingPrint each command before executing (debug mode).
set -x
./deploy.shtrapScriptingExecute a command when the script exits or receives a signal.
trap "rm -f /tmp/lock" EXITreadScriptingRead user input from stdin into a variable.
read -p "Enter name: " name