Linux Command Reference

180+ Linux and bash commands with examples — searchable by name, description, or category. Click Copy to grab any command.

Showing 180 of 180 commands
lsFiles

List directory contents.

Examplels -la
ls -lhFiles

List with human-readable file sizes.

Examplels -lh /var/log
cpFiles

Copy files or directories.

Examplecp file.txt backup.txt
cp -rFiles

Copy a directory recursively.

Examplecp -r src/ dst/
mvFiles

Move or rename files and directories.

Examplemv old.txt new.txt
rmFiles

Remove files.

Examplerm file.txt
rm -rfFiles

Recursively force-remove a directory and its contents.

Examplerm -rf tmp/
touchFiles

Create an empty file or update its timestamp.

Exampletouch notes.txt
catFiles

Print file contents to stdout.

Examplecat /etc/hosts
headFiles

Print the first N lines of a file.

Examplehead -n 20 log.txt
tailFiles

Print the last N lines of a file.

Exampletail -n 50 log.txt
tail -fFiles

Follow a file as it grows (live log watching).

Exampletail -f /var/log/syslog
lessFiles

Page through file contents interactively.

Exampleless /etc/nginx/nginx.conf
moreFiles

Page through file contents (simpler than less).

Examplemore file.txt
fileFiles

Detect the type of a file.

Examplefile image.png
statFiles

Display file or filesystem status.

Examplestat /etc/passwd
ln -sFiles

Create a symbolic link.

Exampleln -s /usr/bin/python3 /usr/local/bin/python
lnFiles

Create a hard link.

Exampleln original.txt hardlink.txt
wc -lFiles

Count lines in a file.

Examplewc -l /etc/passwd
teeFiles

Read stdin and write to both stdout and a file.

Exampleecho "hello" | tee output.txt
pwdDirectories

Print the current working directory.

Examplepwd
cdDirectories

Change the current directory.

Examplecd /var/www/html
cd ~Directories

Change to the home directory.

Examplecd ~
cd -Directories

Switch to the previous directory.

Examplecd -
mkdirDirectories

Create a directory.

Examplemkdir project
mkdir -pDirectories

Create nested directories.

Examplemkdir -p a/b/c
rmdirDirectories

Remove an empty directory.

Examplermdir emptydir
treeDirectories

Display directory structure as a tree.

Exampletree -L 2
du -shDirectories

Show total disk usage of a directory.

Exampledu -sh /home/user
du -sh *Directories

Show disk usage of each item in the current directory.

Exampledu -sh *
grepText

Search for a pattern in files.

Examplegrep "error" /var/log/app.log
grep -iText

Case-insensitive pattern search.

Examplegrep -i "warning" app.log
grep -vText

Invert match — print lines NOT matching the pattern.

Examplegrep -v "^#" config.conf
grep -nText

Print line numbers with matching lines.

Examplegrep -n "TODO" *.ts
grep -rText

Recursively search a directory.

Examplegrep -r "API_KEY" ./src
grep -cText

Count matching lines.

Examplegrep -c "GET" access.log
sedText

Stream editor — substitute text in files.

Examplesed 's/foo/bar/g' file.txt
sed -iText

Edit a file in-place.

Examplesed -i 's/localhost/127.0.0.1/g' config.txt
awkText

Pattern-scanning and text processing language.

Exampleawk '{print $1, $3}' data.txt
awk -FText

Use a custom field separator.

Exampleawk -F: '{print $1}' /etc/passwd
cutText

Remove sections from each line of input.

Examplecut -d: -f1 /etc/passwd
sortText

Sort lines of text.

Examplesort names.txt
sort -nText

Sort numerically.

Examplesort -n sizes.txt
sort -rText

Sort in reverse order.

Examplesort -r -n numbers.txt
uniqText

Remove duplicate adjacent lines.

Examplesort file.txt | uniq
uniq -cText

Prefix lines with occurrence count.

Examplesort file.txt | uniq -c | sort -rn
wcText

Count lines, words, and bytes.

Examplewc -lwc document.txt
diffText

Compare two files line by line.

Examplediff file1.txt file2.txt
trText

Translate or delete characters.

Exampleecho 'Hello' | tr '[:lower:]' '[:upper:]'
echoText

Display a line of text.

Exampleecho "Hello, World!"
printfText

Format and print data.

Exampleprintf "Name: %s\nAge: %d\n" Alice 30
xargsText

Build and execute commands from stdin.

Examplecat urls.txt | xargs wget
column -tText

Format input into aligned columns.

Examplecat data.tsv | column -t
ps auxProcess

Show all running processes.

Exampleps aux | grep nginx
topProcess

Real-time process viewer.

Exampletop
htopProcess

Interactive process viewer (requires install).

Examplehtop
killProcess

Send a signal to a process by PID.

Examplekill -9 1234
killallProcess

Kill processes by name.

Examplekillall node
pkillProcess

Kill processes matching a pattern.

Examplepkill -f "python script.py"
pgrepProcess

Find process IDs matching a pattern.

Examplepgrep -u www-data nginx
bgProcess

Resume a stopped job in the background.

Examplebg %1
fgProcess

Bring a background job to the foreground.

Examplefg %1
jobsProcess

List active jobs in the current shell.

Examplejobs -l
nohupProcess

Run a command immune to hangups.

Examplenohup ./server.sh &
niceProcess

Run a command with modified scheduling priority.

Examplenice -n 10 ./backup.sh
reniceProcess

Alter the priority of a running process.

Examplerenice -n 5 -p 1234
lsofProcess

List open files and the processes using them.

Examplelsof -i :3000
straceProcess

Trace system calls made by a process.

Examplestrace -p 1234
pingNetwork

Send ICMP echo requests to a host.

Exampleping -c 4 google.com
curlNetwork

Transfer data to or from a server.

Examplecurl -s https://api.example.com/data
curl -X POSTNetwork

Send an HTTP POST request.

Examplecurl -X POST -H 'Content-Type: application/json' -d '{"key":"val"}' https://api.example.com
wgetNetwork

Download files from the web.

Examplewget https://example.com/file.tar.gz
wget -rNetwork

Recursively download a website.

Examplewget -r -np https://example.com/
sshNetwork

Open a secure shell connection to a remote host.

Examplessh user@192.168.1.10
scpNetwork

Copy files securely between hosts.

Examplescp file.txt user@host:/remote/path/
rsyncNetwork

Efficiently sync files locally or over a network.

Examplersync -avz ./src/ user@host:/dst/
netstat -tulpnNetwork

Show listening TCP/UDP ports and processes.

Examplenetstat -tulpn
ss -tulpnNetwork

Show socket statistics (modern netstat replacement).

Exampless -tulpn
ip addrNetwork

Show all network interfaces and IP addresses.

Exampleip addr show eth0
ip routeNetwork

Display or manipulate the routing table.

Exampleip route show
ifconfigNetwork

Display or configure network interfaces (legacy).

Exampleifconfig eth0
digNetwork

DNS lookup utility.

Exampledig A example.com
nslookupNetwork

Query DNS name servers.

Examplenslookup google.com 8.8.8.8
tracerouteNetwork

Print the route packets take to a network host.

Exampletraceroute google.com
nmapNetwork

Network exploration and port scanner.

Examplenmap -sV 192.168.1.0/24
ncNetwork

Netcat — read/write TCP/UDP connections.

Examplenc -zv host.com 80
chmodPermissions

Change file permissions.

Examplechmod 755 script.sh
chmod +xPermissions

Make a file executable.

Examplechmod +x deploy.sh
chmod -RPermissions

Recursively change permissions.

Examplechmod -R 644 /var/www/html
chownPermissions

Change file owner and group.

Examplechown www-data:www-data /var/www
chown -RPermissions

Recursively change ownership.

Examplechown -R user:group /home/user/app
chgrpPermissions

Change the group ownership of a file.

Examplechgrp developers project/
sudoPermissions

Execute a command as another user (typically root).

Examplesudo apt update
suPermissions

Switch to another user account.

Examplesu - postgres
passwdPermissions

Change a user account password.

Examplepasswd username
umaskPermissions

Set default file creation permissions.

Exampleumask 022
visudoPermissions

Safely edit the sudoers file.

Examplesudo visudo
getfaclPermissions

Display ACL (access control list) for a file.

Examplegetfacl /etc/secret
setfaclPermissions

Set ACL permissions on a file.

Examplesetfacl -m u:alice:rw file.txt
tar -czfArchives

Create a gzipped tar archive.

Exampletar -czf archive.tar.gz ./folder
tar -xzfArchives

Extract a gzipped tar archive.

Exampletar -xzf archive.tar.gz
tar -cjfArchives

Create a bzip2-compressed tar archive.

Exampletar -cjf archive.tar.bz2 ./folder
tar -xjfArchives

Extract a bzip2-compressed tar archive.

Exampletar -xjf archive.tar.bz2
tar -tfArchives

List contents of a tar archive without extracting.

Exampletar -tf archive.tar.gz
zipArchives

Create a zip archive.

Examplezip -r output.zip ./folder
unzipArchives

Extract a zip archive.

Exampleunzip output.zip -d /target
gzipArchives

Compress a file using gzip.

Examplegzip file.txt
gunzipArchives

Decompress a gzip file.

Examplegunzip file.txt.gz
bzip2Archives

Compress a file using bzip2.

Examplebzip2 file.txt
7z aArchives

Create a 7-zip archive.

Example7z a archive.7z ./folder
7z xArchives

Extract a 7-zip archive.

Example7z x archive.7z -o/target
df -hSystem

Show disk space usage in human-readable form.

Exampledf -h
du -shSystem

Show total size of a directory.

Exampledu -sh /var/log
free -hSystem

Display memory usage in human-readable form.

Examplefree -h
uname -aSystem

Print all system information.

Exampleuname -a
hostnameSystem

Show or set the system hostname.

Examplehostname -I
uptimeSystem

Show how long the system has been running.

Exampleuptime
whoamiSystem

Print the current logged-in username.

Examplewhoami
idSystem

Print user and group IDs.

Exampleid username
dateSystem

Display or set the system date and time.

Exampledate "+%Y-%m-%d %H:%M:%S"
calSystem

Display a calendar.

Examplecal 2025
historySystem

Show command history.

Examplehistory | tail -20
envSystem

Print environment variables.

Exampleenv | grep PATH
exportSystem

Set an environment variable for the current session.

Exampleexport NODE_ENV=production
aliasSystem

Create a command shortcut.

Examplealias ll="ls -lah"
systemctl statusSystem

Check the status of a systemd service.

Examplesystemctl status nginx
systemctl restartSystem

Restart a systemd service.

Examplesudo systemctl restart nginx
journalctl -uSystem

View logs for a specific systemd service.

Examplejournalctl -u nginx --since "1 hour ago"
rebootSystem

Reboot the system.

Examplesudo reboot
shutdownSystem

Shut down or restart the system at a scheduled time.

Examplesudo shutdown -h now
findSearch

Find files and directories matching criteria.

Examplefind /var -name "*.log" -mtime +7
find -nameSearch

Find by filename pattern.

Examplefind . -name "*.ts" -type f
find -sizeSearch

Find files by size.

Examplefind / -size +100M -type f
find -execSearch

Execute a command on each found file.

Examplefind . -name "*.tmp" -exec rm {} \;
locateSearch

Find files by name using a prebuilt database.

Examplelocate nginx.conf
whichSearch

Show the full path of a shell command.

Examplewhich python3
whereisSearch

Locate binary, source, and manual page files.

Examplewhereis nginx
typeSearch

Describe how the shell would interpret a command.

Exampletype ls
grep -rnSearch

Recursively search with line numbers.

Examplegrep -rn "TODO" ./src
fdSearch

Fast and user-friendly find alternative.

Examplefd "*.js" ./src
sshSSH

Open a secure shell session to a remote host.

Examplessh user@hostname
ssh -pSSH

Connect to a non-default SSH port.

Examplessh -p 2222 user@hostname
ssh -iSSH

Specify a private key file for authentication.

Examplessh -i ~/.ssh/id_rsa user@host
ssh -LSSH

Create a local port-forwarding tunnel.

Examplessh -L 8080:localhost:80 user@host
ssh -RSSH

Create a remote port-forwarding tunnel.

Examplessh -R 9090:localhost:9090 user@host
ssh-keygenSSH

Generate an SSH key pair.

Examplessh-keygen -t ed25519 -C "you@example.com"
ssh-copy-idSSH

Install your public key on a remote server.

Examplessh-copy-id user@host
scpSSH

Secure file copy between hosts.

Examplescp -r ./dist user@host:/var/www/
sftpSSH

Interactive secure file transfer over SSH.

Examplesftp user@host
ssh-agentSSH

Hold private keys in memory for passwordless auth.

Exampleeval "$(ssh-agent -s)"
ssh-addSSH

Add a private key to the SSH agent.

Examplessh-add ~/.ssh/id_ed25519
apt updatePackage

Update the package list (Debian/Ubuntu).

Examplesudo apt update
apt upgradePackage

Upgrade all installed packages.

Examplesudo apt upgrade -y
apt installPackage

Install a package.

Examplesudo apt install nginx
apt removePackage

Remove a package.

Examplesudo apt remove nginx
apt searchPackage

Search for a package in the repository.

Exampleapt search "text editor"
yum installPackage

Install a package (RHEL/CentOS).

Examplesudo yum install httpd
dnf installPackage

Install a package (Fedora/newer RHEL).

Examplesudo dnf install nodejs
brew installPackage

Install a Homebrew package (macOS/Linux).

Examplebrew install ripgrep
brew updatePackage

Update Homebrew and all formulae.

Examplebrew update && brew upgrade
pip installPackage

Install a Python package.

Examplepip install requests
pip freezePackage

Output installed Python packages.

Examplepip freeze > requirements.txt
npm installPackage

Install Node.js packages.

Examplenpm install express
npm install -gPackage

Install a Node.js package globally.

Examplenpm install -g typescript
snap installPackage

Install a snap package.

Examplesudo snap install code --classic
#!/bin/bashScripting

Shebang line — declares the script interpreter.

Example#!/bin/bash echo "Hello"
if [ ... ]Scripting

Conditional statement.

Exampleif [ "$VAR" = "yes" ]; then echo "yes"; fi
for ... inScripting

Iterate over a list.

Examplefor f in *.txt; do echo "$f"; done
while readScripting

Read lines from stdin in a loop.

Examplewhile read line; do echo "$line"; done < file.txt
case ... inScripting

Multi-pattern switch statement.

Examplecase "$1" in start) echo "starting";; stop) echo "stopping";; esac
functionScripting

Define a reusable bash function.

Examplefunction greet() { echo "Hello, $1!"; }
$?Scripting

Exit code of the last executed command.

Examplels /missing; echo $?
$1, $2, ...Scripting

Positional arguments passed to a script.

Exampleecho "First arg: $1"
$@Scripting

All positional arguments as separate words.

Examplefor arg in "$@"; do echo "$arg"; done
&&Scripting

Execute the next command only if the previous succeeded.

Examplemake && make install
||Scripting

Execute the next command only if the previous failed.

Exampleping -c1 host || echo "offline"
set -eScripting

Exit immediately if any command fails.

Exampleset -e npm install npm run build
set -xScripting

Print each command before executing (debug mode).

Exampleset -x ./deploy.sh
trapScripting

Execute a command when the script exits or receives a signal.

Exampletrap "rm -f /tmp/lock" EXIT
readScripting

Read user input from stdin into a variable.

Exampleread -p "Enter name: " name