Linux Terminal Cheatsheet

Essential Linux commands for file operations, permissions, processes, and system administration.

CommandDescriptionSyntaxExampleCategory
pwdPrint working directorypwdpwdNavigation
cdChange directorycd [path]cd /home/user/projectsNavigation
lsList directory contentsls [options]ls -la /homeNavigation
mkdirCreate directorymkdir [options] pathmkdir -p /path/to/dirFiles
cpCopy files/directoriescp [options] source destcp -r src/ dest/Files
mvMove/rename filesmv source destmv file.txt /home/user/Files
rmRemove files/directories

Careful: rm -rf deletes everything under the path at once: no confirmation, no recycle bin. Check the path before pressing Enter (a stray space, as in rm -rf / tmp, starts from /). Use rm -ri to be asked for each file when unsure.

rm [options] pathrm -rf /path/to/dirFiles
touchCreate empty filetouch filenametouch new_file.txtFiles
catView file contentscat filenamecat /etc/hostnameFiles
lessView file with paginationless filenameless /var/log/syslogFiles
headView first lines of filehead -n count filenamehead -n 20 file.txtFiles
tailView last lines of filetail -n count filenametail -f /var/log/app.logFiles
chmodChange file permissions

Careful: Avoid chmod 777: it lets every user change or replace the file. Usual values are 755 for scripts and folders and 644 for ordinary files. Be wary of chmod -R on system folders, which is hard to undo.

chmod mode filechmod 755 script.shPermissions
chownChange file ownerchown user:group filechown user:group /home/user/filePermissions
sudoExecute with super user privileges

Careful: sudo runs the command as root, so permission checks no longer protect you. Only use it for commands you understand, and never pipe a downloaded script straight into sudo bash.

sudo commandsudo apt-get install packagePermissions
psList running processesps [options]ps auxProcesses
killTerminate process

Careful: kill -9 (SIGKILL) stops the process instantly, with no chance to save work or clean up, which can corrupt files or leave locks behind. Try plain kill 1234 (SIGTERM) first and use -9 only if it does not stop.

kill -signal pidkill -9 1234Processes
topMonitor system processestoptopProcesses
findSearch for filesfind path -name patternfind /home -name "*.js"Search
grepSearch file contentsgrep [options] pattern filegrep -r "function" src/Search
dfShow disk space usagedf [options]df -hSystem
duShow directory sizedu [options] pathdu -sh /home/userSystem
whoamiShow current userwhoamiwhoamiSystem
unameShow system informationuname [options]uname -aSystem
tar (create)Pack a folder into a gzip-compressed archivetar -czf archive.tar.gz folder/tar -czf backup-2026-11.tar.gz ~/projectsArchives
tar (extract)Unpack a .tar.gz archive, optionally into another foldertar -xzf archive.tar.gz [-C dir]tar -xzf backup-2026-11.tar.gz -C /tmp/restoreArchives
tar (list)List what is inside an archive without unpacking ittar -tzf archive.tar.gztar -tzf backup-2026-11.tar.gz | headArchives
gzip / gunzipCompress or decompress a single file (replaces the original)gzip file | gunzip file.gzgzip -k access.log # -k keeps the originalArchives
zip / unzipCreate or extract .zip files (handy for sharing with Windows users)zip -r out.zip dir/ | unzip out.zip -d dir/zip -r site.zip public/ && unzip site.zip -d /tmp/siteArchives
ipShow network interfaces and IP addressesip addr | ip routeip -brief addrNetworking
pingCheck whether a host is reachable and how long replies takeping -c count hostping -c 4 bharatscholar.comNetworking
curlMake an HTTP request: fetch a page, an API or just its headerscurl [options] URLcurl -I https://bharatscholar.com # headers onlyNetworking
wgetDownload a file from a URLwget [options] URLwget -c https://example.com/big.iso # -c resumesNetworking
ssList open sockets: which ports are listening and which program owns themss [options]ss -tulpnNetworking
digLook up DNS records for a domaindig domain [type]dig bharatscholar.com MX +shortNetworking
tracerouteShow each network hop on the way to a hosttraceroute hosttraceroute google.comNetworking
sshLog in to a remote machine securelyssh [-p port] user@hostssh -p 2222 deploy@203.0.113.10SSH & remote
ssh-keygenCreate an SSH key pair (use instead of passwords)ssh-keygen -t ed25519 -C "comment"ssh-keygen -t ed25519 -C "laptop"SSH & remote
ssh-copy-idInstall your public key on a server so you can log in without a passwordssh-copy-id user@hostssh-copy-id deploy@203.0.113.10SSH & remote
scpCopy files to or from a remote machine over SSHscp source user@host:pathscp report.pdf deploy@203.0.113.10:/srv/files/SSH & remote
rsyncSync folders locally or over SSH, copying only what changed

Careful: With --delete, rsync removes files in the destination that are not in the source. Run it once with -n (dry run) first.

rsync -avz source/ dest/rsync -avz --delete site/ deploy@203.0.113.10:/var/www/site/SSH & remote