Linux Commands Cheat Sheet (CCNA/CCNP/DevOps)

Basic Navigation & Listing

Command Description Example
clearClear the terminal screenclear
ls -lList files and directories of current folder in detail long formatls -l
ls -aList all files and directories including hidden in current folderls -a
ls -RaList all files, directories and subdirectories, including hiddenls -R
ls -d */List directories only in current folderls -d */
tree -dDisplay all directories and subdirectories in tree formattree -d
cdChange directorycd /etc/hosts
cd ..Move up one directorycd ..
cd /Go to root directorycd /
cdGo to home directorycd (or cd ~)
cd ~/dirGo to a subdirectory of home directorycd ~/automation
cd –Go to previous directorycd -
mkdirCreate a directorymkdir scripts
rmdirRemove single empty directoryrmdir reports
rm -rRemove directory and subdirectoriesrm -r config
rm -f *Force remove all files in current folder with no promptsrm -f *
mvMove files or directoriesmv file1.txt ~/automation
mvRename files or directoriesmv file1.txt file2.txt
pwdPrint working directorypwd
cpCopy file to a subdirectory of home directorycp file1.txt ~/documents
cp -rCopy directory and all subdirectories to destinationcp -r dir1 dir2

Text Editors & Viewing

Command Description Example
nanoOpen or create file in nano editornano file.txt
sudo nanoEdit a system configuration file in nano editorsudo nano custom.yaml
catDisplay file contentscat file.txt

Networking

Command Description Example
ip aShow IP addressingip a
ip route showShow routing tableip route show
sudo ip route addAdd a static routesudo ip route add 192.168.2.0/24 via 192.168.1.1 dev ens33
sudo ip route delDelete a static routesudo ip route del 192.168.2.0/24 via 192.168.1.1 dev ens33
sudo ip route add default Add a default routesudo ip route add default via 172.16.1.1 dev ens33
sudo ip route del default Delete a default routesudo ip route del default via 172.16.1.1 dev ens33
sudo ip addr addAdd IP addresssudo ip addr add 192.168.1.1/24 dev ens33
sudo ip addr delDelete IP addresssudo ip addr del 192.168.1.1/24 dev ens33
sudo netplanUpdate and activate network configurationnetplan apply
netplan generate
ip link showShow interface status and MAC addressip link show ens33
ip neighbor showShow ARP tableip neighbor show
ip -6 neighbor showShow IPv6 neighborsip -6 neighbor show
ethtool -SShow interface statsethtool -S ens33
ip link set dev <int> mtu <value>Set interface MTUsudo ip link set dev ens33 mtu 1400
curl ipinfo.io/ipShow NAT public IP (CLI)curl ipinfo.io/ip
ipinfo.io/ipShow NAT public IP (browser)ipinfo.io/ip
pingTest network connectivity + DNSping google.com
sudo mtrMonitor network connection continuouslysudo mtr 8.8.8.8
sudo tracerouteShow network forwarding path (route)sudo traceroute 8.8.8.8
tracepathTraceroute alternate using UDP packetstracepath 8.8.8.8
digdetailed DNS lookupdig udemy.com
nslookupbasic DNS lookupnslookup udemy.com
sudo ss -tulnpShow application listening socketssudo ss -tulnp
telnetTest TCP open port connectiontelnet 192.168.1.1 22
sshConnect via SSHssh shaun@192.168.2.1
sudo tcpdumpCapture network packetssudo tcpdump -i ens33
curl -I urlGet HTTP headers for analysiscurl -I https://example.com
wgetDownload filewget https://example.com/file

Package Management & Git

Command Description Example
sudo apt updateUpdate package indexsudo apt update
sudo apt upgradeUpgrade packagessudo apt upgrade
sudo apt installInstall package/ssudo apt install -y nmap traceroute
ansible –versionShow Ansible versionansible --version
python3 -m pip installInstall a Python packagepython3 -m pip install netmiko
pip showShow Python package infopip show napalm
dpkg -lList installed packagesdpkg -l
gitVersion control toolgit status

System & Process Monitoring

Command Description Example
topShow running processes and resource usagetop
htopInteractive user-friendly graphical version of tophtop
df -hShow disk space usage (human-readable) df -h
free -mShow memory usage in MBfree -m
psShow current processes runningps
envShow environment variablesenv
whichLocate an executablewhich python3
historyShow commands types at bash terminalhistory
uptimeShow system uptimeuptime
uname -aShow system infouname -a
hostnameShow hostnamehostname
dateShow datedate
sudo timedatectlShow or set time/timezone and verify NTP statussudo timedatectl
whoamiShow current logged-in userwhoami
exitExit shellexit
sudo rebootReboot systemsudo reboot
sudo shutdownShutdown systemsudo shutdown now

User & Permissions

Command Description Example
sudo adduserCreate user with home directory and password sudo adduser user2
sudo useraddCreate username onlysudo useradd user2
sudo userdel -rDelete user and home directorysudo userdel -r user1
sudo groupaddAdd new groupsudo groupadd automation
sudo groupdelDelete groupsudo groupdel devops
sudo usermod -a -G group userAdd user to groupsudo usermod -a -G devops user1
sudo passwdChange password for a usernamesudo passwd user1
sudo chmodChange permissions on directory and subdirectoriessudo chmod -R 777 file.sh
sudo chmod +x file.shAdd execute permission to a filesudo chmod +x file.sh
sudo chown -vChange file ownershipsudo chown -v user:group file.sh
su – ‘user’Switch user accountsu - shaun
su –Switch to root accountsu -

Disk & Storage

Command Description Example
lsblkList block devices (HDD, USB etc)lsblk
sudo mountMount filesystemsudo mount /dev/sdb1 /mnt
du -shShow disk usage of a directorydu -sh /home/user
tarArchive filestar -cvf folder.tar folder_to_tar
venvCreate Python virtual environmentpython3 -m venv myenv

Firewall & Networking Tools

Command Description Example
sudo ufw status verboseShow firewall statussudo ufw status verbose
sudo ufw allowAllow inbound protocol traffic through host firewallsudo ufw allow 22/tcp
sudo nft list rulesetList nftables rulessudo nft list ruleset
sudo iptables -L -nList iptables rules (legacy)sudo iptables -L -n
sudo cdpcli showShow CDP neighbor informationsudo cdpcli show neighbors
sudo lldpctlShow LLDP neighbor informationsudo lldpctl

Text Processing

Command Description Example
grepSearch textgrep "error" logfile.txt
awkProcess textawk '{print $1}' file.txt
sedStream editorsed 's/dir/dir/' file.txt
tail -f -nShow bottom lines of log file (e.g., 10) and monitor real-timetail -f -n 10 logfile.txt

Other

Command Description Example
manShow manual page for a commandman ls

Free Course