{"id":1106,"date":"2022-10-26T15:55:49","date_gmt":"2022-10-26T09:55:49","guid":{"rendered":"https:\/\/staging.arifbillah.com\/new\/?p=1106"},"modified":"2022-10-26T15:55:49","modified_gmt":"2022-10-26T09:55:49","slug":"linux-most-common-script","status":"publish","type":"post","link":"https:\/\/arifbillah.com\/?p=1106","title":{"rendered":"Linux most common script."},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Bash Related Commands<br \/>Clear the terminal<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">clear \/ ctrl + l<br \/>Close the terminal<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">exit \/ ctrl + d<br \/>Reset the terminal<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">reset<br \/>Stop any program<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">ctrl + c<br \/>Sleep any program<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">ctrl + z<br \/>Check the history<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">ctrl + r \/ history<br \/>Check last 30 commands<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">history | tail -30<br \/>Autocomplete Filename or Folder name<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Tab<br \/>Autocomplete command<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Tab twice<br \/>Autocomplete command with options<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Tab three times<br \/>System Related Commands<br \/>Dabian Based Systems<br \/>Update the system<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">sudo apt update<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">for some older packages<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">sudo apt-get update<br \/>Upgrade the system<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">sudo apt upgrade<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">for some older packages<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">sudo apt-get upgrade<br \/>Install a package<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">sudo apt install package_name<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">for some older packages<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">sudo apt-get install package_name<br \/>Remove a package<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">sudo apt remove package_name<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">for some older packages<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">sudo apt-get remove package_name<br \/>Remove a package and its dependencies<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">sudo apt autoremove package_name<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">for some older packages<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">sudo apt autoremove package_name<br \/>Search for a package<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">apt search package_name<br \/>List all installed packages<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">apt list &#8211;installed<br \/>List all available packages<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">apt list<br \/>List all available packages with version<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">apt list &#8211;all-versions<br \/>Arch Based Systems<br \/>Update the system<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">sudo pacman -Syyu<br \/>Install a package<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">sudo pacman -S package_name<br \/>Remove a package<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">sudo pacman -R package_name<br \/>Search for a package<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">pacman -Ss package_name<br \/>List all installed packages<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">pacman -Q<br \/>List all available packages<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">pacman -Ss<br \/>More to come<br \/>Check the internet is working<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">ping google.com<br \/>Check System and Kernel version<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">uname -a<br \/>Check System version<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">cat \/etc\/os-release<br \/>Check Kernel<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">uname -r<br \/>Check hostname<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">hostname<br \/>Check IP address<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">ip addr<br \/>Check IP address (short)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">ip a<br \/>Check IP address (long)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">ip address<br \/>See user logged in<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">who<br \/>See username<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">whoami<br \/>Short information of logged in user<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">users<br \/>See all users<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">cat \/etc\/passwd<br \/>See all groups<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">cat \/etc\/group<br \/>See all groups of a user<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">groups username<br \/>See all users of a group<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">getent group groupname<br \/>Reboot the system<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">sudo reboot<br \/>Shutdown the system<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">sudo shutdown -h now \/ sudo poweroff \/ sudo halt \/ sudo init 0 \/ sudo systemctl poweroff<br \/>Check the current date and time<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">date<br \/>Check the current user<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">whoami<br \/>Check the current user&#8217;s home directory<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">echo $HOME<br \/>Check the current user&#8217;s shell<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">echo $SHELL<br \/>Check the current user&#8217;s path \/ executable paths of system<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">echo $PATH<br \/>Check the current user&#8217;s environment variables<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">env<br \/>Check the current user&#8217;s environment variables with values<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">env | grep -i &#8220;variable_name&#8221;<br \/>Check the current user&#8217;s environment variables with values in a file<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">env &gt; env.txt<br \/>Check the current user&#8217;s environment variables with values in a file with root access<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">sudo env &gt; env.txt<br \/>See the top 10 processes<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">top<br \/>See the top 10 processes with root access and sorted by memory usage<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">sudo top -o %MEM<br \/>See the top 10 processes with root access and sorted by cpu usage<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">sudo top -o %CPU<br \/>See the top 10 processes with root access and sorted by cpu usage and memory usage<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">sudo top -o %CPU,%MEM<br \/>See the top 10 processes with root access and sorted by cpu usage and memory usage and show only the process id and the process name<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">sudo top -o %CPU,%MEM -p -c<br \/>See the current running processes<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">ps<br \/>See the current running processes in a tree format<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">pstree<br \/>Kill a specific process<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">killall ProcessName<br \/>See the system uptime<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">uptime<br \/>See the system uptime in a specific format<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">uptime -p<br \/>See the system monitor<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">htop<br \/>See the system monitor with root access and sorted by memory usage<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">sudo htop -o %MEM<br \/>See the system monitor with root access and sorted by cpu usage<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">sudo htop -o %CPU<br \/>See the system monitor with root access and sorted by cpu usage and memory usage<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">sudo htop -o %CPU,%MEM<br \/>See the system monitor with root access and sorted by cpu usage and memory usage and show only the process id and the process name<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">sudo htop -o %CPU,%MEM -p -c<br \/>See the system monitor with root access and sorted by cpu usage and memory usage and show only the process id and the process name and show the process tree<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">sudo htop -o %CPU,%MEM -p -c -t<br \/>Hardware Related Commands<br \/>See the system&#8217;s hardware information<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">sudo lshw<br \/>See the system&#8217;s hardware information in a specific format<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">sudo lshw -short<br \/>See the system&#8217;s hardware information in a specific format and show only the network devices<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">sudo lshw -short -C network<br \/>See the system&#8217;s hardware information in a specific format and show only the network devices and show the network devices in a tree format<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">sudo lshw -short -C network -class network -tree<br \/>Check the system&#8217;s memory usage<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">free -h<br \/>Check CPU information<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">lscpu<br \/>Check Memory information<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">sudo dmidecode -t memory<br \/>Check Disk information<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">sudo dmidecode -t memory<br \/>Check USB information<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">lsusb<br \/>Check PCI information<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">lspci<br \/>Check Partitions<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">lsblk<br \/>Check Partitions with root access<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">sudo lsblk<br \/>Check Partitions with root access and show only the partitions<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">sudo lsblk -p<br \/>Check Partitions with root access and show only the partitions and show the partitions in a tree format<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">sudo lsblk -p -t<br \/>Mount a partition<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">sudo mount \/dev\/sda1 \/mnt<br \/>Unmount a partition<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">sudo umount \/dev\/sda1<br \/>Mount a partition with root access and show only the partitions and show the partitions in a tree format<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">sudo lsblk -p -t<br \/>Read Write Mount a partition<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">sudo mount -o rw \/dev\/sda1 \/mnt<br \/>File \/ Directory Related Commands<br \/>Create a new directory<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">mkdir directory-name<br \/>Create a new file<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">touch file-name<br \/>Create multiple directories at a time<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">mkdir dir1 dir2 dir3 dir4 dir5<br \/>Create multiple files at a time<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">touch index.html style.css script.js<br \/>Delete a directory with all it&#8217;s child<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">rm -rf directory-name<br \/>Delete a file<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">rm filename<br \/>List down all the files and directories<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">ls<br \/>List down all the files and directories with all the details<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">ls -l<br \/>List down all the files and directories with all the details and hidden files<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">ls -la<br \/>List down all the files and directories with all the details and hidden files and sort by size<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">ls -lS<br \/>List down all the files and directories with all the details and hidden files and sort by time<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">ls -lt<br \/>List down all the files and directories with all the details and hidden files and sort by time and reverse<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">ls -ltr<br \/>List down all the files and directories with all the details and hidden files and sort by time and reverse and show only 10 files<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">ls -ltr | head -10<br \/>Open a file<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">cat filename<br \/>Open a file with line numbers<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">cat -n filename<br \/>Open a file with line numbers and show only 10 lines<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">cat -n filename | head -10<br \/>Open a file using vim<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">vim filename<br \/>Open a file using vim and show only 10 lines<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">vim +10 filename<br \/>Open a file using nano<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">nano filename<br \/>Open a file using nano and show only 10 lines<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">nano +10 filename<br \/>Open a file using gedit<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">gedit filename<br \/>Count the number of lines in a file<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">wc -l filename<br \/>Print the current working directory<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">pwd<br \/>Change the current working directory<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">cd directory-name<br \/>Change the current working directory to the home directory<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">cd ~<br \/>Change the current working directory to the parent directory<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">cd ..<br \/>Change the current working directory to the root directory<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">cd \/<br \/>Copy a file<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">cp filename newfilename<br \/>Copy a file to a directory<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">cp filename directory-name<br \/>Copy a directory<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">cp -r directory-name newdirectory-name<br \/>Copy a directory to a directory<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">cp -r directory-name directory-name<br \/>Move a file<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">mv filename newfilename<br \/>Move a file to a directory<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">mv filename directory-name<br \/>Move a directory<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">mv -r directory-name newdirectory-name<br \/>Move a directory to a directory<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">mv -r directory-name directory-name<br \/>Rename a file<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">mv filename newfilename<br \/>Rename a directory<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">mv directory-name newdirectory-name<br \/>Create a symbolic link<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">ln -s filename linkname<br \/>Create a hard link<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">ln filename linkname<br \/>Create a hard link to a directory<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">ln -r directory-name linkname<br \/>Create a symbolic link to a directory<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">ln -sr directory-name linkname<br \/>Create a file with content<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">echo &#8220;Hello World&#8221; &gt; filename<br \/>Append content to a file<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">echo &#8220;Hello World&#8221; &gt;&gt; filename<br \/>Create a file with content and open it using vim<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">echo &#8220;Hello World&#8221; &gt; filename &amp;&amp; vim filename<br \/>Create a file with content and open it using nano<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">echo &#8220;Hello World&#8221; &gt; filename &amp;&amp; nano filename<br \/>Create a file with content and open it using gedit<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">echo &#8220;Hello World&#8221; &gt; filename &amp;&amp; gedit filename<br \/>Create a file with content and open it using cat<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">echo &#8220;Hello World&#8221; &gt; filename &amp;&amp; cat filename<br \/>Create a .tar file<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">tar -cvf filename.tar directory-name<br \/>Create a .tar.gz file<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">tar -cvzf filename.tar.gz directory-name<br \/>Create a .zip file<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">zip -r filename.zip directory-name<br \/>Extract a .tar file<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">tar -xvf filename.tar<br \/>Extract a .tar.gz file<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">tar -xvzf filename.tar.gz<br \/>Extract a .zip file<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">unzip filename.zip<br \/>Find a file<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">find . -name filename<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Bash Related CommandsClear the terminal clear \/ ctrl + lClose the terminal exit \/ ctrl + dReset the terminal resetStop any program ctrl + cSleep any program ctrl + zCheck the history ctrl + r \/ historyCheck last 30 commands history | tail -30Autocomplete Filename or Folder name TabAutocomplete command Tab twiceAutocomplete command with options [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":3168,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[119],"tags":[],"class_list":["post-1106","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-website"],"_links":{"self":[{"href":"https:\/\/arifbillah.com\/index.php?rest_route=\/wp\/v2\/posts\/1106","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/arifbillah.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/arifbillah.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/arifbillah.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/arifbillah.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1106"}],"version-history":[{"count":0,"href":"https:\/\/arifbillah.com\/index.php?rest_route=\/wp\/v2\/posts\/1106\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/arifbillah.com\/index.php?rest_route=\/wp\/v2\/media\/3168"}],"wp:attachment":[{"href":"https:\/\/arifbillah.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1106"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/arifbillah.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1106"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/arifbillah.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1106"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}