Alphabet Command name Details Comment A awk used for data extraction from a file, mostly use for column extraction from a file awk '{print $2}' file_name (it will print 2 column content) awk '{print $NF}' (it will print last column) awk '/string/ {print}' file_name awk '{if($3 >300) print $0}' file_name awk '{if($3==333){$1="Sonu"} print $0 }' text awk 'length($0)>15' text awk -F, '{print $7}' country.txt (csv file , as delimeter) alias to create shortcut to the command or task alias d="ls -ltr | awk '{print $9}'" alias -p (to check the existing alias) after this command, next time you just need to execute 'd' at command used to schedule a task once at 06:43 (then it will stuck in editing mode where you can define task like commands or script name and CTRL+D to finish) at 09:00 AM SUN at 09:00 AM AUG 30 at 09:00 AM 06.22.2024 at 09:00 AM tomorrow atq to list existing jobs atrm <id> to remove the jobs arch to check linux is 64 or 32 bit B bc binary calculator bc bash to run a bash script bash script.sh basename Strips directory and suffix from filenames. basename /usr/local/bin/script.sh Outputs script.sh. bg to send a stopped job in bg to run sleep 50 Ctrl + z to stop jobs to see this job bg (it will start job in background) cat show content of file concatenate two files cat file_name cat file1 file2 > file3 cat /proc/cpuinfo gives you info about your CPU resources cat /proc/meminfo gives you infor about infor and its usage in details cat /etc/redhat-release to check the linux version cal show you calendar cal cal 1993 (full calculator of that year) cal -1 1993 (to show month in 1993) cd change directory chmod change mode, to modify permissions of files chmod o-r file_name ( - to remove permission) chmod g+rw file_name. ( + to add permission) chmod u+x file_name. ( u - user, g - group, o - other, a = all) chown change ownership chown root/user_name folder/file_name
C chage We can use this command to chnage the password expiry chage -l paul (show all he details about account like password expires etc) chage -E 0 user_anme (To disable a account) chage -E -1 user_name (To enable a account) chgrp chnage group chgrp root/user_name folder/file_name crontab to run a command or script on given schedule (cant use as root) To generate cron job http://www.cronmaker.com/ To set timezone use CRON_TZ=America/New_York chrontab -e (for editing or creating new file_ Example of a simple cron job is: * * * * * cd /home/paul/scripts && ./create_file.sh chrontab -l (to show all the cron jobs) cmp compare the content of files byte by byte cmp file1 file2 curl to check if the webpage is up or not, will result into the webpage sourcecode we can also download the software on linux curl www.google.com curl -O <download link> cut to filter out specific characters from the result of output or file, also useful when you want to see only one or two column of a file cut -c2 file_name cut -c1-4 file_name cut -c2,3 file_name cut -d: -f 3 file_name (will show 3rd column separated with : delimiter cp use to copy a file from one location to another cp source_file destination_file cp -p source_file destination_file (if we use -p then it will copy the file with original time when it was last modified) createrepo D date to see the current date and time of system date date -s "28 Jun 2021 23:06:00 IST" date +%F-%N (result: 2022-07-01-011018377) dmesg print or control the kernel ring buffer dmesg diff compare the content of files line by line diff file1.txt file2.txt df report file system disk space usage df -h (h for human readable) dmidecode print system hardware info dmidecode (only as root) dnf Package manager for RPM-based distributions, successor to yum. (new version of linux) sudo dnf install httpd dig DNS lookup utility dig www.google.com dirname Strips the last component from a file name. dirname /usr/local/bin/script.sh Outputs /usr/local/bin du file usage, disk utilization du <file or folder location> (It will show all files size inside that locaion) du -sh <file or folder location> (-h is human readable and only show the size of given folder) E egrep to search for a particular string/keyword from a file egrep "key1|key2" filename echo Print something on terminal echo "hello" env to show env variables on linux to set variable for the current user - .bashrc to set variable for globally - /etc/bashrc or /etc/profile then you need to fire 'source' command To set the environement variable you need to use export command
E ethtool print NIC info ethtool enps03 exit Exits the shell or a script. Close the current terminal (logout) export used to set env vairable temporary export TEST=1 to check, echo $TEST F find to search for a directory or file find /tmp/ -name folder_name find /path/to/search -type f -size +100M (find file based on size) find /path/to/search -mtime -7 (find file based on modified time, 7 days) file to check the type of file file <file_name> free to check the free space free -h fdisk give info about the disk availability fdisk -l fg to bring the running job in foreground fg fold to fold a line into a column echo "ABC" | fold -w1 (w is how much width of each row) output is: A B C ftp File Transfer Protocol client. Example: fgrep 'text' file.txt Usage: Searches for the fixed string text in file.txt. Useful for beginners to search for exact matches in files. fmt Simple text formatter. fmt myfile.txt fsck Filesystem consistency check and repair. Example: sudo fsck /dev/sda1 Usage: Checks and repairs the filesystem on /dev/sda1. Useful for beginners to maintain filesystem integrity. firewall-cmd firewall settings firewall-cmd --add-port=8080/tcp --permanent firewall-cmd --zone=public --add-service=http --permanent firewall-cmd --reload firewall-config it will open GUI to configure firewall settings G grep to search for a particular string/keyword from a file grep keyword filename grep -i keyword (to ignore the upper or lower cases) grep -v keyword (search other than given keyword) groupadd to add group groupadd mygroup check in /etc/group file groupdel to delete group groups Shows the groups a user is a member of. Example: groups username Usage: Lists all the groups that username belongs to. Useful for beginners to check group memberships. getenforce Displays the current SELinux mode. Example: getenforce Usage: Shows whether SELinux is enforcing, permissive, or disabled. Useful for beginners to check SELinux status. getfacl Gets file access control lists (if installed). Example: getfacl filename Usage: Displays the ACLs of filename. Useful for beginners to view detailed file permissions.
G gzip, gunzip compressing and decompressing, usually we apply this on tar file gzip name.tar gunzip name.tar.gz or gzip -d name.tar.gz H 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 halt Stops the system. I ip addr show ip address and network related info ifconfig show ip address and network related info iostat Report Central Processing Unit (CPU) statistics and input/output statistics for devices and partitions. init initi 0-6, 0-6 are different level at which we need to reboot Usage: Shuts down the system (runlevel 0). Beginners should use this with caution as it affects the system's state. id show group and user detail of a user id user_name J jobs to see the current jobs and its state jobs journalctl Queries and displays logs from systemd's journal. Usage: Displays the most recent log entries with detailed information. Useful for beginners to troubleshoot system issues and view log files. K kill to kill any process kill PID kill -9 PID killall Kills all processes by the specified name. Example: killall httpd Usage: Terminates all processes named httpd. L last show listing of last logged users last less it show you file nicely manner page vise less file_name ls to list the file ls ls -ltr ls -la (to see hidden files) ls -i (to see the inode) ln to create hard or soft link ln 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. locate its like find command but its search in its own db locate filename (to search this file on system) M 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 mount Mounts a filesystem. Example: sudo mount /dev/sda1 /mnt Usage: Mounts the filesystem on /dev/sda1 to the /mnt directory. Useful for beginners to access filesystems and external drives. mv to move or rename a file mv filename newname
N nohup to run a process in backgroup even if user close his terminal nohup sleep 50 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 nslookup Queries Internet name servers interactively and DNS record Example: nslookup example.com Usage: Retrieves the DNS records for example.com. nmcli Command-line client for NetworkManager. Example: nmcli device status Usage: Shows the status of network devices. Useful for beginners to manage network connections. nproc Shows the number of processing units available. Example: nproc Usage: Displays the number of CPU cores available. Useful for beginners to understand system resources. netstat Print network connections, routing tables, interface statistics, masquerade connections, and multicast memberships netstat -rnv netstat -tunlp (t-tcp, u-udp, n-no.of port, l-listening port, p- PID programname) netstat -4tunlp (will only show TCPv4 and exclude the TCPv6) To check no. of connection from a specific IP netstat -an | grep <IP> O od Dumps files in octal and other formats. Example: od -c file.txt Usage: Displays the content of file.txt in ASCII characters. openssl A toolkit for the Transport Layer Security (TLS) and Secure Sockets Layer (SSL) protocols. Example: openssl genpkey -algorithm RSA -out private_key.pem Usage: Generates a private key using RSA. Useful for beginners to manage SSL/TLS certificates and keys. P pwd print working dir pwd passwd to change password of a user passwd userid ps to check if a given process is running or not ps -ef | grep <service/process_name> printenv to show the env variables pskill Terminates processes by name Example: sudo pskill firefox Usage: Kills all processes with the name firefox. Useful for beginners to terminate specific applications. pv Monitors the progress of data through a pipeline (if installed). Example: pv file.txt | gzip > file.txt.gz Usage: Shows progress of compressing file.txt to file.txt.gz. Useful for beginners to visualize data processing. parted Manages disk partitions. Example: sudo parted /dev/sda Usage: Opens the partition editor for the disk /dev/sda. Useful for beginners to create, delete, and modify partitions. ping used to check the network connectivity ping ip ping -c 1 ip (only try once) Q quota Displays disk usage and limits. quotacheck Scans a filesystem for disk usage, creates, and updates quota files. rm to remove/delete folder/file rm file_name rm -rf folder_name rpm reh hat package manager, used to list, install or uninstall packages rpm -qa (to list all the installed packages) rpm -e <package_name> (to uninstall any package)
R rsync to synchronized and transfer the data on local system or between local and remote system rsync -avz source destination rsync -avzh destination source (from remote) renice To change the priority of already running program renice -n 5 process_name runlevel to check the current system run-level rename Renames multiple files. Example: rename 's/.txt/.bak/' *.txt Usage: Renames all .txt files to .bak. Useful for beginners to rename files in bulk. route Shows/manipulates the IP routing table (deprecated, use ip route instead). Example: route -n Usage: Displays the routing table. Useful for beginners to view network routes. reboot halt, poweroff, reboot - Halt, power-off or reboot the machine script to record your activity until you exit it will store all the activity a user perform and store in a file so you can keep ther record of the over all activity script <file_name> and start your activity once done, hit exit Ctrl+D sed replace string, find/delete line, remove empty lines sed 's/<string_to_change>/<new_string>/g' file_name (only show change) sed -i 's/Prashant/Potty/g' file_name (change in file) sed -i '5!s/Prashant/Potty/g' file_name (change everywhere except line 5) sed -i 's/Prashant//g' file_name (just to remove word) sed '1d' file_name (to delete first line) sed '1,2d' file_name sed '/st/ /g' (to replace tab with space) sed -n '3,5p' text (to show only 3 to 5 lines) sed -n '3,4d' text (to delete 3 to 5 lines and show) sed -n '$d' file_name ($ is last line) sed -i '/^$/d' text (to remove empty lines) sosreport generate report collect and diagnostic support data and package, it will create a zip file under /var/tmp sos report split split any files into different small files based on given line no. split -l 300 file_name sort sort the conent of file sort file (sort based on starting no. or letter) sort -r file (Reverse sort) sort -k2 file (k is column) If you are sorting number (not based on starting no. but weightage) sort -n file_name sort -h (human redable no.) To sort only unique no. sort -un file Example of sort -h 99K 8M 96K Sorting will be 96K 99K 8M sudo to switch the user or execute a command which need superuser access sudo -iu paul sudo yum install nginx
S shuf to shuffle each line within a file or stdin A B C cat file | shuf B C ssh Secure Shell, used to connect to remote servers. Example: ssh user@hostname ssh-keygen Generates, manages, and converts authentication keys for SSH. Example: ssh-keygen -t rsa -b 2048 Usage: Generates an RSA key pair with 2048-bit encryption. Useful for beginners to set up SSH key-based authentication. scp Secure copy, used to copy files to remote servers Example: scp file.txt user@remote_host:/path/to/destination Usage: Copies file.txt to remote_host under /path/to/destination. shutdown shutdown your server, Halt, power-off or reboot the machine strings Displays printable strings in files. Example: strings binaryfile Usage: Extracts and displays printable strings from binaryfile. Useful for beginners to find readable text in binary files. systemctl Control the systemd system and service manager systemctl start <service_name> like chronyd systemctl status chronyd T tail gives you last few lines tail -2 file_ame tail -f file_name (will keep update the logs) tar grouping of files tar cvf name.tar file_path tar xvf name.tar tar -tf name.tar (will show or list the content of tar file) ----------------------- tar and zip at the same time tar -zcvf name.tar.gz file_path tar -zxvf name.tar.gz NOTE: tar.gz and tgz is the same thing tr to translate or delete echo "hello" | tr [:lower:] [:upper:] delete the lowercase: | -d [:upper:] space with tab: | [:space:] "t" delete or change digits: | -d [:digit:] [:punct:] tee to store and display the output of a command at the same time ls -ltr | tee dir.txt ls -ltr | tee -a dir.txt (to append) telnet to check connectivity from your linux server to outside telnet ip port touch to create a file touch file-name touch -d "Thu, 1 Mar 2018 12:30:00" <file_name> To create file with given date truncate to reduce the file of the size, but your data will be lost (its not like compressing) truncate -s 50 file_name tcpdump to capture the incoming and outgoing traffic over the network interface tcpdump -i <interface_name>
T traceroute Traces the route packets take to a network host. Example: traceroute example.com Usage: Displays the route packets take to reach example.com. Useful for beginners to diagnose network paths and issues. top to monitor the server including CPU, storage usage and process runnning etc top U uname show name of system uname uname -a uptime show how many users logged in, average load on cpu and active time of your server uptime uniq Identify duplicate lines NOTE: To use the uniq, the date should be sorted first as it compare line with it's previous to find the duplicate sort file | uniq To count/find the no. of instances of duplicates (ex: how many times Prashant arrived in list) sort file | uniq -c umask to change the default permissions for newly created files normally the permission is picked from bashrc of user and etc umask u+rw,g+r,o-rwx just doing this will be temporary when you only execute 'umask' it will give result like 0022 so it means default permission will be 0777-0022 = 0755 (r-x) unzip Extracts compressed files from a ZIP archive. Example: unzip archive.zip Usage: Extracts the contents of archive.zip into the current directory. updatedb Updates the database used by locate. Example: sudo updatedb Usage: Refreshes the database for the locate command, allowing it to find files more efficiently. Useful for beginners to keep the file database up-to-date. useradd add user useradd <name_of_user> useradd -g superheores -s /bin/bash -c "thor charac" -m -d /home/thor thor userdel del user userdel <name_of_user> userdel -r (will remove home directory) userdel -f (force delete even if the user is logged in) usermod modify user usermod -G superheores hulk (to add user to a new group) V vi vim text editor to edit a file or creat a file vi file_name vmstat Reports virtual memory statistics. Example: vmstat 2 5 Usage: Displays system performance statistics every 2 seconds for 5 iterations. Useful for beginners to monitor system performance, including CPU, memory, and I/O. vgs Displays information about volume groups. Example: vgs Usage: Lists all volume groups and their attributes. Useful for beginners to manage LVM (Logical Volume Manager) storage. visudo used to change the user roles and permissins by editing /etc/sudoers file as root only visudo W 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 word counter, helps you find no. of words, words present in how many lines etc wc -l/w/c file 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 wget to download something in linux wget <download_link_of_file> X xargs Builds and executes command lines from standard input. Example: echo "file1 file2 file3" | xargs rm Usage: Removes file1, file2, and file3. Useful for beginners to construct command lines from input. Y yum to install packages, downlaod and update yum install package_name yum update -y yum remove nginx yum search nginx yum list installed Z zcat To read content of compressed file Example: zcat file.gz zip To compress Example: zip archive.zip file1 file2 Usage: Creates a ZIP archive named archive.zip containing file1 and file2. Useful for beginners to compress files. zipinfo List detailed information about the contents of a ZIP file. Example: zipinfo archive.zip zgrep Search compressed files for a pattern using grep. Example: zgrep "pattern" file.gz Usage: Searches for pattern in file.gz. Useful for beginners to search within compressed files.
Linux Commands CheatSheet - PDF.pdf for engineer
Linux Commands CheatSheet - PDF.pdf for engineer
Linux Commands CheatSheet - PDF.pdf for engineer
Linux Commands CheatSheet - PDF.pdf for engineer
Linux Commands CheatSheet - PDF.pdf for engineer
Linux Commands CheatSheet - PDF.pdf for engineer
Linux Commands CheatSheet - PDF.pdf for engineer
Linux Commands CheatSheet - PDF.pdf for engineer
Linux Commands CheatSheet - PDF.pdf for engineer
Linux Commands CheatSheet - PDF.pdf for engineer
Linux Commands CheatSheet - PDF.pdf for engineer
Linux Commands CheatSheet - PDF.pdf for engineer
Linux Commands CheatSheet - PDF.pdf for engineer
Linux Commands CheatSheet - PDF.pdf for engineer
Linux Commands CheatSheet - PDF.pdf for engineer
Linux Commands CheatSheet - PDF.pdf for engineer
Linux Commands CheatSheet - PDF.pdf for engineer
Linux Commands CheatSheet - PDF.pdf for engineer
Linux Commands CheatSheet - PDF.pdf for engineer
Linux Commands CheatSheet - PDF.pdf for engineer
Linux Commands CheatSheet - PDF.pdf for engineer
Linux Commands CheatSheet - PDF.pdf for engineer
Linux Commands CheatSheet - PDF.pdf for engineer
Linux Commands CheatSheet - PDF.pdf for engineer
Linux Commands CheatSheet - PDF.pdf for engineer

Linux Commands CheatSheet - PDF.pdf for engineer

  • 1.
    Alphabet Command nameDetails Comment A awk used for data extraction from a file, mostly use for column extraction from a file awk '{print $2}' file_name (it will print 2 column content) awk '{print $NF}' (it will print last column) awk '/string/ {print}' file_name awk '{if($3 >300) print $0}' file_name awk '{if($3==333){$1="Sonu"} print $0 }' text awk 'length($0)>15' text awk -F, '{print $7}' country.txt (csv file , as delimeter) alias to create shortcut to the command or task alias d="ls -ltr | awk '{print $9}'" alias -p (to check the existing alias) after this command, next time you just need to execute 'd' at command used to schedule a task once at 06:43 (then it will stuck in editing mode where you can define task like commands or script name and CTRL+D to finish) at 09:00 AM SUN at 09:00 AM AUG 30 at 09:00 AM 06.22.2024 at 09:00 AM tomorrow atq to list existing jobs atrm <id> to remove the jobs arch to check linux is 64 or 32 bit B bc binary calculator bc bash to run a bash script bash script.sh basename Strips directory and suffix from filenames. basename /usr/local/bin/script.sh Outputs script.sh. bg to send a stopped job in bg to run sleep 50 Ctrl + z to stop jobs to see this job bg (it will start job in background) cat show content of file concatenate two files cat file_name cat file1 file2 > file3 cat /proc/cpuinfo gives you info about your CPU resources cat /proc/meminfo gives you infor about infor and its usage in details cat /etc/redhat-release to check the linux version cal show you calendar cal cal 1993 (full calculator of that year) cal -1 1993 (to show month in 1993) cd change directory chmod change mode, to modify permissions of files chmod o-r file_name ( - to remove permission) chmod g+rw file_name. ( + to add permission) chmod u+x file_name. ( u - user, g - group, o - other, a = all) chown change ownership chown root/user_name folder/file_name
  • 2.
    C chage We canuse this command to chnage the password expiry chage -l paul (show all he details about account like password expires etc) chage -E 0 user_anme (To disable a account) chage -E -1 user_name (To enable a account) chgrp chnage group chgrp root/user_name folder/file_name crontab to run a command or script on given schedule (cant use as root) To generate cron job http://www.cronmaker.com/ To set timezone use CRON_TZ=America/New_York chrontab -e (for editing or creating new file_ Example of a simple cron job is: * * * * * cd /home/paul/scripts && ./create_file.sh chrontab -l (to show all the cron jobs) cmp compare the content of files byte by byte cmp file1 file2 curl to check if the webpage is up or not, will result into the webpage sourcecode we can also download the software on linux curl www.google.com curl -O <download link> cut to filter out specific characters from the result of output or file, also useful when you want to see only one or two column of a file cut -c2 file_name cut -c1-4 file_name cut -c2,3 file_name cut -d: -f 3 file_name (will show 3rd column separated with : delimiter cp use to copy a file from one location to another cp source_file destination_file cp -p source_file destination_file (if we use -p then it will copy the file with original time when it was last modified) createrepo D date to see the current date and time of system date date -s "28 Jun 2021 23:06:00 IST" date +%F-%N (result: 2022-07-01-011018377) dmesg print or control the kernel ring buffer dmesg diff compare the content of files line by line diff file1.txt file2.txt df report file system disk space usage df -h (h for human readable) dmidecode print system hardware info dmidecode (only as root) dnf Package manager for RPM-based distributions, successor to yum. (new version of linux) sudo dnf install httpd dig DNS lookup utility dig www.google.com dirname Strips the last component from a file name. dirname /usr/local/bin/script.sh Outputs /usr/local/bin du file usage, disk utilization du <file or folder location> (It will show all files size inside that locaion) du -sh <file or folder location> (-h is human readable and only show the size of given folder) E egrep to search for a particular string/keyword from a file egrep "key1|key2" filename echo Print something on terminal echo "hello" env to show env variables on linux to set variable for the current user - .bashrc to set variable for globally - /etc/bashrc or /etc/profile then you need to fire 'source' command To set the environement variable you need to use export command
  • 3.
    E ethtool print NICinfo ethtool enps03 exit Exits the shell or a script. Close the current terminal (logout) export used to set env vairable temporary export TEST=1 to check, echo $TEST F find to search for a directory or file find /tmp/ -name folder_name find /path/to/search -type f -size +100M (find file based on size) find /path/to/search -mtime -7 (find file based on modified time, 7 days) file to check the type of file file <file_name> free to check the free space free -h fdisk give info about the disk availability fdisk -l fg to bring the running job in foreground fg fold to fold a line into a column echo "ABC" | fold -w1 (w is how much width of each row) output is: A B C ftp File Transfer Protocol client. Example: fgrep 'text' file.txt Usage: Searches for the fixed string text in file.txt. Useful for beginners to search for exact matches in files. fmt Simple text formatter. fmt myfile.txt fsck Filesystem consistency check and repair. Example: sudo fsck /dev/sda1 Usage: Checks and repairs the filesystem on /dev/sda1. Useful for beginners to maintain filesystem integrity. firewall-cmd firewall settings firewall-cmd --add-port=8080/tcp --permanent firewall-cmd --zone=public --add-service=http --permanent firewall-cmd --reload firewall-config it will open GUI to configure firewall settings G grep to search for a particular string/keyword from a file grep keyword filename grep -i keyword (to ignore the upper or lower cases) grep -v keyword (search other than given keyword) groupadd to add group groupadd mygroup check in /etc/group file groupdel to delete group groups Shows the groups a user is a member of. Example: groups username Usage: Lists all the groups that username belongs to. Useful for beginners to check group memberships. getenforce Displays the current SELinux mode. Example: getenforce Usage: Shows whether SELinux is enforcing, permissive, or disabled. Useful for beginners to check SELinux status. getfacl Gets file access control lists (if installed). Example: getfacl filename Usage: Displays the ACLs of filename. Useful for beginners to view detailed file permissions.
  • 4.
    G gzip, gunzip compressingand decompressing, usually we apply this on tar file gzip name.tar gunzip name.tar.gz or gzip -d name.tar.gz H 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 halt Stops the system. I ip addr show ip address and network related info ifconfig show ip address and network related info iostat Report Central Processing Unit (CPU) statistics and input/output statistics for devices and partitions. init initi 0-6, 0-6 are different level at which we need to reboot Usage: Shuts down the system (runlevel 0). Beginners should use this with caution as it affects the system's state. id show group and user detail of a user id user_name J jobs to see the current jobs and its state jobs journalctl Queries and displays logs from systemd's journal. Usage: Displays the most recent log entries with detailed information. Useful for beginners to troubleshoot system issues and view log files. K kill to kill any process kill PID kill -9 PID killall Kills all processes by the specified name. Example: killall httpd Usage: Terminates all processes named httpd. L last show listing of last logged users last less it show you file nicely manner page vise less file_name ls to list the file ls ls -ltr ls -la (to see hidden files) ls -i (to see the inode) ln to create hard or soft link ln 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. locate its like find command but its search in its own db locate filename (to search this file on system) M 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 mount Mounts a filesystem. Example: sudo mount /dev/sda1 /mnt Usage: Mounts the filesystem on /dev/sda1 to the /mnt directory. Useful for beginners to access filesystems and external drives. mv to move or rename a file mv filename newname
  • 5.
    N nohup to runa process in backgroup even if user close his terminal nohup sleep 50 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 nslookup Queries Internet name servers interactively and DNS record Example: nslookup example.com Usage: Retrieves the DNS records for example.com. nmcli Command-line client for NetworkManager. Example: nmcli device status Usage: Shows the status of network devices. Useful for beginners to manage network connections. nproc Shows the number of processing units available. Example: nproc Usage: Displays the number of CPU cores available. Useful for beginners to understand system resources. netstat Print network connections, routing tables, interface statistics, masquerade connections, and multicast memberships netstat -rnv netstat -tunlp (t-tcp, u-udp, n-no.of port, l-listening port, p- PID programname) netstat -4tunlp (will only show TCPv4 and exclude the TCPv6) To check no. of connection from a specific IP netstat -an | grep <IP> O od Dumps files in octal and other formats. Example: od -c file.txt Usage: Displays the content of file.txt in ASCII characters. openssl A toolkit for the Transport Layer Security (TLS) and Secure Sockets Layer (SSL) protocols. Example: openssl genpkey -algorithm RSA -out private_key.pem Usage: Generates a private key using RSA. Useful for beginners to manage SSL/TLS certificates and keys. P pwd print working dir pwd passwd to change password of a user passwd userid ps to check if a given process is running or not ps -ef | grep <service/process_name> printenv to show the env variables pskill Terminates processes by name Example: sudo pskill firefox Usage: Kills all processes with the name firefox. Useful for beginners to terminate specific applications. pv Monitors the progress of data through a pipeline (if installed). Example: pv file.txt | gzip > file.txt.gz Usage: Shows progress of compressing file.txt to file.txt.gz. Useful for beginners to visualize data processing. parted Manages disk partitions. Example: sudo parted /dev/sda Usage: Opens the partition editor for the disk /dev/sda. Useful for beginners to create, delete, and modify partitions. ping used to check the network connectivity ping ip ping -c 1 ip (only try once) Q quota Displays disk usage and limits. quotacheck Scans a filesystem for disk usage, creates, and updates quota files. rm to remove/delete folder/file rm file_name rm -rf folder_name rpm reh hat package manager, used to list, install or uninstall packages rpm -qa (to list all the installed packages) rpm -e <package_name> (to uninstall any package)
  • 6.
    R rsync to synchronizedand transfer the data on local system or between local and remote system rsync -avz source destination rsync -avzh destination source (from remote) renice To change the priority of already running program renice -n 5 process_name runlevel to check the current system run-level rename Renames multiple files. Example: rename 's/.txt/.bak/' *.txt Usage: Renames all .txt files to .bak. Useful for beginners to rename files in bulk. route Shows/manipulates the IP routing table (deprecated, use ip route instead). Example: route -n Usage: Displays the routing table. Useful for beginners to view network routes. reboot halt, poweroff, reboot - Halt, power-off or reboot the machine script to record your activity until you exit it will store all the activity a user perform and store in a file so you can keep ther record of the over all activity script <file_name> and start your activity once done, hit exit Ctrl+D sed replace string, find/delete line, remove empty lines sed 's/<string_to_change>/<new_string>/g' file_name (only show change) sed -i 's/Prashant/Potty/g' file_name (change in file) sed -i '5!s/Prashant/Potty/g' file_name (change everywhere except line 5) sed -i 's/Prashant//g' file_name (just to remove word) sed '1d' file_name (to delete first line) sed '1,2d' file_name sed '/st/ /g' (to replace tab with space) sed -n '3,5p' text (to show only 3 to 5 lines) sed -n '3,4d' text (to delete 3 to 5 lines and show) sed -n '$d' file_name ($ is last line) sed -i '/^$/d' text (to remove empty lines) sosreport generate report collect and diagnostic support data and package, it will create a zip file under /var/tmp sos report split split any files into different small files based on given line no. split -l 300 file_name sort sort the conent of file sort file (sort based on starting no. or letter) sort -r file (Reverse sort) sort -k2 file (k is column) If you are sorting number (not based on starting no. but weightage) sort -n file_name sort -h (human redable no.) To sort only unique no. sort -un file Example of sort -h 99K 8M 96K Sorting will be 96K 99K 8M sudo to switch the user or execute a command which need superuser access sudo -iu paul sudo yum install nginx
  • 7.
    S shuf to shuffleeach line within a file or stdin A B C cat file | shuf B C ssh Secure Shell, used to connect to remote servers. Example: ssh user@hostname ssh-keygen Generates, manages, and converts authentication keys for SSH. Example: ssh-keygen -t rsa -b 2048 Usage: Generates an RSA key pair with 2048-bit encryption. Useful for beginners to set up SSH key-based authentication. scp Secure copy, used to copy files to remote servers Example: scp file.txt user@remote_host:/path/to/destination Usage: Copies file.txt to remote_host under /path/to/destination. shutdown shutdown your server, Halt, power-off or reboot the machine strings Displays printable strings in files. Example: strings binaryfile Usage: Extracts and displays printable strings from binaryfile. Useful for beginners to find readable text in binary files. systemctl Control the systemd system and service manager systemctl start <service_name> like chronyd systemctl status chronyd T tail gives you last few lines tail -2 file_ame tail -f file_name (will keep update the logs) tar grouping of files tar cvf name.tar file_path tar xvf name.tar tar -tf name.tar (will show or list the content of tar file) ----------------------- tar and zip at the same time tar -zcvf name.tar.gz file_path tar -zxvf name.tar.gz NOTE: tar.gz and tgz is the same thing tr to translate or delete echo "hello" | tr [:lower:] [:upper:] delete the lowercase: | -d [:upper:] space with tab: | [:space:] "t" delete or change digits: | -d [:digit:] [:punct:] tee to store and display the output of a command at the same time ls -ltr | tee dir.txt ls -ltr | tee -a dir.txt (to append) telnet to check connectivity from your linux server to outside telnet ip port touch to create a file touch file-name touch -d "Thu, 1 Mar 2018 12:30:00" <file_name> To create file with given date truncate to reduce the file of the size, but your data will be lost (its not like compressing) truncate -s 50 file_name tcpdump to capture the incoming and outgoing traffic over the network interface tcpdump -i <interface_name>
  • 8.
    T traceroute Traces theroute packets take to a network host. Example: traceroute example.com Usage: Displays the route packets take to reach example.com. Useful for beginners to diagnose network paths and issues. top to monitor the server including CPU, storage usage and process runnning etc top U uname show name of system uname uname -a uptime show how many users logged in, average load on cpu and active time of your server uptime uniq Identify duplicate lines NOTE: To use the uniq, the date should be sorted first as it compare line with it's previous to find the duplicate sort file | uniq To count/find the no. of instances of duplicates (ex: how many times Prashant arrived in list) sort file | uniq -c umask to change the default permissions for newly created files normally the permission is picked from bashrc of user and etc umask u+rw,g+r,o-rwx just doing this will be temporary when you only execute 'umask' it will give result like 0022 so it means default permission will be 0777-0022 = 0755 (r-x) unzip Extracts compressed files from a ZIP archive. Example: unzip archive.zip Usage: Extracts the contents of archive.zip into the current directory. updatedb Updates the database used by locate. Example: sudo updatedb Usage: Refreshes the database for the locate command, allowing it to find files more efficiently. Useful for beginners to keep the file database up-to-date. useradd add user useradd <name_of_user> useradd -g superheores -s /bin/bash -c "thor charac" -m -d /home/thor thor userdel del user userdel <name_of_user> userdel -r (will remove home directory) userdel -f (force delete even if the user is logged in) usermod modify user usermod -G superheores hulk (to add user to a new group) V vi vim text editor to edit a file or creat a file vi file_name vmstat Reports virtual memory statistics. Example: vmstat 2 5 Usage: Displays system performance statistics every 2 seconds for 5 iterations. Useful for beginners to monitor system performance, including CPU, memory, and I/O. vgs Displays information about volume groups. Example: vgs Usage: Lists all volume groups and their attributes. Useful for beginners to manage LVM (Logical Volume Manager) storage. visudo used to change the user roles and permissins by editing /etc/sudoers file as root only visudo W 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 word counter, helps you find no. of words, words present in how many lines etc wc -l/w/c file 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
  • 9.
    W wget todownload something in linux wget <download_link_of_file> X xargs Builds and executes command lines from standard input. Example: echo "file1 file2 file3" | xargs rm Usage: Removes file1, file2, and file3. Useful for beginners to construct command lines from input. Y yum to install packages, downlaod and update yum install package_name yum update -y yum remove nginx yum search nginx yum list installed Z zcat To read content of compressed file Example: zcat file.gz zip To compress Example: zip archive.zip file1 file2 Usage: Creates a ZIP archive named archive.zip containing file1 and file2. Useful for beginners to compress files. zipinfo List detailed information about the contents of a ZIP file. Example: zipinfo archive.zip zgrep Search compressed files for a pattern using grep. Example: zgrep "pattern" file.gz Usage: Searches for pattern in file.gz. Useful for beginners to search within compressed files.