100+ Linux Commands Cheat Sheet (With Practical Examples)

Tech reviewed: Deepak Prasad
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:

Command Example / Syntax Comments For more details
printenv printenv Displays environment variables or a specific variable value man page
env env Runs a program with a modified environment man page for env
export export TEST=deepak env | grep TEST Sets environment variables for the shell session man page
set TEST=deepak set | grep TEST Displays all shell and environment variables man 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:

Command Example / Syntax Purpose More details
ls ls, ls -l, ls -la, ls -ltr List files (basic, long, hidden, sorted by time) man page
cat cat FILENAME Print file content to terminal man page
less less FILENAME View large files with navigation and scrolling man page
more more FILENAME View file page by page (limited navigation) man page
head head -n 5 FILE Show first lines of file (default 10) man page
tail tail -n 5 FILE, tail -f /var/log/messages Show last lines or monitor file in real time man page
sort sort FILE Sort file content (supports -n, -u) man page
uniq uniq FILE Remove adjacent duplicate lines man page
file file FILE, file data.txt Identify file type man page
cp cp SRC DEST, cp /root/file /tmp/ Copy files or directories man page
mv mv old new, mv /root/file /tmp/ Move or rename files man page
grep grep STRING FILE, grep ssh /etc/services Search text in files man page
mkdir mkdir DIR Create directory man page
touch touch FILE Create empty file man page
pwd pwd Show current directory man 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:

Command Example / Syntax Purpose More details
which which cmd, which useradd Show full path of executable from $PATH man page
whereis whereis cmd, whereis sshd Locate binary, source, and man pages man page
locate locate file, locate sshd Fast search using indexed database man page
find find / -name file, find / -type f -name sshd Search files in real-time with filters examples

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.

Command Example / Syntax Purpose More details
who who -u Show logged-in users with session details man page
users users List usernames currently logged in man page
last last -a Show login/logout history from /var/log/wtmp man page
finger finger Display user information (if installed) man page
whoami whoami Show current logged-in user man page
id id Display UID, GID, and groups man page
w w Show 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:

Command Example/Syntax Comments For more details
uptime uptime The uptime utility displays the current time, system uptime, number of logged-in users, and load averages (1, 5, and 15 minutes). man page
free free -m The free utility shows total, used, and free physical (RAM) and swap memory, including kernel buffers. Linux Memory Management
dmidecode dmidecode -t system dmidecode displays hardware information such as system serial numbers, BIOS details, and firmware information including BIOS revision. man page
lshw lshw lshw extracts detailed hardware configuration including memory, firmware, CPU, cache, and bus speed. man page
hwinfo hwinfo hwinfo probes system hardware and generates detailed reports (commonly available on SUSE systems). man page
lscpu lscpu lscpu gathers CPU architecture information from sysfs, /proc/cpuinfo, and architecture-specific libraries. man page
lspci lspci lspci displays information about PCI buses and connected devices. man page
/proc/cpuinfo cat /proc/cpuinfo Provides detailed CPU information such as model, architecture, and processor details. This file is also used by lscpu. man page
uname uname [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:

Command Example / Syntax Purpose More details
ps ps, ps aux Display running processes man page
nice nice -n 10 command Start process with adjusted priority example
renice renice -n 15 PID Change priority of running process example
top top Real-time system and process monitoring examples
pgrep pgrep process Find process IDs by name man page
pkill pkill process Kill processes by name man page
kill kill PID, kill -9 PID Send signal to process (terminate/force kill) man page
sar sar -u 1 5 Monitor system performance over time examples
vmstat vmstat 1 Show memory, CPU, and process stats man page
iostat iostat -x Monitor disk I/O performance man page
crond crontab -e Schedule jobs using cron daemon examples

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:

Command Example / Syntax Purpose More details
useradd useradd USER Create a new user account with default settings examples
usermod usermod OPTIONS USER, usermod -G admin deepak Modify user account (e.g. add to group) man page
userdel userdel USER Delete a user account man page
passwd passwd USER Set or update user password, lock/unlock account examples
groupadd groupadd GROUP Create a new group examples
groupdel groupdel GROUP Delete a group examples
groupmod groupmod OPTIONS GROUP, groupmod -n administrator admin Modify group (e.g. rename group) examples
sudo $ sudo COMMAND, $ sudo systemctl network restart Run commands with elevated privileges guide

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:

Command Example / Syntax Purpose More details
chown chown USER:GROUP FILE, chown deepak:admin /tmp/file Change file owner and group man page
chmod chmod PERM PATH, chmod 755 /tmp/dir1 Change file permissions (symbolic or octal) man page
chgrp chgrp GROUP FILE, chgrp admin /tmp/file Change group ownership man page
groups groups USER, groups deepak Show groups of a user man page
newgrp $ newgrp GROUP, $ id Change current primary group man page
setfacl setfacl -m u:user:perm FILE, setfacl -m u:deepak:rx /tmp/file Set ACL permissions for users/groups examples
getfacl getfacl FILE, getfacl /tmp/file View ACL permissions examples
chattr chattr +i FILE, chattr +i /tmp/file Change file attributes (e.g. immutable) examples
lsattr lsattr FILE, lsattr /tmp/file View file attributes set by chattr examples

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:

Command Example / Syntax Purpose More details
ifconfig ifconfig Legacy tool to display network interfaces (use ip addr instead) man page
ip ip addr, ip link show Modern tool to manage IP, interfaces, and network settings examples
route route Legacy routing tool (use ip route) ip route
ip route ip route, ip route show View and manage routing table examples
ethtool ethtool DEVICE, ethtool -i eth0 Display and modify NIC settings man page
ping ping HOST, ping 192.168.0.100 Test network connectivity man page
traceroute traceroute HOST, traceroute 192.168.0.100 Trace route to destination host man page
nmap nmap HOST Scan open ports and services man page
netstat netstat, netstat -tunlp Show network connections and ports (legacy, use ss) man page
nmcli nmcli Command-line tool for NetworkManager examples
nmtui nmtui Text-based UI for NetworkManager examples
ss ss, ss -tunlp Display 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:

Command Example / Syntax Purpose More details
df df Show disk space usage of mounted filesystems man page
fdisk fdisk DEVICE Manage disk partitions (MBR/GPT) example
cfdisk cfdisk DEVICE Interactive partition table editor man page
parted parted Advanced partition management tool (GPT/MS-DOS) example
pvcreate pvcreate DEVICE, pvcreate /dev/sda Create LVM physical volume example
pvdisplay pvdisplay DEVICE Show physical volume details man page
pvs pvs Display summary of physical volumes man page
vgcreate vgcreate VG PV, vgcreate test_vg /dev/sda Create volume group example
vgdisplay vgdisplay Show volume group details man page
vgs vgs Display summary of volume groups man page
lvcreate lvcreate OPTIONS, lvcreate -L 1G -n lv vg Create logical volume example
lvdisplay lvdisplay Show logical volume details man page
lvs lvs Display summary of logical volumes man page
pvscan pvscan Scan and detect physical volumes example
vgscan vgscan Scan and detect volume groups man page
lvscan lvscan Scan and detect logical volumes man page
vgchange vgchange -ay Activate/deactivate volume groups example
e2fsck e2fsck DEVICE Check and repair ext filesystems example
tune2fs tune2fs DEVICE Modify filesystem parameters example
dumpe2fs dumpe2fs DEVICE Show filesystem metadata and superblock man page
mkfs mkfs.ext4, mkfs.xfs Create filesystem on device example
lvextend lvextend OPTIONS Extend logical volume size example
vgextend vgextend VG PV Add physical volume to volume group example
resize2fs resize2fs DEVICE Resize ext filesystem example
lsscsi lsscsi List SCSI devices man page
lsblk lsblk Show block devices and hierarchy man page
blkid blkid Display UUID of block devices man 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:

Command Example / Syntax Purpose More details
rpm rpm -ivh pkg.rpm, rpm -qa Install, query, and manage RPM packages man page
yum yum install pkg Legacy package manager for RPM systems (replaced by dnf) examples
dnf dnf install pkg Modern package manager for RPM-based systems examples
yumdownloader yumdownloader pkg Download RPM packages without installing examples
zypper zypper install pkg Package manager for SUSE-based systems examples
apt-get apt-get install pkg Package manager for Debian/Ubuntu systems man page
apt-cache apt-cache search pkg Search packages from local cache man page
dpkg dpkg -i pkg.deb Install and manage Debian packages man page
dpkg-scanpackages dpkg-scanpackages dir Create repository metadata from .deb files man page
createrepo createrepo /repo Create YUM/DNF repository metadata examples
repoquery repoquery pkg Query package info from repositories examples
repotrack repotrack pkg Download package with dependencies examples
reposync reposync Sync remote repository locally examples
subscription-manager subscription-manager status Manage RHEL subscriptions and repositories examples

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:

Command Example / Syntax Purpose More details
logger logger "message" Write messages to system logs examples
logrotate logrotate -f /etc/logrotate.conf Rotate and manage log files to prevent growth examples
journalctl journalctl, journalctl -xe View and filter systemd journal logs examples

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

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, …

  • Red Hat Certified System Administrator in Red Hat OpenStack
  • Certified Kubernetes Application Developer (CKAD)
  • Red Hat Certified Specialist in Ansible Automation
  • Go (programming language)
  • Python (programming language)
  • DevOps
  • Computer Security