100+ Linux commands cheat sheet & examples - 2024 | GoLinuxCloud (2024)

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.

Topics we will cover hide

Environment Variables

File Management

Finding files and directories

Check User Information

Check System Information

Manage System Processes

Managing Permissions

Configure and Troubleshoot Network

Managing Partitions and Logical Volumes

Managing RPM and Software Repositories

Manage logging

Conclusion

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

# TEST=deepak

Verify the content of this variable

# echo $TESTdeepak

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

# echo $TEST

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

Recommended Read:
How to find the path of any command in Linux
How to set environment (PATH) variable permanently in Linux
Find the path of the commands in linux

CommandExample/SyntaxCommentsFor more details
printenv# printenv

# printenv PATH

Displays environment variable names and values.
When called with the name of an environment variable, it displays the value of that variable.
man page for printenv
env# envThe env utility runs a program as a child of the current shell, allowing you to modify the environment the current shell exports to the newly created process.man page for env
export# export TEST=deepak
# env | grep TEST

TEST=deepak
When you run an export command with variable names as arguments, the shell places the names (and values, if present) of those variables in the environment.man page for export
set# TEST=deepak
# set | grep TEST

TEST=deepak
Display variables in the current shell
These variables comprise shell variables (variables not in the environment) and environment variables.
man page for set

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:

5 commands to copy file from one server to another in Linux or Unix

Securely transfer files between two hosts using HTTPS in Linux
10+ practical examples to create symbolic link in Linux

CommandExample/SyntaxCommentsFor more details
ls# lsList filesman page for ls
# ls -lLong list files
# ls -laLong list files including hidden files
# ls -ltrLong list files and sort by modification time. oldest placed first.
cat# cat FILENAMEPrint the content of the provided file on the terminalman page for cat
less# less FILENAMEWhen you want to view a file that is longer than one screen, you can use either thelessutility or the more utility.
It will pause after displaying a screen of text
You can use keyboard arrow to navigate around the file to read the text
Pressqto return to the shell
man page for less
more# more FILENAMEmorecommand is also similar to less but has few restrictions
We cannot use navigation arrow from the keyboard while reading with more
You must use SPACE bar to scroll through the file
Pressqto return to console
man page for more
head# head -n 5 FILENAMEThis example displays the top 5 lines of provided file
By default theheadutility displays the first ten lines of a file.
man page for head
tail# tail -n 5 FILENAMEThis example will display the last 5 lines of the provided file
By defaulttailwill show the last 10 lines of the file
man page for tail
# tail -f /var/log/messagesTo continuously monitor the incoming log messages into/var/log/messagesfile in runtime
sort# sort FILENAMEDisplays a File in Order
The sort utility displays the contents of a file in order by lines
It does not change the original file.
The–uoption generates a sorted list in which each line is unique (no duplicates).
The–noption puts a list of numbers in numerical order.
man page for sort
uniq# uniq FILENAMETheuniq(unique) utility displays a file, skipping adjacent duplicate lines; it does not change the original file.
If a file contains a list of names and has two successive entries for the same person,uniqskips the extra line
man page for uniq
file# file FILENAMEIdentifies the Contents of a File
You can use thefileutility to learn about the contents of any file on a Linux system without having to open and examine the file yourself.
man page for file
# file dataFile.txt
dataFile.txt: ASCII text
filecommand identified thedataFile.txttype as ASCII text
cp# cp SOURCE-FILE DESTINATION-FILEThecp(copy) utility makes a copy of a file.
TheSOURCE-FILEis the name of the file thatcpwill copy.
TheDESTINATION-FILEis the namecpassigns to the resulting (new) copy of the file.
If theDESTINATION-FILEexists before you give acpcommand,cpoverwrites it.
man page for cp
# cp /root/myfile /tmp/dir1/This command copiedmyfilefrom/rootto/tmp/dir1directory
mv# mv EXISTING-FILENAME NEW-FILENAMEChanges the Name of a File
Themv(move) utility can rename a file without making a copy of it. Themvcommand line specifies an existing file and a new filename using the same syntax ascp
man page for mv
# mv /root/debug.log /tmp/new_debug.logIn this example we rename the name ofdebug.logfile tonew_debug.logand also changed the location of the file from/root/to/tmp
grep# grep STRING FILENAMEThegreputility searches through one or more files to see whether any contain a specified string of characters.
This utility does not change the file it searches but simply displays each line that contains the string.
man page for grep
# grep ssh /etc/servicesIn this example we search for all the lines containing "ssh" in/etc/servicesfile
mkdir# mkdir DIRCreate directoriesman page for mkdir
touch# touch FILECreate empty fileman page for touch
pwd# pwdpresent working directoryman page for pwd
ALSO READ15+ ping command examples in Linux [Cheat Sheet]

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:
10 find exec multiple commands examples in Linux/Unix
How to find and remove duplicate files using shell script in Linux
10+ practical examples to create symbolic link in Linux

CommandExample/SyntaxCommentsFor more details
which# which PROGRAMNAMEwhichwill print the full path of the providedPROGRAMNAMEonSTDOUT
It does this by searching for an executable or script in the directories listed in the environment variablePATH.
man page for which
# which useradd
/usr/sbin/useradd
In this example we are searching for the path ofuseraddcommand
whereis# whereis FILENAMEwhereisattempts to locate the desired program in the standard Linux places, and in the places specified by$PATHand$MANPATHman page for whereis
# whereis sshd
sshd: /usr/sbin/sshd /usr/share/man/man8/sshd.8.gz
In this example we are searching for the path ofsshdbinary and themanpage location forsshdfile
locate# locate FILENAMEThelocateutility (locatepackage; some distributions usemlocate) searches for files on the local system:
Before you can use locate (mlocate), theupdatedbutility must build or update the locate (mlocate) database. Typically the database is updated once a day by a cron script
man page for locate
# locate sshd
/etc/pam.d/sshd
/etc/ssh/sshd_config
/etc/sysconfig/sshd
In this example we are searching for all files in your Linux server containing stringsshdin their name
find# find PATH OPTIONS FILENAMEfindcommand will search for file or directory based on the OPTIONS providedfind cmnd examples
# find / -type f -name sshdIn this example we are searching for a file namedsshdinside/location

Check User Information

Recommended Read:
How to check last login time for users in Linux
How to keep a track of all the commands run by any user in Linux
How to check the lock status of any user account in Linux
How to auto logout(timeout) a normal user and root user in Linux?

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/SyntaxCommentsFor more details
who# who -uThewhoutility displays a list of users who are logged in on the local system.man page for who
users# usersPrint the user names of users currently logged in to the current host
It does not give much information apart from usernames
man page for users
last# last -aThis command searches back through the file/var/log/wtmp(or the file designated by the -f flag) and displays a list of all users logged in (and out) since that file was created.man page for last
finger# fingerIf no arguments are specified,fingerwill print an entry for each user currently logged into the system.man page for finger
whoami# whoamiPrint the user name associated with the current effective user IDman page of whoami
id# idPrint real and effective user and group IDsman page for id
w# wThe first line thewutility displays is the same as the output ofuptimecommand. Following that line, w displays a list of the users who are logged in.

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:
5 commands to check if server is physical or virtual in Linux or Unix
How to check if Hyper Threading (HT) is enabled or disabled on my Linux server
How to get the hardware model information in Linux

CommandExample/SyntaxCommentsFor more details
uptime# uptimeTheuptimeutility displays a single line that includes the time of day, the period of time the computer has been running (in days, hours, and minutes), the number of users logged in, and the load average (how busy the system is). The three load average numbers represent the number of jobs waiting to run, averaged over the past 1, 5, and 15 minutes.man page for uptime
free# free -mThefreeutility displays the amount of physical (RAM) and swap memory in the local system. It displays columns for total, used, and free memory as well as for kernel buffers.Linux Memory Management
dmidecode# dmidecode -t systemdmidecodeis a tool for dumping a computer's DMI (some say SMBIOS) table contents in a human-readable format. This table contains a description of the system's hardware components, as well as other useful pieces of information such as serial numbers and BIOS revisionman page for dmidecode
lshw# lshwlshwis a small tool to extract detailed information on the hardware configuration of the machine. It can report exact memory configuration, firmware version, mainboard configuration, CPU version and speed, cache configuration, bus speed, etcman page for lshw
hwinfo# hwinfohwinfois used to probe for the hardware present in the system. It can be used to generate a system overview log which can be later used for support. (available only with SuSE)man page for hwinfo
lscpu# lscpulscpugathers CPU architecture information from sysfs,/proc/cpuinfoand any applicable architecture-specific libraries (e.g. librtas on Powerpc).man page for lscpu
lspci# lspcilspciis a utility for displaying information about PCI buses in the system and devices connected to them.man page for lspci
/proc/cpuinfo# cat /proc/cpuinfoProvides information about the CPU model, architecture, processors, available modules, and many more CPU related information.lscpugathers information from this file,man page for lscpu
uname# uname [OPTIONS]Print system informationman page for uname
ALSO READ10 tee command examples in Linux [Cheat Sheet]

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:
Tutorial for Monitoring Tools SAR and KSAR with examples in Linux
How to check memory usage of an individual process or application/program in Linux
Tutorial: Beginners guide on linux memory management

CommandExample/SyntaxCommentsFor more details
ps# ps [OPTIONS]psdisplays information about a selection of the active processes. If you want a repetitive update of the selection and the displayed information, usetopinstead.man page for ps
nice# nice [OPTIONS]Run COMMAND with an adjusted niceness, which affects process scheduling. With no COMMAND, print the current niceness. Niceness values range from -20 (most favorable to the process) to 19 (least favorable to the process).nice example
renice# renice [OPTIONS] PIDrenicealters the scheduling priority of one or more running processes. The first argument is the priority value to be used. The other arguments are interpreted as process IDs (by default), process group IDs, user IDs, or user names.renice example
# renice -n 15 1121
1121 (process ID) old priority 0, new priority 15
In this example I have changed the nice value of PID 1121 from 0 to 15
top# topThetopprogram provides a dynamic real-time view of a running system. It can display system summary information as well as a list of processes or threads currently being managed by the Linux kernel.top examples
pgrep# pgrep [OPTIONS] PATTERNpgreplooks through the currently running processes and lists the process IDs which match the selection criteria to stdout.man page for pgrep
pkill# pkill [OPTIONS] PATTERNpkillwill send the specified signal (by default SIGTERM) to each process instead of listing them on stdout.man page for pkill
kill# kill [OPTIONS] PIDThe commandkillsends the specified signal to the specified processes or process groups.man page for kill
sar# sar [OPTIONS]Thesarcommand writes to standard output the contents of selected cumulative activity counters in the operating system. The accounting system, based on the values in the count and interval parameters, writes information the specified number of times spaced at the specified intervals in seconds. If the interval parameter is set to zero, thesarcommand displays the average statistics for the time since the system was started.sar examples
vmstat# vmstat [OPTIONS]vmstatreports information about processes, memory, paging, block IO, traps, disks and cpu activity.man page for vmstat
iostat# iostat [OPTIONS]Theiostatcommand is used for monitoring system input/output device loading by observing the time the devices are active in relation to their average transfer rates.man page for iostat
crond# crond [OPTIONS]cronddaemon is used to execute scheduled commands. You can create new job usingcrontab -eand provide the time when the script should be executed and the script pathcrond 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:

4 easy methods to check sudo access for user in Linux
10 practical examples to add or remove user from group in Linux
How to prevent user from using old password (or re-using) again in Linux

CommandExample/SyntaxCommentsFor more details
useradd# useradd USERNAMETheuseraddcommand creates a new user account using the values specified on the command line plus the default values from the system. Depending on command line options, theuseraddcommand will update system files and may also create the new user's home directory and copy initial files.useradd examples
usermod# usermod OPTIONS USERNAMETheusermodcommand modifies the system account files to reflect the changes that are specified on the command line.man page of usermod
# usermod -G admin deepakIn this example I am adding additional group to my existingdeepakuser
userdel# userdel USERNAMETheuserdelcommand modifies the system account files, deleting all entries that refer to the user nameUSERNAME. The named user must existman page for userdel
passwd# passwd USERNAMEThepasswdutility is used to update user's authentication token(s).
You can lock, unlock, assign passwords usingpasswdutility for any system user
passwd examples
groupadd# groupadd GROUPNAMEThegroupaddcommand creates a new group account using the values specified on the command line plus the default values from the system. The new group will be entered into the system files as neededadd or remove user from group
groupdel# groupdel GROUPNAMEThegroupdelcommand modifies the system account files, deleting all entries that refer toGROUPNAME. The named group must exist.add or remove user from group
groupmod# groupmod [options] GROUPNAMEThegroupmodcommand modifies the definition of the specifiedGROUPby modifying the appropriate entry in the group database.add or remove user from group
# groupmod -n administrator adminIn this example I am renaming the group name from admin to administrator
sudo$ sudo OPTIONS COMMANDsudoallows a permitted user to execute a command as the superuser or another user, as specified by the security policy.Add sudo permisison
$ sudo systemctl network restartObserve the$sign in the beginning of the shell, it donates a normal user shell. A root user's shell will have hash (#)
So in this example a normal user is performing network restart using sudo privilege
ALSO READ10 finger command examples in Linux [Cheat Sheet]

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:
Understanding special permission Sticky Bit in Linux with examples
Understanding special permission SUID in Linux with examples
Understanding special permission SGID in Linux with examples
chmod recursive usage guide for absolute beginners

CommandExample/SyntaxCommentsFor more details
chown# chown OPTIONS USER:GROUP TARGETchownchanges the user and/or group ownership of each given file or directory
USERrepresents the user owner of the target file
GROUPrepresents the group owner of the target file
TARGETrepresents any file or directory or PATH
man page for chown
# chown deepak:admin /tmp/fileIn this example I am assigning user owner permission todeepak, group owner permission to admin group for/tmp/file
chmod# chmod PERM PATHchmodchanges the file mode bits i.e.PERMof each given file according to mode, which can be either a symbolic representation of changes to make, or an octal number representing the bit pattern for the new mode bitsman page for chmod
# chmod 755 /tmp/dir1In this example I am changing permission of/tmp/dir1to 755 i.e. full permission for user, read+execute permission for group and other users
chgrp# chgrp GROUPNAME FILEChange group ownership of files and directories
GROUPNAMErepresents the group to be assigned forFILE
man page for chgrp
# chgrp admin /tmp/fileIn this example we are changing the group ownership to admin group for/tmp/file
groups# groups USERNAMEPrint group memberships for eachUSERNAMEman page for groups
# groups deepak
deepak : deepak admin
In this example we are checking the list of group which userdeepakis part of.
newgrp$ newgrp GROUPNAMEThenewgrpcommand is used to change the current group ID during a login sessionman page for newgrp
$ id
uid=1001(deepak) gid=1001(deepak) groups=1001(deepak),1003(admin)

$ newgrp admin

$ id
uid=1001(deepak) gid=1003(admin) groups=1003(admin),1001(deepak)

In this example we are changing the primary group of userdeepakto admin group
setfacl# setfacl OPTIONS FILEThis utility sets Access Control Lists (ACLs) of files and directories.
It is useful to give individual permission to users and groups aschmodassigns permission of file level but here we have more control over each user permission
setfacl examples
# setfacl -m u:deepak:rx /tmp/fileIn this example I am giving read and execute permission for userdeepakfor/tmp/file
getfacl# getfacl FILEFor each file,getfacldisplays the file name, owner, the group, and the Access Control List (ACL). If a directory has a default ACL,getfaclalso displays the default ACLgetfacl examples
# getfacl /tmp/file
getfacl: Removing leading '/' from absolute path names
# file: tmp/file
# owner: root
# group: admin
user::rw-
user:deepak:r-x
group::r--
mask::r-x
other::r--
In this example I am collecting the acl permission list from/tmp/file
It has the permission detail which we applied earlier withsetfacl
chattr# chattr OPTIONS FILEchattrchanges the file attributes on a Linux file systemchattr examples
# chattr +i /tmp/fileIn this example we have restricted the modification permission on/tmp/file. Now not even root user can modify the content of/tmp/file
To remove this permission use chattr -i /tmp/file
lsattr# lsattr FILElist file attributes on a Linux second extended file system. By default ls command will not show the permission attributes applied bychattrso we must uselsattrto get these detailslsattr examples
# lsattr /tmp/file
----i---------e---- /tmp/file
In this example we can see the "i" attribute which we added withchattrin the previous example
The 'e' attribute indicates that the file is using extents for mapping the blocks on disk. It may not be removed usingchattr

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:
How to monitor network bandwidth in Linux using netperf
How to use iperf3 tool to monitor network bandwidth in Linux
27 nmcli command examples (cheatsheet), compare nm-settings with if-cfg file

CommandExample/SyntaxCommentsFor more details
ifconfig# ifconfigThis program isobsolete! For replacement checkip addrandip link. For statistics useip -s link.
If no arguments are given,ifconfigdisplays the status of the currently active interfaces. If a single interface argument is given, it displays the status of the given interface only;
man page for ifconfig
ip# ip [OPTIONS]Newer command to monitor and set IP address and other network card–related informationip examples
# ip link showThis example lists the available network device on the Linux server along with their Link status
route# route [OPTIONS]This program isobsolete. For replacement checkip route.ip route examples
ip route# ip route [OPTIONS]Manipulate route entries in the kernel routing tables keep information about paths to other networked nodes.ip route examples
# ip route showIn this example we are printing the configured routes on the Linux server from the routing table
ethtool# ethtool [OPTIONS] DEVICEquery or control network driver and hardware settingsman page for ethtool
# ethtool -i eth0In this example we are printing the interface details foreth0. Theinterface namemay vary based on the environment and configuration.
ping# ping OPTIONS DESTINATIONpingis used to check the connectivity of remote computersman page for ping
# ping 192.168.0.100In this example we are testing the connectivity between localhost and192.168.0.100server
traceroute# traceroute HOSTUtility that helps you analyzing reachability of hosts on the network.
In most cases it is possible that due to firewall you may not get the list of hops towards the destination
man page for traceroute
# traceroute 192.168.0.100In this example we are checking the route used to connect192.168.0.100
nmap# nmap OPTIONS HOSTUtility that helps you check which services are offered by an other host
It is used to check the list of open ports on destination server
man page for nmap
netstat# netstat [OPTIONS]Utility that helps you find out which services are offered by the local host
It will give you a list of ports which are used by different system services and any service from the network
man page for netstat
# netstat -tunlpIn this example I am listing the listening TCP and UDP protocols on my Linux server
nmcli# nmcli [OPTIONS]nmcliis a command-line tool for controlling NetworkManager and reporting network status.nmcli examples
nmtui# nmtuinmtuiis a curses‐based TUI application for interacting with NetworkManager
It is a graphical alternative to nmcli
nmtui examples
ss# ss [OPTIONS]ssis used to dump socket statistics. It allows showing information similar tonetstat. It can display more TCP and state information than other tools.
When no option is used ss displays a list of open non-listening sockets (e.g. TCP/UNIX/UDP) that have established connection
man page for ss
ALSO READ10+ cut command examples in Linux [Cheat Sheet]

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:
Step-by-Step Tutorial: Configure software Linear RAID 0 in Linux
Step-by-Step Tutorial: Configure Software RAID 0 in Linux
Step-by-Step Tutorial: Configure Software RAID 1 in Linux
Step-by-Step Tutorial: Configure Software RAID 4 in Linux
Step-by-Step Tutorial: Configure Software RAID 5 in Linux
Step-by-Step Tutorial: Configure Hybrid Software RAID 10 in Linux

CommandExample/SyntaxCommentsFor more details
df# df [OPTIONS]Report file system disk space usage
If no file name is given, the space available on all currently mounted file systems is shown
man page for df
fdisk# fdisk [OPTIONS] DEVICEfdiskis interactive program for creation and manipulation of partition tables. It understands GPT, MBR, Sun, SGI and BSD partition tablesfdisk example
cfdisk# cfdisk [OPTIONS] DEVICEDisplay or manipulate a disk partition tableman page for cfdisk
parted# partedpartedis a program to manipulate disk partitions. It supports multiple partition table formats, including MS-DOS and GPT.parted example
pvcreate# pvcreate [OPTIONS] DEVICECreate LVM Physical Volumepvcreate example
# pvcreate /dev/sdaIn this example we are creating a physical volume using/dev/sdadevice
pvdisplay# pvdisplay DEVICEIt shows the attributes of PVs, like size, physical extent size, space used for the VG descriptor area, etcman page for pvdisplay
pvs# pvsDisplay information about physical volumes
This can be used as an alternative topvdisplayto display limited information of available physical volumes
man page for pvs
vgcreate# vgcreate [OPTIONS]It creates a new Volume Group on block devices (physical volume)vgcreate example
# vgcreate test_vg /dev/sdaIn this example we are create a new volume group "test_vg" by adding/dev/sda
Here/dev/sdais a new physical volume, you cannot use any existing device used by other logical volumes
vgdisplay# vgdisplay DEVICEvgdisplayshows the attributes of VGs, and the associated PVs and LVsman page for vgdisplay
vgs# vgsDisplay information about Volume Groups
This can be used as an alternative tovgdisplayto display limited information of available volume groups
man page for vgs
lvcreate# lvcreate [OPTIONS]This is used to create logical volumeslvcreate example
# lvcreate -L 1G -n test_lv1 test_vgIn this example I am creating a logical volumetest_lv1of size 1GB undertest_vgvolume group
lvdisplay# lvdisplay DEVICEDisplay information about a logical volumeman page for lvdisplay
lvs# lvsDisplay information about logical volumes in shorter output compared tolvdisplaycommand. You can use this as an alternative tolvdisplayman page for lvs
pvscan# pvscan [OPTIONS]Scans storage devices for the presence of LVM physical volumes.
It is used when a new physical volume metadata is not loaded and apvscancan load the metadata of all the available PV
pvscan example
vgscan# vgscan [OPTIONS]Scans storage devices for the presence of LVM volume groups.
It can be used when any VG metadata is not visible andvgscancan scan the available VG
man page for vgscan
lvscan# lvscan [OPTIONS]Scans storage devices for the presence of LVM logical volumes.
It can be used when any LV metadata is not visible andlvscancan scan the available LV
man page for lvscan
vgchange# vgchange [OPTIONS]Changes the status from LVM volume groups and the volumes in it from active to inactive and vice versavgchange example
# vgchange -ayIn this example we are activating all the available volume groups. To deactivate all volume groups usevgchange -an
e2fsck# e2fsck [OPTIONS]check a Linux ext2/ext3/ext4 file system
We cannot perform a check on a mounted file system so normally this is performed during reboot or in single user mode
e2fsck example
tune2fs# tune2fs [OPTIONS] DEVICEtune2fsallows the system administrator to adjust various tunable filesystem parameters on Linux ext2, ext3, or ext4 filesystems.tune2fs example
dumpe2fs# dumpe2fs [OPTIONS] DEVICEprints the super block and blocks group information for the filesystem present on device.man page for dumpe2fs
mkfs.# mkfs.ext4
# mkfs.xfs
mkfsis used to build a Linux filesystem on a device, usually a hard disk partition. The device argument is either the device name (e.g. /dev/hda1, /dev/sdb2), or a regular file that shall contain the filesystem.create filesystem
lvextend# lvextend OPTIONSAdd space to a logical volumelvextend example
vgextend# vgextend VGNAME PVAdd physical volumes to a volume groupvgextend example
resize2fs# resize2fs DEVICETheresize2fsprogram will resize ext2, ext3, or ext4 file systems. It can be used to enlarge or shrink an unmounted file system located on deviceresize2fs example
lsscsi# lsscsi [OPTIONS]list attached SCSI devices (or hosts)man page for lsscsi
lsblk# lsblklsblk lists information about all available or the specified block devices. The lsblk command reads the sysfs filesystem and udev db to gather informationman page for lsblk
blkid# blkidIt prints the UUID valud of all the connected storage device. You can use this UUID to identify the storage device instead of using the physical nameman page for blkid
ALSO READ15 tune2fs command examples in Linux [Cheat Sheet]

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:
Step-by-Step: YUM install specific version of Package
Install old rpm or downgrade rpm to specific version using yum in Linux
Create local offline yum repository in Linux

CommandExample/SyntaxCommentsFor more details
rpm# rpm [OPTIONS] FILERPM Package Manager which can be used to build, install, query, verify, update, and erase individual software packages.man page for rpm
yum# yum [OPTIONS] FILEyumis short abbreviation for Yellow Dog Updater Modified.
It is obsolete now and is replaced by dnf in most recent Linux distributions.
YUM is a package manager for RPM-based Linux distributions
yum examples
yumdownloader# yumdownloader [OPTIONS]Allows you to download packages from a repository to your system without installing themyumdownloader examples
zypper# zypper [OPTIONS] FILEPackage management utility in the SUSE works. Works more or less the same as yum.
The handling of repository is slightly different withzyppercompared toyum
zypper examples
apt-get# apt-get [OPTIONS] FILEUbuntu/Debian package management utility. Does a great job in installing and updating software.man page for apt-get
apt-cache# apt-cache [OPTIONS] FILETool that allows you to search for packages in the locally cached index filesman page for apt-cache
dpkg# dpkg [OPTIONS] ACTIONOriginal Debian package management utility, which has been made more or less obsolete byapt-getman page for dpkg
dpkg-scanpackages# dpkg-scanpackages [OPTIONS]Tool that allows you to convert a directory containing .deb packages into a repository.man page for dpkg-scanpackages
dnf# dnf [OPTIONS]DNF is the next upcoming major version of YUM, a package manager for RPM-based Linux distributions.dnf examples
createrepo# createrepo [OPTIONS] PATHcreaterepois a program that creates arepomd(xml-based rpm metadata) repository from a set of rpms.createrepo examples
repoquery# repoquery [OPTIONS]This is part ofyum-utils, Searches the available DNF repositories for selected packages and displays the requested information about themrepoquery examples
repotrack# repotrack [OPTIONS]This is part ofyum-utils, track packages and its dependencies and download themrepotrack examples
reposync# reposync [OPTIONS]Synchronize packages of a remote DNF or YUM repository to a local directory.reposync examples
subscription-manager# subscription-manager [OPTIONS]Registers systems to a subscription management service and then attaches and manages subscriptions for software productssubscription-manager 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:
Understanding systemd-journald and how logging works with Journal in RHEL 7
Journalctl cheat sheet with 10+ commands to filter systemd logs
How to enable persistent logging in systemd-journald without reboot

CommandExample/SyntaxCommentsFor more details
logger# logger [OPTIONS] MESSAGEloggermakes entries in the system log.
When the optional message argument is present, it is written to the log.
logger examples
logrotate# logrotate [OPTIONS]Command that helps you to prevent log files from growing too big and rotate them after a certain amount of time or once a given size has been reachedlogrotate examples
journalctl# journalctl [OPTIONS]journalctlmay be used to query the contents of the systemd journal as written by systemd-journald.servicejournalctl 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.

Views: 7,794

Can't find what you're searching for? Let us assist you.

Enter your query below, and we'll provide instant results tailored to your needs.

100+ Linux commands cheat sheet & examples - 2024 | GoLinuxCloud (2024)

References

Top Articles
Latest Posts
Article information

Author: Sen. Ignacio Ratke

Last Updated:

Views: 6216

Rating: 4.6 / 5 (56 voted)

Reviews: 87% of readers found this page helpful

Author information

Name: Sen. Ignacio Ratke

Birthday: 1999-05-27

Address: Apt. 171 8116 Bailey Via, Roberthaven, GA 58289

Phone: +2585395768220

Job: Lead Liaison

Hobby: Lockpicking, LARPing, Lego building, Lapidary, Macrame, Book restoration, Bodybuilding

Introduction: My name is Sen. Ignacio Ratke, I am a adventurous, zealous, outstanding, agreeable, precious, excited, gifted person who loves writing and wants to share my knowledge and understanding with you.