Linux Commands

📁 Linux Commands – File Operations & Navigation

TopicQuestionAnswer
LinuxGet all files realpathsfind . -exec realpath {} +
LinuxFind file by namefind . -name "file.txt"
LinuxFind file name case insensitivefind . -iname "file.txt"
LinuxFind all *.txt filesfind . -name "*.txt"
LinuxFind file containing text in namefind . -name "*report*"
LinuxRemove empty directoriesfind . -type d -empty -delete
LinuxDelete all files of specific formatfind . -name "*.log" -delete
LinuxFind directoriesfind . -type d -name "foldername"
LinuxFind modified in last 1 dayfind . -mtime -1
LinuxFind modified more than 7 days agofind . -mtime +7
LinuxFind modified in last 60 minutesfind . -mmin -60
LinuxFind accessed in last N daysfind . -atime -N
LinuxFind by size greater than 100mbfind . -size +100M
LinuxFind by size less than 10mbfind . -size -10M
LinuxFind by exact sizefind . -size 1024c
LinuxFind empty filesfind . -size 0
LinuxFind file + grepfind . -type f -name "*.sv" -exec grep -l "uvm_component" {} \;
LinuxDelete all empty filesfind . -type f -empty -delete
LinuxFind and move filesfind . -name "*.bak" -exec mv {} /backup/ \;
LinuxFind files owned by userfind . -user username
LinuxFind files by permissionsfind . -perm 644
LinuxFind writable filesfind . -perm -200
LinuxFind executable filesfind . -type f -executable
LinuxFind symbolic linksfind . -type l
LinuxFind broken symbolic linksfind . -xtype l
LinuxFind and count filesfind . -type f | wc -l
LinuxFind files excluding directoryfind . -path ./exclude -prune -o -name "*.txt"
LinuxFind by multiple extensionsfind . -name "*.sv" -o -name "*.v"
LinuxClear terminalCTRL + l or clear
LinuxExit terminalCTRL + d or exit
LinuxList files with detailsls -lah
LinuxList files sorted by timels -lt
LinuxList files sorted by sizels -lS
LinuxList files reverse orderls -lr
LinuxList with inode numbersls -li
LinuxList only directoriesls -d */
LinuxList with full pathls -d $PWD/*
LinuxList recursivelyls -R
LinuxList one per linels -1
LinuxList with file type indicatorsls -F
LinuxShow disk usagedu -sh *
LinuxShow disk usage sorteddu -sh * | sort -h
LinuxShow directory sizedu -sh directory/
LinuxShow total disk usagedu -ch
LinuxShow free disk spacedf -h
LinuxShow inode usagedf -i
LinuxShow specific filesystemdf -h /dev/sda1
LinuxCreate directorymkdir dirname
LinuxCreate directory with parentsmkdir -p path/to/directory
LinuxCreate multiple directoriesmkdir dir1 dir2 dir3
LinuxCreate directory with permissionsmkdir -m 755 dirname
LinuxRemove empty directoryrmdir dirname
LinuxRemove directory recursivelyrm -rf directory_name
LinuxRemove directory interactivelyrm -ri directory_name
LinuxCopy filecp source.txt dest.txt
LinuxCopy files recursivelycp -r source_dir dest_dir
LinuxCopy preserving attributescp -p file dest
LinuxCopy with verbose outputcp -v file dest
LinuxCopy force overwritecp -f file dest
LinuxCopy only if newercp -u file dest
LinuxCopy creating backupcp --backup file dest
LinuxMove/Rename filesmv old_name new_name
LinuxMove multiple filesmv file1 file2 file3 dest/
LinuxMove with backupmv --backup file dest
LinuxMove no clobbermv -n file dest
LinuxCreate hard linkln file linkname
LinuxCreate symbolic linkln -s /path/to/file linkname
LinuxCreate symbolic link forceln -sf /path/to/file linkname
LinuxShow current directorypwd
LinuxShow physical directory (resolve symlinks)pwd -P
LinuxChange to home directorycd ~ or cd
LinuxGo to previous directorycd -
LinuxGo up one levelcd ..
LinuxGo up two levelscd ../..
LinuxChange to rootcd /
LinuxTouch create filetouch newfile.txt
LinuxTouch update timestamptouch existing.txt
LinuxTouch with specific timetouch -t 202401011200 file.txt
LinuxTouch set access timetouch -a file.txt
LinuxTouch set modification timetouch -m file.txt

TopicQuestionAnswer
LinuxSearch text in filesgrep "pattern" file.txt
LinuxSearch recursivelygrep -r "pattern" directory/
LinuxSearch case insensitivegrep -i "pattern" file.txt
LinuxSearch with line numbersgrep -n "pattern" file.txt
LinuxSearch with contextgrep -C 3 "pattern" file.txt
LinuxSearch with before contextgrep -B 2 "pattern" file.txt
LinuxSearch with after contextgrep -A 2 "pattern" file.txt
LinuxCount matching linesgrep -c "pattern" file.txt
LinuxInverse matchgrep -v "pattern" file.txt
LinuxSearch whole wordgrep -w "word" file.txt
LinuxSearch multiple patternsgrep -e "pat1" -e "pat2" file.txt
LinuxSearch with regexgrep -E "regex" file.txt or egrep
LinuxSearch with extended regexgrep -P "perl_regex" file.txt
LinuxShow only matching partgrep -o "pattern" file.txt
LinuxSearch in multiple filesgrep "pattern" *.txt
LinuxSearch with filename onlygrep -l "pattern" *.txt
LinuxSearch without filenamegrep -h "pattern" *.txt
LinuxSearch binary filesgrep -a "pattern" file
LinuxSearch excluding filesgrep --exclude="*.log" "pattern" *
LinuxSearch excluding directorygrep --exclude-dir=".git" -r "pattern"
LinuxView file contentscat file.txt
LinuxView with line numberscat -n file.txt
LinuxView showing tabscat -T file.txt
LinuxView showing endscat -E file.txt
LinuxConcatenate filescat file1 file2 > combined.txt
LinuxView first 10 lineshead file.txt
LinuxView first N lineshead -n 20 file.txt
LinuxView first N byteshead -c 100 file.txt
LinuxView multiple fileshead file1 file2
LinuxView last 10 linestail file.txt
LinuxView last N linestail -n 50 file.txt
LinuxView from line Ntail -n +10 file.txt
LinuxFollow file real-timetail -f file.log
LinuxFollow with retrytail -F file.log
LinuxFollow multiple filestail -f file1 file2
LinuxView page by pageless file.txt
LinuxView with moremore file.txt
LinuxCount lineswc -l file.txt
LinuxCount wordswc -w file.txt
LinuxCount characterswc -c file.txt
LinuxCount byteswc -c file.txt
LinuxCount longest linewc -L file.txt
LinuxSort filesort file.txt
LinuxSort numericallysort -n file.txt
LinuxSort reversesort -r file.txt
LinuxSort by columnsort -k 2 file.txt
LinuxSort case insensitivesort -f file.txt
LinuxSort uniquesort -u file.txt
LinuxSort by monthsort -M file.txt
LinuxSort human numericsort -h file.txt
LinuxRemove duplicatessort file.txt | uniq
LinuxCount duplicatessort file.txt | uniq -c
LinuxShow only duplicatessort file.txt | uniq -d
LinuxShow only uniquesort file.txt | uniq -u
LinuxCompare filesdiff file1.txt file2.txt
LinuxCompare side by sidediff -y file1.txt file2.txt
LinuxCompare unified formatdiff -u file1.txt file2.txt
LinuxCompare ignore whitespacediff -w file1.txt file2.txt
LinuxCompare ignore casediff -i file1.txt file2.txt
LinuxCompare directoriesdiff -r dir1/ dir2/
LinuxShow file typefile filename
LinuxShow MIME typefile -i filename
LinuxCut by delimitercut -d ',' -f 1 file.csv
LinuxCut by character positioncut -c 1-10 file.txt
LinuxCut by bytecut -b 1-10 file.txt
LinuxPaste filespaste file1 file2
LinuxPaste with delimiterpaste -d ',' file1 file2
LinuxColumn formattingcolumn -t file.txt
LinuxTranslate characterstr 'a-z' 'A-Z' < file.txt
LinuxDelete characterstr -d '0-9' < file.txt
LinuxSqueeze repeatstr -s ' ' < file.txt

🛠️ Linux Commands – System & Process Management

TopicQuestionAnswer
LinuxArchive filestar -czf archive.tar.gz directory/
LinuxArchive with bzip2tar -cjf archive.tar.bz2 directory/
LinuxArchive verbosetar -czvf archive.tar.gz directory/
LinuxExtract archivetar -xzf archive.tar.gz
LinuxExtract to directorytar -xzf archive.tar.gz -C /path/
LinuxList archive contentstar -tzf archive.tar.gz
LinuxExtract single filetar -xzf archive.tar.gz file.txt
LinuxCompress file with gzipgzip file.txt
LinuxDecompress gzipgunzip file.txt.gz
LinuxKeep original with gzipgzip -k file.txt
LinuxCompress with bzip2bzip2 file.txt
LinuxDecompress bzip2bunzip2 file.txt.bz2
LinuxCompress with xzxz file.txt
LinuxDecompress xzunxz file.txt.xz
LinuxCreate zipzip archive.zip file1 file2
LinuxCreate zip recursivezip -r archive.zip directory/
LinuxExtract zipunzip archive.zip
LinuxList zip contentsunzip -l archive.zip
LinuxCheck processesps aux
LinuxCheck process treeps auxf or pstree
LinuxCheck processes for userps -u username
LinuxFind process by nameps aux | grep process_name
LinuxShow process by PIDps -p PID
LinuxShow all threadsps -eLf
LinuxKill processkill PID
LinuxForce killkill -9 PID or kill -SIGKILL PID
LinuxTerminate gracefullykill -15 PID or kill -SIGTERM PID
LinuxKill process by namepkill process_name
LinuxKill all by namekillall process_name
LinuxShow running processestop
LinuxShow processes with htophtop
LinuxSort top by memoryPress M in top
LinuxSort top by CPUPress P in top
LinuxKill from topPress k in top
LinuxShow system uptimeuptime
LinuxShow load averageuptime or cat /proc/loadavg
LinuxShow memoryfree -h
LinuxShow memory in MBfree -m
LinuxShow memory continuousfree -s 2
LinuxShow swap usageswapon --show
LinuxShow current userwhoami
LinuxShow effective user IDid
LinuxShow all logged userswho
LinuxShow detailed user infow
LinuxShow last loginslast
LinuxShow failed loginslastb
LinuxShow login historylastlog
LinuxChange permissionschmod 755 file.sh
LinuxChange recursivelychmod -R 755 directory/
LinuxAdd execute permissionchmod +x file.sh
LinuxRemove write permissionchmod -w file.txt
LinuxSet user permissionschmod u+rwx file
LinuxSet group permissionschmod g+rw file
LinuxSet other permissionschmod o+r file
LinuxChange ownershipchown user:group file.txt
LinuxChange owner onlychown user file.txt
LinuxChange group onlychgrp group file.txt
LinuxChange ownership recursivechown -R user:group directory/
LinuxMake file executablechmod +x script.sh
LinuxView file permissionsls -l file.txt
LinuxView octal permissionsstat -c "%a %n" file
LinuxSet setuid bitchmod u+s file
LinuxSet setgid bitchmod g+s file
LinuxSet sticky bitchmod +t directory/
LinuxChange file ACLsetfacl -m u:user:rwx file
LinuxView file ACLgetfacl file

🌐 Linux Commands – Network & Remote

TopicQuestionAnswer
LinuxDownload filewget URL
LinuxDownload with curlcurl -O URL
LinuxDownload to filecurl -o filename URL
LinuxDownload continuewget -c URL
LinuxDownload in backgroundwget -b URL
LinuxDownload with user agentwget --user-agent="agent" URL
LinuxDownload FTPwget ftp://server/file
LinuxCheck connectivityping google.com
LinuxPing countping -c 4 google.com
LinuxPing with intervalping -i 2 google.com
LinuxTraceroutetraceroute google.com
LinuxDNS lookupnslookup google.com
LinuxDNS with digdig google.com
LinuxReverse DNSdig -x IP_ADDRESS
LinuxShow network interfacesifconfig or ip addr
LinuxShow specific interfaceifconfig eth0
LinuxBring interface upsudo ifconfig eth0 up
LinuxBring interface downsudo ifconfig eth0 down
LinuxShow routing tableroute -n or ip route
LinuxAdd routesudo route add -net 192.168.1.0/24 gw 192.168.1.1
LinuxShow listening portsnetstat -tuln or ss -tuln
LinuxShow all connectionsnetstat -a
LinuxShow TCP connectionsnetstat -t
LinuxShow UDP connectionsnetstat -u
LinuxShow with PIDnetstat -tulnp
LinuxShow statisticsnetstat -s
LinuxShow network socketsss -s
LinuxTest portnc -zv host port or telnet host port
LinuxSecure copy to remotescp file.txt user@host:/path/
LinuxSecure copy from remotescp user@host:/path/file.txt .
LinuxSCP with portscp -P 2222 file.txt user@host:/path/
LinuxSCP recursivescp -r directory/ user@host:/path/
LinuxSSH to remotessh user@hostname
LinuxSSH with portssh -p 2222 user@hostname
LinuxSSH with keyssh -i keyfile user@hostname
LinuxSSH execute commandssh user@host 'command'
LinuxSSH tunnelssh -L localport:remotehost:remoteport user@host
LinuxRsync filesrsync -avz source/ destination/
LinuxRsync with progressrsync -avz --progress source/ dest/
LinuxRsync with deletersync -avz --delete source/ dest/
LinuxRsync dry runrsync -avz --dry-run source/ dest/
LinuxRsync over SSHrsync -avz -e ssh source/ user@host:dest/
LinuxShow ARP tablearp -a
LinuxFlush DNS cachesudo systemd-resolve --flush-caches
LinuxShow hostnamehostname
LinuxShow FQDNhostname -f
LinuxShow IP addresshostname -I
LinuxSet hostnamesudo hostnamectl set-hostname newname

⚙️ Linux Commands – Shell & Environment

TopicQuestionAnswer
LinuxSearch command historyhistory | grep "keyword"
LinuxExecute previous command!!
LinuxExecute command from history!number
LinuxExecute last command starting with!string
LinuxClear command historyhistory -c
LinuxDelete history entryhistory -d number
LinuxShow environment variablesprintenv or env
LinuxSet environment variableexport VAR_NAME="value"
LinuxUnset environment variableunset VAR_NAME
LinuxShow specific variableecho $VAR_NAME
LinuxShow all variablesset
LinuxShow PATHecho $PATH
LinuxAdd to PATHexport PATH=$PATH:/new/path
LinuxShow shellecho $SHELL
LinuxFind which commandwhich command_name
LinuxShow command locationwhereis command_name
LinuxShow command typetype command_name
LinuxShow all locationswhich -a command_name
LinuxCreate aliasalias ll='ls -la'
LinuxShow all aliasesalias
LinuxRemove aliasunalias ll
LinuxPermanent aliasAdd to ~/.bashrc or ~/.bash_aliases
LinuxSource bashrcsource ~/.bashrc or . ~/.bashrc
LinuxRun command in backgroundcommand &
LinuxBring to foregroundfg
LinuxBring specific jobfg %1
LinuxSend to backgroundbg
LinuxList background jobsjobs
LinuxDisown jobdisown %1
LinuxRedirect outputcommand > output.txt
LinuxAppend outputcommand >> output.txt
LinuxRedirect errorscommand 2> error.log
LinuxRedirect bothcommand > output.txt 2>&1
LinuxRedirect to nullcommand > /dev/null
LinuxRedirect both to nullcommand > /dev/null 2>&1
LinuxPipe commandscommand1 | command2
LinuxTee to file and stdoutcommand | tee output.txt
LinuxTee appendcommand | tee -a output.txt
LinuxRun multiple commandscommand1 && command2
LinuxRun if previous fails`command1 |
LinuxRun sequentiallycommand1 ; command2
LinuxShow datedate
LinuxShow date formatteddate "+%Y-%m-%d %H:%M:%S"
LinuxShow date UTCdate -u
LinuxShow calendarcal
LinuxShow specific monthcal 12 2024
LinuxShow year calendarcal 2024
LinuxCalculate MD5md5sum file.txt
LinuxCalculate SHA1sha1sum file.txt
LinuxCalculate SHA256sha256sum file.txt
LinuxVerify checksummd5sum -c checksums.txt
LinuxBase64 encodebase64 file.txt
LinuxBase64 decodebase64 -d encoded.txt

📝 Linux Commands – Text Editors (sed, awk)

TopicQuestionAnswer
LinuxReplace text in filessed 's/old/new/g' file.txt
LinuxReplace in-placesed -i 's/old/new/g' file.txt
LinuxReplace with backupsed -i.bak 's/old/new/g' file.txt
LinuxDelete linessed '/pattern/d' file.txt
LinuxDelete empty linessed '/^$/d' file.txt
LinuxPrint specific linessed -n '10,20p' file.txt
LinuxReplace on specific linesed '5s/old/new/' file.txt
LinuxInsert line beforesed '/pattern/i\New line' file.txt
LinuxAppend line aftersed '/pattern/a\New line' file.txt
LinuxPrint specific columnsawk '{print $1, $3}' file.txt
LinuxPrint with separatorawk -F',' '{print $1}' file.csv
LinuxSum column valuesawk '{sum+=$1} END {print sum}' file.txt
LinuxPrint line numbersawk '{print NR, $0}' file.txt
LinuxFilter by conditionawk '$3 > 100' file.txt
LinuxPrint number of fieldsawk '{print NF}' file.txt
LinuxPattern matchingawk '/pattern/ {print}' file.txt
LinuxBegin and endawk 'BEGIN {print "Start"} {print} END {print "End"}' file

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top