Skip to main content

Linux Commands

This guide presents the most essential Linux commands you’ll use for everyday tasks, organized by category.


File and Directory Management

CommandDescriptionExample Usage
lsList directory contentsls -l
cdChange current directorycd /path/to/dir
pwdShow current directorypwd
mkdirMake new directorymkdir new_folder
rmdirRemove empty directoryrmdir old_folder
rmRemove file/directoryrm file.txt
rm -r dir
cpCopy files/directoriescp source dest
mvMove or rename files/directoriesmv old_name new_name
touchCreate an empty filetouch file.txt
catDisplay file contentscat file.txt
nano/vimEdit files in terminalnano file.txt
vim file.txt

System and User Management

CommandDescriptionExample Usage
sudoRun commands as superusersudo apt update
passwdChange user passwordpasswd
adduserAdd a new usersudo adduser username
deluserDelete a usersudo deluser username
chownChange file/directory ownersudo chown user file.txt
chmodChange file permissionschmod 755 script.sh
idShow user identityid
groupsShow group membershipsgroups

Package Management (Ubuntu/Debian)

CommandDescriptionExample Usage
apt updateUpdate package indexsudo apt update
apt upgradeUpgrade installed packagessudo apt upgrade
apt installInstall a packagesudo apt install curl
apt removeRemove a packagesudo apt remove nginx
apt searchSearch for a packageapt search nginx

Disk and Process Management

CommandDescriptionExample Usage
df -hShow disk usagedf -h
du -shShow directory/file sizedu -sh /home/user
topMonitor system processestop
htopAdvanced process viewerhtop
ps auxList running processesps aux
killKill a process by PIDkill 12345
killallKill all processes by namekillall firefox
free -hShow memory usagefree -h

Networking

CommandDescriptionExample Usage
pingTest network connectivityping example.com
ip aShow network interfacesip a
netstat -tulnShow open/listening portsnetstat -tuln
ss -ltnShow listening TCP portsss -ltn
lsof -i -P -nList all open network connectionslsof -i -P -n
lsof -i :80Show processes using port 80lsof -i :80
sshSSH to a remote machinessh user@host
scpCopy files over SSHscp file.txt user@host:/path/
wgetDownload files from internetwget http://example.com/file
curlDownload or transfer datacurl -O http://url/file

Text Processing

CommandDescriptionExample Usage
grepSearch text patternsgrep "error" logfile.txt
awkPattern scanning/processingawk '{print $1}' file.txt
sedStream editor for textsed 's/old/new/g' file.txt
sortSort lines of text filessort names.txt
head/tailShow start/end of fileshead -10 file.txt, tail -20 file

Miscellaneous

CommandDescriptionExample Usage
echoPrint text to terminalecho "Hello"
historyShow command historyhistory
clearClear terminal screenclear
shutdownShutdown systemsudo shutdown now
rebootReboot systemsudo reboot
dateShow date and timedate
uname -aShow system informationuname -a
manManual/help for a commandman ls
--helpShow command helpls --help

Service Management Commands in Linux

The following table provides commonly used service management commands in Linux, particularly with systemd and service.

Actionsystemctl Commandservice Command
Start a servicesystemctl start <service>service <service> start
Stop a servicesystemctl stop <service>service <service> stop
Restart a servicesystemctl restart <service>service <service> restart
Reload a servicesystemctl reload <service>service <service> reload
Enable at bootsystemctl enable <service>chkconfig <service> on
Disable at bootsystemctl disable <service>chkconfig <service> off
Check statussystemctl status <service>service <service> status
Show all servicessystemctl list-units --type=serviceservice --status-all
Check if enabledsystemctl is-enabled <service>chkconfig --list <service>
Mask a servicesystemctl mask <service>(Not available in service)
Unmask a servicesystemctl unmask <service>(Not available in service)
Reboot systemsystemctl rebootreboot
Shutdown systemsystemctl poweroffshutdown now
View logsjournalctl -u <service> -f(Check /var/log/syslog or others)

🔹 Replace <service> with the actual service name (e.g., nginx, ssh, docker).