Linux commands

Linux
Most used Unix/Linux Commands

Most used Linux/Unix commands

CommandDescription
apropos whatisShow commands pertinent to string. You may need to first run: sudo mandb
man -t ascii | ps2pdf → ascii.pdfMake a PDF of a manual page
 which commandShow full path name of command
 time commandSee how long a command takes
time catStart stopwatch. Ctrl‑d to stop. See also sw
Dir Navigation
cd –Go to previous directory
cdGo to $HOME directory
 (cd dir && command)Go to dir, run command then return
pushd .Push current dir on stack; return via popd
File Searching
alias l='ls -l --color=auto'Quick dir listing. (See also ls_color)
ls -lrtList files by date (newest last).
ls /usr/bin | pr -T9 -W$COLUMNSPrint in 9 columns
 find -name '*.[ch]' | xargs grep -E 'expr'Search files for expr()
 find … | xargs grep -F 'example'Search for text in files
 find –maxdepth 1 …Search in current dir only
find -type f ! -perm -444Find unreadable files
find -type d ! -perm -111Find inaccessible dirs
locate -r 'file[^/]*\.txt'Cached search for names
look referenceSearch prefix in dictionary
grep --color reference /usr/share/dict/wordsHighlight regex matches
File Comparison
diff -u old.c new.cUnified diff
diff -r dir1 dir2Recursively compare two directories
 comm -options file1 file2Compare sorted files
cmp file1 file2Show first difference between two binary files
 md5sum filePrint MD5 checksum for file
File Viewing
cat -n fileShow file with line numbers
less fileView file one page at a time
 head -n 20 fileShow first 20 lines
 tail -n 20 fileShow last 20 lines
tail -f fileFollow file as it grows
Disk Usage
df -hHuman-readable free space on mounted filesystems
du -sh *Summarize disk usage for files and directories
 du -sh .[!.]* *Include hidden files and directories
ncduInteractive disk usage viewer
Permissions
chmod 755 fileSet rwxr-xr-x permissions
 chmod -R o-r *Remove read permission for others recursively
 chown user:group fileChange owner and group
 umask 022Set default permissions: rwxr-xr-x
Archiving & Compression
tar czf file.tar.gz filesCreate gzip-compressed archive
tar xzf file.tar.gzExtract gzip-compressed archive
 gzip -d file.gzDecompress gzip file
zip -r file.zip dirCreate zip archive
 unzip file.zipExtract zip archive
Networking
ping hostTest network connection
wget urlDownload file from URL
curl -O urlDownload file with curl
 scp file user@host:/pathSecure copy to remote host
 rsync -av file user@host:/pathEfficient file transfer
Process Management
topInteractive process viewer
ps auxShow all running processes
 kill pidSend SIGTERM to process
kill -9 pidForce kill a process
pkill nameKill process by name
Miscellaneous
alias ll='ls -lh'Create a shortcut command
 history | grep commandSearch command history
!!Repeat last command
 !abcRepeat last command starting with abc
Git Commands
git initInitialize new repository
git clone URLClone remote repository
git statusShow changed files
git add fileStage file for commit
git commit -m "msg"Commit changes
git logShow commit history
git diffShow changes not staged
git branchList local branches
git checkout branchSwitch to branch
git merge branchMerge branch into current
git pullUpdate from remote
git pushSend commits to remote
systemd Commands
systemctl statusShow system status
systemctl status nameStatus of a specific service
systemctl start nameStart a service
systemctl stop nameStop a service
systemctl restart nameRestart a service
systemctl enable nameEnable service at boot
systemctl disable nameDisable service at boot
journalctl -xeView recent system logs
systemctl list-units --type=serviceList active services
Docker Commands
docker psList running containers
docker ps -aList all containers
docker imagesList images
docker pull imageDownload image
docker run -it imageRun container interactively
docker exec -it name bashRun bash inside container
docker stop nameStop container
docker rm nameRemove container
docker rmi imageRemove image
docker-compose upStart containers from compose file
docker-compose downStop and remove containers
SSH Commands
ssh user@hostConnect to host
ssh -i key.pem user@hostUse private key to connect
ssh-copy-id user@hostCopy public key to remote
scp file user@host:/pathCopy file to remote
scp user@host:/file .Copy file from remote
rsync -avz src/ user@host:/destEfficient directory sync
tmux Commands
tmuxStart new session
tmux lsList sessions
tmux attach -t nameAttach to session
tmux new -s nameNew named session
Ctrl-b dDetach session
Ctrl-b cNew window
Ctrl-b n / pNext/previous window
Ctrl-b "Split horizontal
Ctrl-b %Split vertical
Ctrl-b xClose pane
sed & awk
sed 's/foo/bar/' fileReplace first "foo" with "bar"
sed -i 's/foo/bar/g' fileReplace all and edit in-place
sed -n '5,10p' filePrint lines 5 to 10
awk '{print $1}' filePrint first column
awk -F ':' '{print $1}' fileSplit by colon, print first field
awk '/pattern/ {print $0}' filePrint lines matching pattern
System Info
uname -aKernel and architecture
hostnamectlShow hostname and OS info
uptimeShow system uptime
whoamiCurrent user
idUser ID and groups
top / htopRunning processes
df -hDisk usage
free -hMemory usage
lsblkList block devices
lscpu / lsusb / lspciCPU / USB / PCI info

Previous Post Next Post