{"id":107,"date":"2023-01-17T07:57:21","date_gmt":"2023-01-17T07:57:21","guid":{"rendered":"https:\/\/raesch.ch\/?p=107"},"modified":"2023-01-17T07:59:42","modified_gmt":"2023-01-17T07:59:42","slug":"linux-cheat-sheet","status":"publish","type":"post","link":"https:\/\/raesch.ch\/index.php\/2023\/01\/17\/linux-cheat-sheet\/","title":{"rendered":"LINUX- CHEAT SHEET"},"content":{"rendered":"\n<h1 class=\"wp-block-heading\" id=\"c511\">_System Based Commands<\/h1>\n\n\n\n<p><\/p>\n\n\n\n<p id=\"e49d\"><code>#uname<\/code>\u00a0Displays Linux system information<\/p>\n\n\n\n<p id=\"f288\"><code>#uname -r<\/code>Displays kernel release information<\/p>\n\n\n\n<p id=\"69c9\"><code>#uptime<\/code>Displays how long the system has been running<\/p>\n\n\n\n<p id=\"cabf\"><code>#hostname<\/code>Shows the system hostname<\/p>\n\n\n\n<p id=\"ee86\"><code>#hostname -i<\/code>Displays the IP address of the system<\/p>\n\n\n\n<p id=\"f1e5\"><code>#last reboot<\/code>Shows system reboot history<\/p>\n\n\n\n<p id=\"6f36\"><code>#date<\/code>Displays current system date and time<\/p>\n\n\n\n<p id=\"a4b2\"><code>#whoami<\/code>Displays who you are logged in as<\/p>\n\n\n\n<p id=\"56ff\"><code>#finger username<\/code>Displays information about the user<\/p>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"be93\">_Hardware Based Command<\/h1>\n\n\n\n<p id=\"553c\"><code>#lshw&nbsp;<\/code>Displays information about system&#8217;s hardware configuration<\/p>\n\n\n\n<p id=\"636f\"><code>#lsblk<\/code>Displays block devices related information<\/p>\n\n\n\n<p id=\"5d70\"><code>#free -m<\/code>Displays free and used memory in the system (-m indicates memory in MB)<\/p>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"aa4c\">_Users Management Commands<\/h1>\n\n\n\n<p id=\"691c\"><code>#id<\/code>Displays the details of the active user e.g. uid, gid, and groups<\/p>\n\n\n\n<p id=\"a6c1\"><code>#last<\/code>Shows the last logins in the system<\/p>\n\n\n\n<p id=\"6c16\"><code>#who<\/code>Shows who is logged in to the system<\/p>\n\n\n\n<p id=\"5d33\"><code>#groupadd \"pink\"<\/code>Adds the group \u2018pink\u2019<\/p>\n\n\n\n<p id=\"193b\"><code>#adduser \"rajni\"<\/code>Adds user \u2018rajni\u2019<\/p>\n\n\n\n<p id=\"818a\"><code>#userdel \"rajni\"<\/code>Deletes user \u2018rajni\u2019<\/p>\n\n\n\n<p id=\"0273\"><code>#usermod<\/code>Used for modifying user information<\/p>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"5207\">_File Commands<\/h1>\n\n\n\n<p id=\"cafc\"><code>#ls -al<\/code>Lists files &#8211; both regular &amp; hidden files and their permissions<\/p>\n\n\n\n<p id=\"61e1\"><code>#pwd<\/code>Displays the present working directory path<\/p>\n\n\n\n<p id=\"e68c\"><code>mkdir 'pink'<\/code>Creates a new directory named \u2018pink\u2019<\/p>\n\n\n\n<p id=\"95df\"><code>#rm file_name<\/code>Removes a file<\/p>\n\n\n\n<p id=\"4c8d\"><code>#rm -f filename<\/code>Forcefully removes a file<\/p>\n\n\n\n<p id=\"f4a7\"><code>#rm -r directory_name<\/code>Removes a directory recursively<\/p>\n\n\n\n<p id=\"a46c\"><code>#rm -rf directory_name<\/code>Removes a directory forcefully and recursively<\/p>\n\n\n\n<p id=\"f705\"><code>#cp file1 file2<\/code>Copies the contents of file1 to file2<\/p>\n\n\n\n<p id=\"8fa7\"><code>#cp -r dir1 dir2<\/code>Recursively Copies dir1 to dir2. dir2 is created if it does not exist<\/p>\n\n\n\n<p id=\"5642\"><code>#mv file1 file2<\/code>Renames file1 to file2<\/p>\n\n\n\n<p id=\"9216\"><code>#ln -s \/path\/to\/file_name link_name<\/code>Creates a symbolic link to file_name<\/p>\n\n\n\n<p id=\"151a\"><code>#touch file_name<\/code>Creates a new file<\/p>\n\n\n\n<p id=\"d0fb\"><code>#cat &gt; file_name<\/code>Places standard input into a file<\/p>\n\n\n\n<p id=\"64d5\"><code>#more file_name<\/code>Outputs the contents of a file<\/p>\n\n\n\n<p id=\"c649\"><code>#head file_name<\/code>Displays the first 10 lines of a file<\/p>\n\n\n\n<p id=\"86b5\"><code>#tail file_name<\/code>Displays the last 10 lines of a file<\/p>\n\n\n\n<p id=\"d221\"><code>#gpg -c file_name<\/code>Encrypts a file<\/p>\n\n\n\n<p id=\"a2d8\"><code>#gpg file_name.gpg<\/code>Decrypts a file<\/p>\n\n\n\n<p id=\"b800\"><code>#wc<\/code>Prints the number of bytes, words and lines in a file<\/p>\n\n\n\n<p id=\"cc8b\"><code>#xargs<\/code>Executes commands from standard input<\/p>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"907f\">_Process Related Commands<\/h1>\n\n\n\n<p id=\"3e19\"><code>#ps<\/code>Display currently active processes<\/p>\n\n\n\n<p id=\"6f3c\"><code>#ps aux | grep 'telnet'<\/code>Searches for the id of the process &#8218;telnet&#8216;<\/p>\n\n\n\n<p id=\"4f56\"><code>#pmap<\/code>Displays memory map of processes<\/p>\n\n\n\n<p id=\"5f54\"><code>#top<\/code>&nbsp;Displays all running processes<\/p>\n\n\n\n<p id=\"aa55\"><code>#kill pid<\/code>Terminates process with a given pid<\/p>\n\n\n\n<p id=\"a4e6\"><code>#killall proc<\/code>Kills \/ Terminates all processes named proc<\/p>\n\n\n\n<p id=\"c503\"><code>#pkill process-name<\/code>Sends a signal to a process with its name<\/p>\n\n\n\n<p id=\"8df7\"><code>#bg<\/code>Resumes suspended jobs in the background<\/p>\n\n\n\n<p id=\"7326\"><code>#fg<\/code>Brings suspended jobs to the foreground<\/p>\n\n\n\n<p id=\"6426\"><code>#lsof<\/code>Lists files that are open by processes<\/p>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"de60\">_File Permission Commands<\/h1>\n\n\n\n<p id=\"e2cc\"><code>chmod octal filename<\/code>&nbsp;Change file permissions of the file to octal<\/p>\n\n\n\n<p id=\"efe6\"><strong>Example<\/strong><\/p>\n\n\n\n<p id=\"b254\"><code>#chmod 777 peep.txt<\/code>Set rwx permissions to owner, group and everyone<\/p>\n\n\n\n<p id=\"f67b\"><code>#chmod 755 peep.txt<\/code>&nbsp;Set rwx to the owner and r_x to group and everyone<\/p>\n\n\n\n<p id=\"5d8f\"><code>#chmod 766 peep.txt<\/code>&nbsp;Sets rwx for owner, rw for group and everyone<\/p>\n\n\n\n<p id=\"9310\"><code>#chown owner user-file<\/code>&nbsp;Change ownership of the file<\/p>\n\n\n\n<p id=\"2d6d\"><code>#chown owner-user:owner-group file_name<\/code>&nbsp;Change owner and group owner of the file<\/p>\n\n\n\n<p id=\"3642\"><code>#chown owner-user:owner-group directory<\/code>&nbsp;Change owner and group owner of the directory<\/p>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"ac18\">_Network Commands<\/h1>\n\n\n\n<p id=\"7b0c\"><code>#ip addr show<\/code>&nbsp;Displays IP addresses and all the network interfaces<\/p>\n\n\n\n<p id=\"21be\"><code>#ip address add 192.160.0.1\/24 dev eth0<\/code>&nbsp;Assigns IP address 192.168.0.1 to interface eth0<\/p>\n\n\n\n<p id=\"f533\"><code>#ifconfig<\/code>&nbsp;Displays IP addresses of all network interfaces<\/p>\n\n\n\n<p id=\"5b23\"><code>#ping host<\/code>&nbsp;ping command sends an ICMP echo request to establish a connection to server<\/p>\n\n\n\n<p id=\"487e\"><code>#whois domain<\/code>&nbsp;Retrieves more information about a domain name<\/p>\n\n\n\n<p id=\"7bba\"><code>#dig domain<\/code>&nbsp;Retrieves DNS information about the domain<\/p>\n\n\n\n<p id=\"a3b0\"><code>#host google.com<\/code>&nbsp;Performs an IP lookup for the domain name<\/p>\n\n\n\n<p id=\"c5ff\"><code>#hostname -i<\/code>&nbsp;Displays local IP address<\/p>\n\n\n\n<p id=\"669f\"><code>#wget file_name<\/code>&nbsp;Downloads a file from an online source<\/p>\n\n\n\n<p id=\"14d9\"><code>#netstat -pnltu<\/code>&nbsp;Displays all active listening ports<\/p>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"7f13\">_Compression\/Archives Commands<\/h1>\n\n\n\n<p id=\"29bf\"><code>#tar -cf peep.tar peep&lt;:code&gt;<\/code>Creates archive file called &#8218;peep.tar&#8216; from file &#8218;peep&#8216;<\/p>\n\n\n\n<p id=\"3fd9\"><code>#tar -xf peep.tar<\/code>&nbsp;Extract archive file &#8218;peep.tar&#8216;<\/p>\n\n\n\n<p id=\"b909\"><code>#tar -zcvf peep.tar.gz source-folder<\/code>&nbsp;Creates gzipped tar archive file from the source folder<\/p>\n\n\n\n<p id=\"b8fe\"><code>#gzip file<\/code>&nbsp;Compression a file with .gz extension<\/p>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"2ce0\">_Install Packages Commands<\/h1>\n\n\n\n<p id=\"8075\"><code>#rpm -i pkg_name.rpm<\/code>&nbsp;Install an rpm package<\/p>\n\n\n\n<p id=\"3fb2\"><code>#rpm -e pkg_name<\/code>&nbsp;Removes an rpm package<\/p>\n\n\n\n<p id=\"c054\"><code>#dnf install pkg_name<\/code>Install package using dnf utility<\/p>\n\n\n\n<ul><li><\/li><\/ul>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"2ee0\">_Search Commands<\/h1>\n\n\n\n<p id=\"2bab\"><code>#grep 'pattern' files<\/code>&nbsp;Search for a given pattern in files<\/p>\n\n\n\n<p id=\"cb52\"><code>#grep -r pattern dir<\/code>&nbsp;Search recursively for a pattern in a given directory<\/p>\n\n\n\n<p id=\"b47c\"><code>#locate file<\/code>&nbsp;Find all instances of the file<\/p>\n\n\n\n<p id=\"edbd\"><code>#find \/home\/ -name \"index\"<\/code>&nbsp;Find file names that begin with &#8218;index&#8216; in \/home folder<\/p>\n\n\n\n<p id=\"20a8\"><code>#find \/home -size +10000k<\/code>Find files greater than 10000k in the home folder<\/p>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"c653\">_File Transfer Commands<\/h1>\n\n\n\n<p id=\"21cf\"><code>#scp file1.txt server2\/tmp<\/code>&nbsp;Securely copy file1.txt to server2 in \/tmp directory<\/p>\n\n\n\n<p id=\"1aca\"><code>#rsync -a \/home\/apps \/backup\/<\/code>&nbsp;Synchronize contents in \/home\/apps directory with \/backup directory<\/p>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"99cf\">_Disk Usage Commands<\/h1>\n\n\n\n<p id=\"322f\"><code>#df -h<\/code>&nbsp;Displays free space on mounted systems<\/p>\n\n\n\n<p id=\"fb6e\"><code>#df -i<\/code>&nbsp;Displays free inodes on filesystems<\/p>\n\n\n\n<p id=\"25c4\"><code>#fdisk -l<\/code>&nbsp;Shows disk partitions, sizes, and types<\/p>\n\n\n\n<p id=\"ac55\"><code>#du -sh<\/code>&nbsp;Displays disk usage in the current directory in a human-readable format<\/p>\n\n\n\n<p id=\"2c60\"><code>#findmnt<\/code>&nbsp;Displays target mount point for all filesystems<\/p>\n\n\n\n<p id=\"e48e\"><code>#mount device-path mount-point<\/code>Mount a device<\/p>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"cb45\">_Directory Traverse Commands<\/h1>\n\n\n\n<p id=\"aee7\"><code>#cd ..<\/code>&nbsp;Move up one level in the directory tree structure<\/p>\n\n\n\n<p id=\"ee65\"><code>#cd<\/code>&nbsp;Change directory to $HOME directory<\/p>\n\n\n\n<p id=\"0b8b\">#cd \/test Change directory to \/test directory<\/p>\n","protected":false},"excerpt":{"rendered":"<p>_System Based Commands #uname\u00a0Displays Linux system information #uname -rDisplays kernel release information #uptimeDisplays how long the system has been running #hostnameShows the system hostname #hostname -iDisplays the IP address of the system #last rebootShows system reboot history #dateDisplays current system date and time #whoamiDisplays who you are logged in as #finger usernameDisplays information about the user _Hardware Based Command #lshw&nbsp;Displays information about system&#8217;s hardware configuration #lsblkDisplays block devices related information #free -mDisplays free and used memory in the system (-m indicates memory in MB) _Users Management Commands #idDisplays the details of the active user e.g. uid, gid, and groups #lastShows the last logins in the system #whoShows who is logged in to the system #groupadd &#8222;pink&#8220;Adds the group \u2018pink\u2019 #adduser &#8222;rajni&#8220;Adds user \u2018rajni\u2019 #userdel &#8222;rajni&#8220;Deletes user \u2018rajni\u2019 #usermodUsed for modifying user information _File Commands #ls -alLists files &#8211; both regular &amp; hidden files and their permissions #pwdDisplays the present working directory path mkdir &#8218;pink&#8217;Creates a new directory named \u2018pink\u2019 #rm file_nameRemoves a file #rm -f filenameForcefully removes a file #rm -r directory_nameRemoves a directory recursively #rm -rf directory_nameRemoves a directory forcefully and recursively #cp file1 file2Copies the contents of file1 to file2 #cp -r dir1 dir2Recursively Copies dir1 to dir2. dir2 is created if it does not exist #mv file1 file2Renames file1 to file2 #ln -s \/path\/to\/file_name link_nameCreates a symbolic link to file_name #touch file_nameCreates a new file #cat &gt; file_namePlaces standard input into a file #more file_nameOutputs the contents of a file #head file_nameDisplays the first 10 lines of a file #tail file_nameDisplays the last 10 lines of a file #gpg -c file_nameEncrypts a file #gpg file_name.gpgDecrypts a file #wcPrints the number of bytes, words and lines in a file #xargsExecutes commands from standard input _Process Related Commands #psDisplay currently active processes #ps aux | grep &#8218;telnet&#8217;Searches for the id of the process &#8218;telnet&#8216; #pmapDisplays memory map of processes #top&nbsp;Displays all running processes #kill pidTerminates process with a given pid #killall procKills \/ Terminates all processes named proc #pkill process-nameSends a signal to a process with its name #bgResumes suspended jobs in the background #fgBrings suspended jobs to the foreground #lsofLists files that are open by processes _File Permission Commands chmod octal filename&nbsp;Change file permissions of the file to octal Example #chmod 777 peep.txtSet rwx permissions to owner, group and everyone #chmod 755 peep.txt&nbsp;Set rwx to the owner and r_x to group and everyone #chmod 766 peep.txt&nbsp;Sets rwx for owner, rw for group and everyone #chown owner user-file&nbsp;Change ownership of the file #chown owner-user:owner-group file_name&nbsp;Change owner and group owner of the file #chown owner-user:owner-group directory&nbsp;Change owner and group owner of the directory _Network Commands #ip addr show&nbsp;Displays IP addresses and all the network interfaces #ip address add 192.160.0.1\/24 dev eth0&nbsp;Assigns IP address 192.168.0.1 to interface eth0 #ifconfig&nbsp;Displays IP addresses of all network interfaces #ping host&nbsp;ping command sends an ICMP echo request to establish a connection to server #whois domain&nbsp;Retrieves more information about a domain name #dig domain&nbsp;Retrieves DNS information about the domain #host google.com&nbsp;Performs an IP lookup for the domain name #hostname -i&nbsp;Displays local IP address #wget file_name&nbsp;Downloads a file from an online source #netstat -pnltu&nbsp;Displays all active listening ports _Compression\/Archives Commands #tar -cf peep.tar peep&lt;:code&gt;Creates archive file called &#8218;peep.tar&#8216; from file &#8218;peep&#8216; #tar -xf peep.tar&nbsp;Extract archive file &#8218;peep.tar&#8216; #tar -zcvf peep.tar.gz source-folder&nbsp;Creates gzipped tar archive file from the source folder #gzip file&nbsp;Compression a file with .gz extension _Install Packages Commands #rpm -i pkg_name.rpm&nbsp;Install an rpm package #rpm -e pkg_name&nbsp;Removes an rpm package #dnf install pkg_nameInstall package using dnf utility _Search Commands #grep &#8218;pattern&#8216; files&nbsp;Search for a given pattern in files #grep -r pattern dir&nbsp;Search recursively for a pattern in a given directory #locate file&nbsp;Find all instances of the file #find \/home\/ -name &#8222;index&#8220;&nbsp;Find file names that begin with &#8218;index&#8216; in \/home folder #find \/home -size +10000kFind files greater than 10000k in the home folder _File Transfer Commands #scp file1.txt server2\/tmp&nbsp;Securely copy file1.txt to server2 in \/tmp directory #rsync -a \/home\/apps \/backup\/&nbsp;Synchronize contents in \/home\/apps directory with \/backup directory _Disk Usage Commands #df -h&nbsp;Displays free space on mounted systems #df -i&nbsp;Displays free inodes on filesystems #fdisk -l&nbsp;Shows disk partitions, sizes, and types #du -sh&nbsp;Displays disk usage in the current directory in a human-readable format #findmnt&nbsp;Displays target mount point for all filesystems #mount device-path mount-pointMount a device _Directory Traverse Commands #cd ..&nbsp;Move up one level in the directory tree structure #cd&nbsp;Change directory to $HOME directory #cd \/test Change directory to \/test directory<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,1],"tags":[],"_links":{"self":[{"href":"https:\/\/raesch.ch\/index.php\/wp-json\/wp\/v2\/posts\/107"}],"collection":[{"href":"https:\/\/raesch.ch\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/raesch.ch\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/raesch.ch\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/raesch.ch\/index.php\/wp-json\/wp\/v2\/comments?post=107"}],"version-history":[{"count":2,"href":"https:\/\/raesch.ch\/index.php\/wp-json\/wp\/v2\/posts\/107\/revisions"}],"predecessor-version":[{"id":110,"href":"https:\/\/raesch.ch\/index.php\/wp-json\/wp\/v2\/posts\/107\/revisions\/110"}],"wp:attachment":[{"href":"https:\/\/raesch.ch\/index.php\/wp-json\/wp\/v2\/media?parent=107"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/raesch.ch\/index.php\/wp-json\/wp\/v2\/categories?post=107"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/raesch.ch\/index.php\/wp-json\/wp\/v2\/tags?post=107"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}