Comprehensive Linux command reference with 75+ commands
List directory contents
Syntax:
ls [options] [directory]-lLong format listing-aShow hidden files-hHuman readable file sizes-tSort by modification time-RRecursive listingls -laList all files in long format
ls -lh /homeList /home directory with readable sizes
Copy files and directories
Syntax:
cp [options] source destination-rCopy directories recursively-iInteractive mode (prompt before overwrite)-vVerbose mode-pPreserve file attributescp file.txt backup.txtCopy file to backup
cp -r folder/ backup/Copy directory recursively
Move/rename files and directories
Syntax:
mv [options] source destination-iInteractive mode (prompt before overwrite)-vVerbose mode-nNo overwritemv old.txt new.txtRename file
mv file.txt /home/user/Move file to directory
Remove files and directories
Syntax:
rm [options] file...-rRemove directories recursively-fForce removal without prompts-iInteractive mode (prompt before removal)-vVerbose moderm file.txtRemove file
rm -rf directory/Force remove directory and contents
Create directories
Syntax:
mkdir [options] directory...-pCreate parent directories as needed-vVerbose mode-mSet file mode (permissions)mkdir newdirCreate directory
mkdir -p path/to/dirCreate nested directories
Remove empty directories
Syntax:
rmdir [options] directory...-pRemove parent directories if empty-vVerbose modermdir emptydirRemove empty directory
rmdir -p path/to/emptyRemove empty nested directories
Create empty files or update timestamps
Syntax:
touch [options] file...-aChange access time only-mChange modification time only-cDo not create file if it doesn't existtouch newfile.txtCreate empty file
touch file1 file2 file3Create multiple files
Create links between files
Syntax:
ln [options] target linkname-sCreate symbolic link-fForce creation-vVerbose modeln -s /path/to/file linkCreate symbolic link
ln file hardlinkCreate hard link
Change directory
Syntax:
cd [directory]-Go to previous directory~Go to home directory..Go to parent directorycd /home/userChange to specific directory
cd ..Go to parent directory
cd -Go to previous directory
Print working directory (current location)
Syntax:
pwd [options]-LUse PWD from environment (logical path)-PShow actual path without symlinks (physical path)pwdShow current directory path
pwd -PShow physical path without symlinks
Push directory onto stack and change to it
Syntax:
pushd [directory]-nDon't change directorypushd /tmpPush current dir to stack and go to /tmp
Pop directory from stack and change to it
Syntax:
popd [+n | -n]-nDon't change directorypopdReturn to previous directory from stack
Display directory stack
Syntax:
dirs [options]-vVerbose listing with position numbers-cClear directory stackdirsShow directory stack
dirs -vShow numbered directory stack
Display file contents
Syntax:
cat [options] file...-nNumber all output lines-bNumber non-empty output lines-AShow all characters including non-printingcat file.txtDisplay file contents
cat -n file.txtDisplay with line numbers
View file contents page by page
Syntax:
less [options] file...-NShow line numbers-SDon't wrap long lines-iCase insensitive searchless file.txtView file with pagination
less -N file.txtView file with line numbers
View file contents page by page (basic)
Syntax:
more [options] file...-dDisplay help at bottom-fCount logical linesmore file.txtView file with basic pagination
Display first lines of file
Syntax:
head [options] file...-nNumber of lines to show-cNumber of bytes to showhead file.txtShow first 10 lines
head -n 20 file.txtShow first 20 lines
Display last lines of file
Syntax:
tail [options] file...-nNumber of lines to show-fFollow file changes (monitor)-FFollow with retrytail file.txtShow last 10 lines
tail -f /var/log/syslogMonitor log file
Search text patterns in files
Syntax:
grep [options] pattern [file...]-iCase insensitive search-rRecursive search-nShow line numbers-vInvert match-cCount matchesgrep -i 'error' log.txtFind 'error' (case insensitive) in log.txt
grep -rn 'TODO' .Find 'TODO' recursively with line numbers
Stream editor for filtering and transforming text
Syntax:
sed [options] 'command' file...-iEdit files in place-eAdd script to commands-nSuppress automatic printingsed 's/old/new/g' file.txtReplace 'old' with 'new' globally
sed -i 's/foo/bar/g' file.txtReplace in file directly
Pattern scanning and processing language
Syntax:
awk [options] 'program' file...-FField separator-vAssign variableawk '{print $1}' file.txtPrint first column
awk -F: '{print $1}' /etc/passwdPrint usernames from passwd
Sort lines in text files
Syntax:
sort [options] file...-rReverse sort order-nNumeric sort-uRemove duplicates-kSort by specific fieldsort file.txtSort file alphabetically
sort -n numbers.txtSort numerically
Report or omit repeated lines
Syntax:
uniq [options] file...-cCount occurrences-dOnly show duplicates-uOnly show unique linesuniq file.txtRemove consecutive duplicates
sort file.txt | uniq -cCount unique lines
Word, line, character, and byte count
Syntax:
wc [options] file...-lCount lines-wCount words-cCount bytes-mCount characterswc file.txtShow lines, words, and bytes
wc -l file.txtCount lines only
Extract sections from lines
Syntax:
cut [options] file...-dField delimiter-fSelect fields-cSelect characterscut -d: -f1 /etc/passwdExtract usernames
cut -c1-10 file.txtExtract first 10 characters
Send ICMP echo requests to network hosts
Syntax:
ping [options] destination-cNumber of packets to send-iInterval between packets-tSet TTL value-sPacket sizeping google.comPing Google continuously
ping -c 4 8.8.8.8Send 4 ping packets
Download files from web
Syntax:
wget [options] URL-OOutput filename-cContinue partial download-rRecursive download-qQuiet modewget https://example.com/file.zipDownload file
wget -O myfile.zip https://example.com/file.zipDownload with custom name
Transfer data from/to servers
Syntax:
curl [options] URL-oOutput to file-LFollow redirects-HAdd header-dSend datacurl https://api.example.comGET request to API
curl -o file.html https://example.comDownload to file
Secure Shell remote login
Syntax:
ssh [options] user@hostname-pPort number-iIdentity file (private key)-vVerbose mode-XEnable X11 forwardingssh user@server.comConnect to remote server
ssh -p 2222 user@server.comConnect using custom port
Secure copy files between hosts over SSH
Syntax:
scp [options] source destination-rRecursively copy directories-PSpecify SSH port number-vVerbose mode (show progress)-pPreserve file permissions and timestamps-CEnable compression during transfer-iSpecify SSH private key filescp file.txt user@host:/path/Copy local file to remote server
scp user@host:/path/file.txt .Copy remote file to current directory
scp -r folder/ user@host:/path/Copy directory recursively to remote server
scp -P 2222 file.txt user@host:/path/Copy file using custom SSH port
Synchronize files/directories between locations
Syntax:
rsync [options] source destination-aArchive mode (preserve attributes)-vVerbose mode-zCompress during transfer--deleteDelete files not in sourcersync -av source/ dest/Sync directories with archive mode
rsync -avz user@host:/path/ local/Sync from remote with compression
Display network connections and statistics
Syntax:
netstat [options]-aShow all connections-nShow numerical addresses-tShow TCP connections-uShow UDP connections-lShow listening portsnetstat -anShow all connections with numerical addresses
netstat -tlnpShow listening TCP ports with process info
Display running processes
Syntax:
ps [options]auxShow all processes with detailed info-efShow all processes in full format-uShow processes for specific userps auxShow all running processes
ps -ef | grep nginxFind nginx processes
Display and update sorted information about running processes
Syntax:
top [options]-dDelay between updates-nNumber of iterations-uMonitor specific usertopShow real-time process information
top -u usernameShow processes for specific user
Interactive process viewer (enhanced top)
Syntax:
htop [options]-dDelay between updates-uShow processes for specific userhtopInteractive process monitor
Display filesystem disk space usage
Syntax:
df [options] [filesystem...]-hHuman readable format-TShow filesystem type-iShow inode informationdf -hShow disk usage in human readable format
df -TShow disk usage with filesystem types
Display directory space usage
Syntax:
du [options] [directory...]-hHuman readable format-sSummary (total only)-aShow all files--max-depthLimit directory depthdu -hShow directory sizes in human readable format
du -sh *Show size of each item in current directory
Display memory usage
Syntax:
free [options]-hHuman readable format-mShow in megabytes-gShow in gigabytesfree -hShow memory usage in human readable format
Display system information
Syntax:
uname [options]-aShow all information-sShow kernel name-rShow kernel release-mShow machine hardware nameuname -aShow all system information
uname -rShow kernel version
Show system uptime and load average
Syntax:
uptime [options]-pShow uptime in pretty format-sShow system up sinceuptimeShow system uptime and load
uptime -pShow uptime in readable format
Display current username
Syntax:
whoamiNo common options
whoamiShow current user
Display user and group IDs
Syntax:
id [options] [user]-uShow user ID only-gShow group ID only-GShow all group IDsidShow current user and group IDs
id usernameShow IDs for specific user
Terminate processes by PID
Syntax:
kill [options] PID...-9Force kill (SIGKILL)-15Terminate gracefully (SIGTERM)-lList available signalskill 1234Terminate process with PID 1234
kill -9 1234Force kill process
Terminate processes by name
Syntax:
killall [options] name...-9Force kill-iInteractive mode-vVerbose modekillall firefoxKill all Firefox processes
killall -9 chromeForce kill all Chrome processes
Display active jobs
Syntax:
jobs [options]-lShow process IDs-pShow process IDs onlyjobsList active background jobs
jobs -lList jobs with PIDs
Put jobs in background
Syntax:
bg [job_spec]No common options
bgPut current job in background
bg %1Put job 1 in background
Bring jobs to foreground
Syntax:
fg [job_spec]No common options
fgBring current job to foreground
fg %1Bring job 1 to foreground
Run commands immune to hangups
Syntax:
nohup command [args...]No common options
nohup ./script.sh &Run script in background, immune to hangups
Change file permissions
Syntax:
chmod [options] mode file...-RRecursive (apply to directories and contents)-vVerbose modechmod 755 script.shSet rwxr-xr-x permissions
chmod +x fileAdd execute permission
chmod -R 644 directory/Set permissions recursively
Change file ownership
Syntax:
chown [options] owner[:group] file...-RRecursive-vVerbose modechown user file.txtChange owner to user
chown user:group file.txtChange owner and group
chown -R user:group directory/Change ownership recursively
Change group ownership
Syntax:
chgrp [options] group file...-RRecursive-vVerbose modechgrp staff file.txtChange group to staff
chgrp -R users directory/Change group recursively
Set default file permissions
Syntax:
umask [mode]-SShow symbolic modeumaskShow current umask
umask 022Set umask to 022
Archive files
Syntax:
tar [options] archive file...-cCreate archive-xExtract archive-vVerbose mode-fSpecify archive file-zUse gzip compression-jUse bzip2 compressiontar -czf archive.tar.gz directory/Create compressed archive
tar -xzf archive.tar.gzExtract compressed archive
tar -tvf archive.tarList archive contents
Compress files
Syntax:
gzip [options] file...-dDecompress-rRecursive-vVerbose mode-9Best compressiongzip file.txtCompress file
gzip -d file.txt.gzDecompress file
Decompress gzip files
Syntax:
gunzip [options] file...-vVerbose mode-tTest archive integritygunzip file.txt.gzDecompress gzip file
Create ZIP archives
Syntax:
zip [options] archive file...-rRecursive-vVerbose mode-9Best compressionzip -r archive.zip directory/Create ZIP archive
zip archive.zip file1 file2Add files to ZIP
Extract ZIP archives
Syntax:
unzip [options] archive-dExtract to directory-lList archive contents-vVerbose modeunzip archive.zipExtract ZIP archive
unzip -d /tmp archive.zipExtract to specific directory
Search for files and directories
Syntax:
find [path] [expression]-nameSearch by filename-typeSearch by file type (f=file, d=directory)-sizeSearch by file size-mtimeSearch by modification time-execExecute command on found filesfind . -name '*.txt'Find all .txt files in current directory
find /home -type d -name 'Documents'Find directories named 'Documents'
find . -size +100MFind files larger than 100MB
Find files by name (uses database)
Syntax:
locate [options] pattern-iCase insensitive-cCount matches-rUse regexlocate filenameFind files containing 'filename'
locate -i readmeCase insensitive search for readme
Locate command
Syntax:
which command-aShow all matcheswhich pythonFind location of python command
which -a gccFind all gcc installations
Locate binary, source, and manual page files
Syntax:
whereis [options] command-bSearch only for binaries-mSearch only for manuals-sSearch only for sourceswhereis lsFind ls binary, source, and manual
whereis -b gccFind only gcc binary
Display or set environment variables
Syntax:
env [options] [variable=value...] [command]-iStart with empty environment-uUnset variableenvShow all environment variables
env PATH=/usr/bin commandRun command with modified PATH
Set environment variables
Syntax:
export [variable[=value]...]-nRemove variable from export list-pDisplay all exported variablesexport PATH=$PATH:/new/pathAdd to PATH variable
export EDITOR=vimSet default editor
Display text
Syntax:
echo [options] [string...]-nDon't output trailing newline-eEnable interpretation of backslash escapesecho 'Hello World'Display text
echo $PATHDisplay PATH variable
Display command history
Syntax:
history [options] [n]-cClear history-dDelete history entryhistoryShow command history
history 10Show last 10 commands
Create command aliases
Syntax:
alias [name[=value]...]No common options
alias ll='ls -la'Create alias for long listing
aliasShow all aliases
Remove command aliases
Syntax:
unalias [name...]-aRemove all aliasesunalias llRemove ll alias
unalias -aRemove all aliases
Package manager for Debian/Ubuntu
Syntax:
apt [options] command [package...]updateUpdate package listupgradeUpgrade packagesinstallInstall packagesremoveRemove packagessearchSearch packagesapt updateUpdate package list
apt install package-nameInstall package
apt search keywordSearch for packages
Package manager for Red Hat/CentOS
Syntax:
yum [options] command [package...]updateUpdate packagesinstallInstall packagesremoveRemove packagesyum updateUpdate all packages
yum install package-nameInstall package
Modern package manager for Fedora/Red Hat
Syntax:
dnf [options] command [package...]updateUpdate packagesinstallInstall packagesremoveRemove packagesdnf updateUpdate all packages
dnf install package-nameInstall package
Control systemd services
Syntax:
systemctl [options] command [service...]startStart servicestopStop servicerestartRestart serviceenableEnable service at bootdisableDisable service at bootstatusShow service statussystemctl start nginxStart nginx service
systemctl enable sshEnable SSH at boot
systemctl status apache2Check Apache status
Control system services (SysV)
Syntax:
service service_name commandstartStart servicestopStop servicerestartRestart servicestatusShow service statusservice nginx startStart nginx service
service ssh restartRestart SSH service
Schedule tasks
Syntax:
crontab [options]-eEdit crontab-lList crontab-rRemove crontabcrontab -eEdit scheduled tasks
crontab -lList scheduled tasks
Mount filesystems
Syntax:
mount [options] device mountpoint-tFilesystem type-oMount options-aMount all filesystems in fstabmount /dev/sdb1 /mntMount device to /mnt
mount -t ext4 /dev/sdb1 /mntMount with specific filesystem type
Unmount filesystems
Syntax:
umount [options] mountpoint|device-fForce unmount-lLazy unmountumount /mntUnmount /mnt
umount -f /mntForce unmount