Linux Commands Cheat Sheet
Linux Commands Cheat Sheet
com/linux-command-cheat-sheet/
Linux Commands
Hello everyone, here is a list of all the linux commands I can think of and can be helpful for
your usage.
Input/output
echo
It is used to print string values in the terminal.
Examples:
printf
It is used to print formatted string values in the terminal.
Examples:
read
It is used to take input from the user.
Examples:
1 of 24 3/14/2023, 10:42 PM
Firefox https://linuxhint.com/linux-command-cheat-sheet/
pipe
It is used to take the output of one process and pass it as the input for another process.
The symbol, ‘|’ is for the pipe.
Example:
# The output of`echo` command will be sent as the input of the`wc` command
echo "Hello World" | wc –w
Redirection
The redirection is used in Linux to change the standard input/output of the device after
executing the command. The ‘<’ symbol is used for input redirection and the ‘>’ symbol is
used for output redirection.
Examples:
System Information
date
It is used to print the current date and time of the system in different formats.
Examples:
hostname
It is used to check or modify the hostname, domain, and IP address.
Examples:
2 of 24 3/14/2023, 10:42 PM
Firefox https://linuxhint.com/linux-command-cheat-sheet/
uname
It is used to print different information about the hardware and the operating system.
Examples:
vmstate
It is used to get information about the memory, disk, processes, block IO, paging, and
CPU scheduling.
Examples:
iostate
It is used to monitor the statistics of the system input/output of devices and partitions. The
sysstat package requires to install before using this command.
Examples:
free
It is used to print the detailed report of the system’s memory usage.
Examples:
3 of 24 3/14/2023, 10:42 PM
Firefox https://linuxhint.com/linux-command-cheat-sheet/
whoami
It is used to print the name of the currently logged-in user.
Example:
uptime
It is used to print the information about the total running time of the system.
Examples:
shutdown
It is used to power off or shutdown or restart the system from the terminal.
Examples:
reboot
It is used to reboot the system from the terminal with root privilege.
Example:
User Management
adduser
It is used to add a new user account in the Linux system. The root privilege requires to
4 of 24 3/14/2023, 10:42 PM
Firefox https://linuxhint.com/linux-command-cheat-sheet/
Examples:
deluser
It is used to remove the Linux user account. The root privilege requires to execute this
command.
Examples:
usermod
It is used to modify the information of any existing Linux user. It requires root privilege to
execute.
Examples:
groupadd
It is used to create a new group. It requires root privilege to execute this command.
Examples:
groupdel
It is used to delete an existing group. It requires root privilege to execute this command.
5 of 24 3/14/2023, 10:42 PM
Firefox https://linuxhint.com/linux-command-cheat-sheet/
Examples:
groupmod
It is used to modify any existing group. It requires root privilege to execute this
command.Examples:
last
It is used to print the information about the last login session of the Linux users.
Examples:
id
IT is used to search the username, group name, and the ID of the current user or another
user of the server.
Examples:
id #Print the ID and group information related to the current login user’s
id username #Print the ID and group information related to the particular user
id -u username #Print the user ID of the particular user
id -g username #Print the group ID of the particular user
groups
It is used to print the primary and supplementary group names for each username or the
current process if no username is given.
Examples:
6 of 24 3/14/2023, 10:42 PM
Firefox https://linuxhint.com/linux-command-cheat-sheet/
passwd
It is used to change the user’s password. The root user can change the password of all
users and other users can change their password only.
Examples:
sudo
It is used to perform the restricted tasks with the root privileges without logging as root
user or by logging as the root user.
Examples:
su
It is used to switch from the current user to another user.
Example:
Packages
apt
It is used to install, update, delete and manage different packages in Linux operating
system. It requires root privileges.
Examples:
7 of 24 3/14/2023, 10:42 PM
Firefox https://linuxhint.com/linux-command-cheat-sheet/
apt-get
It works like the `apt` command but some commands are used differently by `apt-get`
command when it is used in replacement of the `apt` command.
Examples:
dpkg
It is used to install, remove, manage and query Debian packages and their dependencies.
It requires root privilege to use.
Examples:
Disk Usage
du
It is used to get disk usage information.
Examples:
8 of 24 3/14/2023, 10:42 PM
Firefox https://linuxhint.com/linux-command-cheat-sheet/
df
It is used to print the used available disk space information of the file system.
Examples:
df #Print the used and available disk space in the default format
df -h #Print the used and available disk space in human-readable format
df -T #Print the used and available disk space with file system type
df --total #Print the used and available disk space with total values
df -a #Print the used and available disk space with other information
fdisk
It is used to create or modify the partition tables of the hard disk.
Examples:
mount
It is used to attach the file system and removable devices at a particular mount point.
Examples:
unmount
It is used to detach the mounted file system and the device.
Examples:
Process Management
ps
It is used to get information related to the processes of the system.
9 of 24 3/14/2023, 10:42 PM
Firefox https://linuxhint.com/linux-command-cheat-sheet/
Examples:
pgrep
It is used to search the process ID of the running program based on the specific condition.
Examples:
kill
It is used to send a signal to a process defined by a PID. The default signal is SIGTERM
which terminates the process.
Examples:
killall
It is used to kill any running process forcefully based on the given process name.
Examples:
10 of 24 3/14/2023, 10:42 PM
Firefox https://linuxhint.com/linux-command-cheat-sheet/
pkill
It is used to send a signal to a process of the running program based on the full or partial
process name, username, or other attributes.
Examples:
fg
It is used to move the background job of the current shell into the foreground.
Example:
bg
It is used to restart a stopped background process.
Example:
Scripting Tools
sed
It is used to search, find-replace, and insert or delete purposes.
Examples:
awk
It is a scripting language that is used for manipulating data and generating a report by
11 of 24 3/14/2023, 10:42 PM
Firefox https://linuxhint.com/linux-command-cheat-sheet/
Example:
sort
It is used to sort the content of a file.
Examples:
wc
It is used to count the number of characters, words, and lines of a file or the standard
input.
Examples:
uniq
It is used to filter the duplicate lines of a file.
Examples:
uniq filename.txt #Print the file after filtering the duplicate lines
uniq –c filename.txt #Print the file after filtering the duplicate lines with number
uniq –d filename.txt #Print the duplicate lines of the file only.
uniq –u filename.txt #Print the unique lines of the file only
tr
It is used to convert the string or delete characters from the string.
Examples:
12 of 24 3/14/2023, 10:42 PM
Firefox https://linuxhint.com/linux-command-cheat-sheet/
echo Linux | tr [:lower:] [:upper:] #Change all small letters to capital letters of
the string
tr A-Z a-z < filename.txt #Change all capital letters to small letters of a file
echo "fool" | tr -c 'ool\n' 'b' #Change those characters by ‘b’ that don’t match with
‘ool\n’
File commands
touch
It is used to create an empty file and change the access or modification timestamp value
of the existing file.
Examples:
cat
It is used to create, read, and concatenate files.
Examples:
cp
It is used to copy file or group of files or directories.
Examples:
mv
It is used to move files and directories from one location to another location.
Examples:
13 of 24 3/14/2023, 10:42 PM
Firefox https://linuxhint.com/linux-command-cheat-sheet/
rm
It is used to remove files and directories.
Examples:
ln
It is used to create the symbolic link.
Examples:
less
It is used to read the large file or command output that displays the content of a file or a
command output part by part to make the reading task faster.
Examples:
more
It works similar to `less` command and it has many other features to scroll the content of
the large file or command output.
Examples:
14 of 24 3/14/2023, 10:42 PM
Firefox https://linuxhint.com/linux-command-cheat-sheet/
cut
It is used to cut the portion of each line from a file and print the output in the terminal.
Examples:
cut -b 3 file.txt #Print the 3rd character from each line of the file
cut -c 2,5 file.txt #Print the 2nd and 5th characters from each line of the file
cut -c -3 file.txt #Print the first 3 characters from each line of the file
head
It is used to read the file from the beginning.
Examples:
tail
It is used to read the file from the end.
Examples:
File Permissions
chmod
It is used to set the permission bits for the files and folders.
Examples:
#Owner can read & write, the group users can read and others can execute
chmod 642 filename
#Owner can read, write and execute, the group users can execute and others can read
only
chmod u=rwx,g=x,o=r filename
#Owner can read and write, the group users can write and others can do nothing to the
files and folders #of the directory
chmod -R 620 dirname
15 of 24 3/14/2023, 10:42 PM
Firefox https://linuxhint.com/linux-command-cheat-sheet/
chown
It is used to change the ownership of a file for the owner or the group users. It requires
root privileges to execute.
Examples:
gzip
It is used to compress the file by keeping the original file mode, timestamp and ownership.
Examples:
tar
It is used to create compressed achieve files of large files and folders that can be
transferred from one location to another.Examples:
zip
It is used to compress the file in .zip format that is supported by many operating systems.
Examples:
unzip
It is used to unzip the files and folders from the zip achieve.
16 of 24 3/14/2023, 10:42 PM
Firefox https://linuxhint.com/linux-command-cheat-sheet/
Examples:
unzip file.zip #Decompress file in the current location from the zip archive
sudo unzip file.zip -d /temp #Decompress file in the particular folder from the zip
archive
Directory operations
pwd
It is used to know the path of the current working directory.
Examples:
mkdir
It is used to create a new directory.
Examples:
rmdir
It is used to remove any directory.
Examples:
ls
It is used to print the list of files and folders of the current path or a particular path.
Examples:
17 of 24 3/14/2023, 10:42 PM
Firefox https://linuxhint.com/linux-command-cheat-sheet/
cd
It is used to change the directory.
Examples:
Searching Commands
grep
It is used to search the particular string in a file.
Examples:
grep 'test' file.txt #Print the lines that match the word, 'test'
grep -i ‘test’ file.txt #Print the lines that match the word, 'test' case-
insensitively
grep ‘^test’ file.txt #Print the lines that match the word, 'test' at the beginning
of the line
grep ‘test$’ file.txt #Print the lines that match the word, 'test' at the end of the
line
locate
It is used to search a file by name.
Examples:
18 of 24 3/14/2023, 10:42 PM
Firefox https://linuxhint.com/linux-command-cheat-sheet/
find
It is used to search and locate the files and folders based on the condition.
Examples:
whereis
It is used to search the location of the source, binary, and the manual page files for a
command.
Examples:
whereis -l #Find the directories where the `whereis` command will search
whereis bash #Find the location of the `bash`
whereis man uptime #Find the location of `man` and `uptime`
Network Information
ping
It is used to test a host is reachable or not in the network.
Examples:
ifconfig
It is used to configure, manage, and query network interface parameters by using a
command-line interface or system configuration script. You have to install the net-tools
package to use this command.
Examples:
19 of 24 3/14/2023, 10:42 PM
Firefox https://linuxhint.com/linux-command-cheat-sheet/
dig
It is used to search the DNS name servers for DNS lookup.
Examples:
netstat
It is used to get information about the network activities and display which ports are open
or have established connections. It is a useful tool to debug network problems.
Examples:
ip
It is used to bring the interface up or down, assign and remove the address, etc.
Examples:
alt+ctrl+t
It is used to open a new terminal window.
ctrl+c
It is used to stop the running command.
20 of 24 3/14/2023, 10:42 PM
Firefox https://linuxhint.com/linux-command-cheat-sheet/
ctrl+a
It is used to go to the start of the line.
ctrl+e
It is used to go to the end of the line.
ctrl+u
It is used to cut the line before the cursor to the clipboard.
ctrl+k
It is used to cut the line after the cursor to the clipboard.
ctrl+r
It is used to search history.
ctrl+z
It is used to suspend the current foreground process.
!!
It is used to repeat the last command.
!$
It is used to read the last argument of the previous command.
!*
It is used to read all arguments of the previous command.
Variables
The variable is used to store and read data.
Example:
Length
The length of a string can be calculated in bash in different ways. The simple way to count
the length is shown below.
21 of 24 3/14/2023, 10:42 PM
Firefox https://linuxhint.com/linux-command-cheat-sheet/
Example:
Substring
Sometimes it requires cutting the portion of a string that is called substring.
Example:
Uppercase
The string can be converted into uppercase by using `tr` command and ‘^^’ operator.
Example:
var="Hello"
echo $var | tr [:lower:] [:upper:] #Convert to uppercase using `tr`
echo ${var^^} #Convert to uppercase using '^^'
Lowercase
The string can be converted into lowercase by using `tr` command and ‘,,’ operator.
Example:
var="Hello"
echo $var | tr [A-Z] [a-z] #Convert to lowercase using `tr`
echo ${var,,} #Convert to lowercase using '^^'
If Statement
If statement is used to define the conditional statements.
Example:
str="file.txt"
if [[ -f $str ]]; then #Check the file exists or not
echo "$str is a file."
elif [[ -d $str ]]; then #Check the directory exist or not
echo "$str is a directory."
else
echo "$str is not a fir or directory."
fi
22 of 24 3/14/2023, 10:42 PM
Firefox https://linuxhint.com/linux-command-cheat-sheet/
Case statement
The case statement can be used as an alternative to if statement.
Example:
id=45
case $id in
67) echo "Group-1";; #Match with an ID
45 | 89) echo "Group-2";; #Match with any of two IDs
92 | 12 | 54) echo "Group-3" ;; #Match with any of three IDs
*) echo "You are not selected." ;;
esac
For loop
It is used to iterate some statements multiple times or read the array values.
Example:
While loop
It is used as the alternative of for loop.
Example:
Function
It is used to define a block of code with a name that can be executed anytime by calling
the function name.
Example:
23 of 24 3/14/2023, 10:42 PM
Firefox https://linuxhint.com/linux-command-cheat-sheet/
eval
It is used to execute arguments like a shell command.
Example:
set
It is used to control certain flags and features in Bash to set the behavior of the scripts.
Examples:
unset
Ii is used to delete the variables during the program execution. It can be used to delete
both functions and shell variables.
Example:
24 of 24 3/14/2023, 10:42 PM