100+ Linux Commands Cheat Sheet (With Practical Examples)

100+ Linux Commands Cheat Sheet (With Practical Examples)

In this cheat sheet tutorial I have consolidated a list of Linux commands with examples and man page link to give you an overview on Linux day to day usage. We know Linux is one of the preferred choice for most of the IT domains so having basic knowledge of Linux is mandatory for everyone. I have divided the Linux commands into different section so you can choose to only concentrate on the commands which suits your domain.

I will keep adding and updating this article from time to time to add more commands.


Environment Variables

Variables are local, which means they are specific to a process. Local means local to a process. For example, when you log in on a terminal or open a terminal emulator, you start a process that runs a shell and create this variable TEST with value as deepak

bash
TEST=deepak

Verify the content of this variable

bash
echo $TEST
deepak

Now you open another terminal of the same Linux server and try to access this variable,

bash
echo $TEST

The output would be empty, so our variable is only accessible in the terminal where we created.

Recommended Read:

CommandExample / SyntaxCommentsFor more details
printenvprintenvDisplays environment variables or a specific variable valueman page
envenvRuns a program with a modified environmentman page for env
exportexport TEST=deepak env | grep TESTSets environment variables for the shell sessionman page
setTEST=deepak set | grep TESTDisplays all shell and environment variablesman page

File Management

The commands under this section are very basic commands and must be known to every system administrator. This is definitely not the complete list of Linux commands for file management but can give you a kickstart and can cover most of the basic to complex scenarios.

Recommended Read:

CommandExample / SyntaxPurposeMore details
lsls, ls -l, ls -la, ls -ltrList files (basic, long, hidden, sorted by time)man page
catcat FILENAMEPrint file content to terminalman page
lessless FILENAMEView large files with navigation and scrollingman page
moremore FILENAMEView file page by page (limited navigation)man page
headhead -n 5 FILEShow first lines of file (default 10)man page
tailtail -n 5 FILE, tail -f /var/log/messagesShow last lines or monitor file in real timeman page
sortsort FILESort file content (supports -n, -u)man page
uniquniq FILERemove adjacent duplicate linesman page
filefile FILE, file data.txtIdentify file typeman page
cpcp SRC DEST, cp /root/file /tmp/Copy files or directoriesman page
mvmv old new, mv /root/file /tmp/Move or rename filesman page
grepgrep STRING FILE, grep ssh /etc/servicesSearch text in filesman page
mkdirmkdir DIRCreate directoryman page
touchtouch FILECreate empty fileman page
pwdpwdShow current directoryman page

Finding files and directories

Most of the time we will end up using find command to find files and directories. But I also like which command as it gives is the path of the binary which is required at multiple events when we are required to execute a binary with complete PATH.

Recommended Read:

CommandExample / SyntaxPurposeMore details
whichwhich cmd, which useraddShow full path of executable from $PATHman page
whereiswhereis cmd, whereis sshdLocate binary, source, and man pagesman page
locatelocate file, locate sshdFast search using indexed databaseman page
findfind / -name file, find / -type f -name sshdSearch files in real-time with filtersexamples

Check User Information

Recommended Read:

These are some of the commands which we use to check the last logged in user information and some other commands to get more details on existing user.

CommandExample / SyntaxPurposeMore details
whowho -uShow logged-in users with session detailsman page
usersusersList usernames currently logged inman page
lastlast -aShow login/logout history from /var/log/wtmpman page
fingerfingerDisplay user information (if installed)man page
whoamiwhoamiShow current logged-in userman page
ididDisplay UID, GID, and groupsman page
wwShow logged-in users and their activity

Check System Information

As a sytem and Linux administrator you must be familiar with these commands. These will help you determine the type of server you are working on, such as load, cpu model, hardware model, hardware type etc. Some of the commands may be distribution specific such as hwinfo is only available in SuSE Linux while others are expected to be found on almost all distros.

Recommended Read:

CommandExample/SyntaxCommentsFor more details
uptimeuptimeThe uptime utility displays the current time, system uptime, number of logged-in users, and load averages (1, 5, and 15 minutes).man page
freefree -mThe free utility shows total, used, and free physical (RAM) and swap memory, including kernel buffers.Linux Memory Management
dmidecodedmidecode -t systemdmidecode displays hardware information such as system serial numbers, BIOS details, and firmware information including BIOS revision.man page
lshwlshwlshw extracts detailed hardware configuration including memory, firmware, CPU, cache, and bus speed.man page
hwinfohwinfohwinfo probes system hardware and generates detailed reports (commonly available on SUSE systems).man page
lscpulscpulscpu gathers CPU architecture information from sysfs, /proc/cpuinfo, and architecture-specific libraries.man page
lspcilspcilspci displays information about PCI buses and connected devices.man page
/proc/cpuinfocat /proc/cpuinfoProvides detailed CPU information such as model, architecture, and processor details. This file is also used by lscpu.man page
unameuname [OPTIONS]Prints system information such as kernel name, version, and architecture.man page

Manage System Processes

These Linux commands will help you manage the Linux processes, and will help you troubleshoot any server resource related issues. You can use these commands to monitor your server's resource such as Memory, CPU, disk IO etc.

Recommended Read:

CommandExample / SyntaxPurposeMore details
psps, ps auxDisplay running processesman page
nicenice -n 10 commandStart process with adjusted priorityexample
renicerenice -n 15 PIDChange priority of running processexample
toptopReal-time system and process monitoringexamples
pgreppgrep processFind process IDs by nameman page
pkillpkill processKill processes by nameman page
killkill PID, kill -9 PIDSend signal to process (terminate/force kill)man page
sarsar -u 1 5Monitor system performance over timeexamples
vmstatvmstat 1Show memory, CPU, and process statsman page
iostatiostat -xMonitor disk I/O performanceman page
crondcrontab -eSchedule jobs using cron daemonexamples

Managing Users and Groups

These are some of the basic Linux commands to perform user management such as create, modify, delete user or groups.

Recommended Read:

CommandExample / SyntaxPurposeMore details
useradduseradd USERCreate a new user account with default settingsexamples
usermodusermod OPTIONS USER, usermod -G admin deepakModify user account (e.g. add to group)man page
userdeluserdel USERDelete a user accountman page
passwdpasswd USERSet or update user password, lock/unlock accountexamples
groupaddgroupadd GROUPCreate a new groupexamples
groupdelgroupdel GROUPDelete a groupexamples
groupmodgroupmod OPTIONS GROUP, groupmod -n administrator adminModify group (e.g. rename group)examples
sudo$ sudo COMMAND, $ sudo systemctl network restartRun commands with elevated privilegesguide

Managing Permissions

Linux permission is a very vast topic and here I have only covered the basic commands which we use to assign/modify/remove permissions to files and directories.

Recommended Read:

CommandExample / SyntaxPurposeMore details
chownchown USER:GROUP FILE, chown deepak:admin /tmp/fileChange file owner and groupman page
chmodchmod PERM PATH, chmod 755 /tmp/dir1Change file permissions (symbolic or octal)man page
chgrpchgrp GROUP FILE, chgrp admin /tmp/fileChange group ownershipman page
groupsgroups USER, groups deepakShow groups of a userman page
newgrp$ newgrp GROUP, $ idChange current primary groupman page
setfaclsetfacl -m u:user:perm FILE, setfacl -m u:deepak:rx /tmp/fileSet ACL permissions for users/groupsexamples
getfaclgetfacl FILE, getfacl /tmp/fileView ACL permissionsexamples
chattrchattr +i FILE, chattr +i /tmp/fileChange file attributes (e.g. immutable)examples
lsattrlsattr FILE, lsattr /tmp/fileView file attributes set by chattrexamples

Configure and Troubleshoot Network

This section will help Network engineers who are new to Linux environment. I have tried to place the most used commands for network troubleshooting, we also have tcpdump, iperf, netperf and many other networking tools which are used for troubleshooting network related issues but they can get complicated hence those are not mentioned in this list.

Recommended Read:

CommandExample / SyntaxPurposeMore details
ifconfigifconfigLegacy tool to display network interfaces (use ip addr instead)man page
ipip addr, ip link showModern tool to manage IP, interfaces, and network settingsexamples
routerouteLegacy routing tool (use ip route)ip route
ip routeip route, ip route showView and manage routing tableexamples
ethtoolethtool DEVICE, ethtool -i eth0Display and modify NIC settingsman page
pingping HOST, ping 192.168.0.100Test network connectivityman page
traceroutetraceroute HOST, traceroute 192.168.0.100Trace route to destination hostman page
nmapnmap HOSTScan open ports and servicesman page
netstatnetstat, netstat -tunlpShow network connections and ports (legacy, use ss)man page
nmclinmcliCommand-line tool for NetworkManagerexamples
nmtuinmtuiText-based UI for NetworkManagerexamples
ssss, ss -tunlpDisplay socket statistics (modern replacement for netstat)man page

Managing Partitions and Logical Volumes

One of the primary roles of system administrator would be to configure partitions, storage layouts in the Linux server. Here you can get the list of most used Linux commands for managing partitions and file systems.

Recommended Read:

CommandExample / SyntaxPurposeMore details
dfdfShow disk space usage of mounted filesystemsman page
fdiskfdisk DEVICEManage disk partitions (MBR/GPT)example
cfdiskcfdisk DEVICEInteractive partition table editorman page
partedpartedAdvanced partition management tool (GPT/MS-DOS)example
pvcreatepvcreate DEVICE, pvcreate /dev/sdaCreate LVM physical volumeexample
pvdisplaypvdisplay DEVICEShow physical volume detailsman page
pvspvsDisplay summary of physical volumesman page
vgcreatevgcreate VG PV, vgcreate test_vg /dev/sdaCreate volume groupexample
vgdisplayvgdisplayShow volume group detailsman page
vgsvgsDisplay summary of volume groupsman page
lvcreatelvcreate OPTIONS, lvcreate -L 1G -n lv vgCreate logical volumeexample
lvdisplaylvdisplayShow logical volume detailsman page
lvslvsDisplay summary of logical volumesman page
pvscanpvscanScan and detect physical volumesexample
vgscanvgscanScan and detect volume groupsman page
lvscanlvscanScan and detect logical volumesman page
vgchangevgchange -ayActivate/deactivate volume groupsexample
e2fscke2fsck DEVICECheck and repair ext filesystemsexample
tune2fstune2fs DEVICEModify filesystem parametersexample
dumpe2fsdumpe2fs DEVICEShow filesystem metadata and superblockman page
mkfsmkfs.ext4, mkfs.xfsCreate filesystem on deviceexample
lvextendlvextend OPTIONSExtend logical volume sizeexample
vgextendvgextend VG PVAdd physical volume to volume groupexample
resize2fsresize2fs DEVICEResize ext filesystemexample
lsscsilsscsiList SCSI devicesman page
lsblklsblkShow block devices and hierarchyman page
blkidblkidDisplay UUID of block devicesman page

Managing RPM and Software Repositories

With package manager such as yum, dnf, apt-get, the life of a system administrator becomes very easy. You can easily install, update, remove packages, upgrade server operating system and much more using these commands.

Recommended Read:

CommandExample / SyntaxPurposeMore details
rpmrpm -ivh pkg.rpm, rpm -qaInstall, query, and manage RPM packagesman page
yumyum install pkgLegacy package manager for RPM systems (replaced by dnf)examples
dnfdnf install pkgModern package manager for RPM-based systemsexamples
yumdownloaderyumdownloader pkgDownload RPM packages without installingexamples
zypperzypper install pkgPackage manager for SUSE-based systemsexamples
apt-getapt-get install pkgPackage manager for Debian/Ubuntu systemsman page
apt-cacheapt-cache search pkgSearch packages from local cacheman page
dpkgdpkg -i pkg.debInstall and manage Debian packagesman page
dpkg-scanpackagesdpkg-scanpackages dirCreate repository metadata from .deb filesman page
createrepocreaterepo /repoCreate YUM/DNF repository metadataexamples
repoqueryrepoquery pkgQuery package info from repositoriesexamples
repotrackrepotrack pkgDownload package with dependenciesexamples
reposyncreposyncSync remote repository locallyexamples
subscription-managersubscription-manager statusManage RHEL subscriptions and repositoriesexamples

Manage logging

Now you know about most of the Linux commands to manager different areas of Linux server but you must be familiar of how logging works in Linux? This may vary based on different distribution, with old distros we used syslog-ng for logging but now almost all major distros have moved to rsyslog solution.

Recommended Read:

CommandExample / SyntaxPurposeMore details
loggerlogger "message"Write messages to system logsexamples
logrotatelogrotate -f /etc/logrotate.confRotate and manage log files to prevent growthexamples
journalctljournalctl, journalctl -xeView and filter systemd journal logsexamples

Conclusion

In this cheat sheet tutorial I have tried to consolidate most used Linux commands by different types of experts across IT domains. I am yet to add commands for many other scenarios such as Managing Linux services, archiving, firewall etc but that would just make this tutorial infinite long. I may write another article based on the response I get on this one, even writers need motivation. So that I know people are reading and loving this cheat sheet then I may decide to spend some more time to write about the remaining Linux commands in another tutorial.

Looking forward for your feedback in the comment section.

Deepak Prasad

Deepak Prasad

R&D Engineer

Founder of GoLinuxCloud with over a decade of expertise in Linux, Python, Go, Laravel, DevOps, Kubernetes, Git, Shell scripting, OpenShift, AWS, Networking, and Security. With extensive experience, he excels across development, DevOps, networking, and security, delivering robust and efficient solutions for diverse projects.