Linux Commands CheatSheet - PDF
Linux Commands CheatSheet - PDF
at 09:00 AM SUN
at command used to schedule a task once at 09:00 AM AUG 30
at 09:00 AM 06.22.2024
at 09:00 AM tomorrow
to set variable for the current user - .bashrc To set the environement variable you need to use export command
env
to set variable for globally - /etc/bashrc or /etc/profile
E
ethtool print NIC info ethtool enps03
exit Exits the shell or a script. Close the current terminal (logout)
export TEST=1
export used to set env vairable temporary to check, echo $TEST
E
find /tmp/ -name folder_name
groupadd mygroup
groupadd to add group check in /etc/group file
groupdel to delete group
Example: groups username
groups Shows the groups a user is a member of. Usage: Lists all the groups that username belongs to. Useful for
beginners to check group memberships.
Example: getenforce
getenforce Displays the current SELinux mode. Usage: Shows whether SELinux is enforcing, permissive, or
disabled. Useful for beginners to check SELinux status.
Example: getfacl filename
getfacl Gets file access control lists (if installed). Usage: Displays the ACLs of filename. Useful for beginners to
view detailed file permissions.
G
gzip name.tar
gzip, gunzip compressing and decompressing, usually we apply this on tar file gunzip name.tar.gz or gzip -d name.tar.gz
G
head gives you starting lines head -2 file_name
hostname show your hostname hostname
hostnamectl to control and change the hostname hostnamectl set-hostname <new_hostname>
history Lists all the commands that have been entered in the current shell session. $history
htop An interactive process viewer (if installed).
help Help to show you how to use a command help cd
H halt Stops the system.
ip addr show ip address and network related info
ifconfig show ip address and network related info
Report Central Processing Unit (CPU) statistics and input/output statistics for devices and
iostat
partitions.
Usage: Shuts down the system (runlevel 0). Beginners should use
init initi 0-6, 0-6 are different level at which we need to reboot this with caution as it affects the system's state.
I id show group and user detail of a user id user_name
jobs to see the current jobs and its state jobs
Usage: Displays the most recent log entries with detailed
journalctl Queries and displays logs from systemd's journal. information. Useful for beginners to troubleshoot system issues
J and view log files.
kill PID
kill to kill any process kill -9 PID
Example: killall httpd
killall Kills all processes by the specified name. Usage: Terminates all processes named httpd.
K
last show listing of last logged users last
less it show you file nicely manner page vise less file_name
ls
ls -ltr
ls to list the file ls -la (to see hidden files)
ls -i (to see the inode)
ln
ln to create hard or soft link ln -s source_file name_of_link
lscpu to check the linux machine sepec
lsblk Displays a tree of block devices.
lsmod Lists all currently loaded kernel modules.
L locate its like find command but its search in its own db locate filename (to search this file on system)
mkdir to create a directory mkdir folder_name
more it gives you result one page at a time (in case if the output list is very big) ls -ltr | more
man to read more about a command (man cd) will give manual on cd command
Example: sudo mount /dev/sda1 /mnt
mount Mounts a filesystem. Usage: Mounts the filesystem on /dev/sda1 to the /mnt directory.
Useful for beginners to access filesystems and external drives.
M mv to move or rename a file mv filename newname
nohup sleep 50
nohup to run a process in backgroup even if user close his terminal nohup sleep 50 > /dev/null 2>&1 &
nice to assign a process with priority nice -n 5 process_name (-19 to 20 will be priority)4
nano text editor to create, edit your files nano file_name
Example: nslookup example.com
nslookup Queries Internet name servers interactively and DNS record Usage: Retrieves the DNS records for example.com.
Example: nmcli device status
nmcli Command-line client for NetworkManager. Usage: Shows the status of network devices. Useful for beginners
to manage network connections.
Shows the number of processing units available. Example: nproc
nproc Usage: Displays the number of CPU cores available. Useful for
beginners to understand system resources.
netstat -rnv
shuf to shuffle each line within a file or stdin cat file | shuf
B
C
ssh Secure Shell, used to connect to remote servers. Example: ssh user@hostname
Example: ssh-keygen -t rsa -b 2048
ssh-keygen Generates, manages, and converts authentication keys for SSH. Usage: Generates an RSA key pair with 2048-bit encryption.
Useful for beginners to set up SSH key-based authentication.
Example: scp file.txt user@remote_host:/path/to/destination
scp Secure copy, used to copy files to remote servers Usage: Copies file.txt to remote_host under
/path/to/destination.
shutdown shutdown your server, Halt, power-off or reboot the machine
Example: strings binaryfile
strings Displays printable strings in files. Usage: Extracts and displays printable strings from binaryfile.
Useful for beginners to find readable text in binary files.
systemctl start <service_name> like chronyd
systemctl Control the systemd system and service manager systemctl status chronyd
S
tail -2 file_ame
tail gives you last few lines tail -f file_name (will keep update the logs)
tar cvf name.tar file_path
tar xvf name.tar
tar -tf name.tar (will show or list the content of tar file)
T
Example: traceroute example.com
traceroute Traces the route packets take to a network host. Usage: Displays the route packets take to reach example.com.
Useful for beginners to diagnose network paths and issues.
T top to monitor the server including CPU, storage usage and process runnning etc top
uname
uname show name of system uname -a
uptime show how many users logged in, average load on cpu and active time of your server uptime
sort file | uniq
Identify duplicate lines
uniq NOTE: To use the uniq, the date should be sorted first as it compare line with it's previous to To count/find the no. of instances of duplicates (ex: how many
find the duplicate times Prashant arrived in list)
sort file | uniq -c
umask u+rw,g+r,o-rwx
to change the default permissions for newly created files
umask just doing this will be temporary
normally the permission is picked from bashrc of user and etc when you only execute 'umask' it will give result like 0022
so it means default permission will be 0777-0022 = 0755 (r-x)
Example: unzip archive.zip
Extracts compressed files from a ZIP archive. Usage: Extracts the contents of archive.zip into the current
unzip
directory.
Example: sudo updatedb
Usage: Refreshes the database for the locate command, allowing
updatedb Updates the database used by locate. it to find files more efficiently. Useful for beginners to keep
the file database up-to-date.
useradd <name_of_user>
useradd add user useradd -g superheores -s /bin/bash -c "thor charac" -m -d
/home/thor thor
userdel <name_of_user>
userdel del user userdel -r (will remove home directory)
userdel -f (force delete even if the user is logged in)
U usermod modify user usermod -G superheores hulk (to add user to a new group)
vi vim text editor to edit a file or creat a file vi file_name
Example: vmstat 2 5
Usage: Displays system performance statistics every 2 seconds
vmstat Reports virtual memory statistics. for 5 iterations. Useful for beginners to monitor system
performance, including CPU, memory, and I/O.
Example: vgs
vgs Displays information about volume groups. Usage: Lists all volume groups and their attributes. Useful for
beginners to manage LVM (Logical Volume Manager) storage.
V visudo used to change the user roles and permissins by editing /etc/sudoers file as root only visudo
w show who is logged on what the user is doing w
who show who is logged on to your linux server who
which It will show the path of executable file which pwd
wc -l/w/c file
wc word counter, helps you find no. of words, words present in how many lines etc grep "key" file | wc -l
write to wirte a message to a user, mostly use duing maintenance write user_name
wall to broadcast your message wall
W
W wget to download something in linux wget <download_link_of_file>
Example: echo "file1 file2 file3" | xargs rm
Usage: Removes file1, file2, and file3. Useful for beginners to
xargs Builds and executes command lines from standard input. construct command lines from input.
X
yum install package_name
yum update -y
yum to install packages, downlaod and update yum remove nginx
yum search nginx
Y yum list installed
zcat To read content of compressed file Example: zcat file.gz
Example: zip archive.zip file1 file2
Usage: Creates a ZIP archive named archive.zip containing file1
zip To compress and file2. Useful for beginners to compress files.
zipinfo List detailed information about the contents of a ZIP file. Example: zipinfo archive.zip
Example: zgrep "pattern" file.gz
zgrep Search compressed files for a pattern using grep. Usage: Searches for pattern in file.gz. Useful for beginners to
Z search within compressed files.