{"id":11444,"date":"2019-03-14T07:44:28","date_gmt":"2019-03-14T07:44:28","guid":{"rendered":"http:\/\/www.appservgrid.com\/paw92\/?p=11444"},"modified":"2019-03-14T07:44:28","modified_gmt":"2019-03-14T07:44:28","slug":"5-interesting-command-line-tips-and-tricks-in-linux","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/14\/5-interesting-command-line-tips-and-tricks-in-linux\/","title":{"rendered":"5 Interesting Command Line Tips and Tricks in Linux"},"content":{"rendered":"<p>Are you making most out of the Linux? There are lots of helpful features which appears to be Tips and Tricks for many of Linux Users. Sometimes Tips and Tricks become the need. It helps you get productive with the same set of commands yet with enhanced functionality.<\/p>\n<div id=\"attachment_11992\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/03\/5-Command-Line-Tips.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-11992\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/03\/5-Command-Line-Tips-620x297.jpg\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/03\/5-Command-Line-Tips-620x297.jpg 620w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/03\/5-Command-Line-Tips.jpg 720w\" alt=\"5 Command Line Tips and Tricks\" width=\"620\" height=\"297\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">5 Command Line Tips and Tricks<\/p>\n<\/div>\n<p>Here we are starting a new series, where we will be writing some tips and tricks and will try to yield as more as we can in small time.<\/p>\n<p><strong>1.<\/strong>\u00a0To audit the commands we\u2019d run in past, we use\u00a0<a href=\"https:\/\/www.tecmint.com\/history-command-examples\/\" target=\"_blank\" rel=\"noopener\">history command<\/a>. Here is a sample output of history command.<\/p>\n<pre># history\r\n<\/pre>\n<div id=\"attachment_11979\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/03\/history-command.gif\"><img decoding=\"async\" class=\"size-medium wp-image-11979\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/03\/history-command.gif\" alt=\"Linux history Command Usage\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">history command example<\/p>\n<\/div>\n<p>Obvious from output, the history command do not output the time stamp with the log of last executed commands. Any solution for this? Yeah! Run the below command.<\/p>\n<pre># HISTTIMEFORMAT=\"%d\/%m\/%y %T \"\r\n# history\r\n<\/pre>\n<p><center>If you want to permanently append this change, add the below line to\u00a0<code>~\/.bashrc<\/code>.<\/center><\/p>\n<pre>export HISTTIMEFORMAT=\"%d\/%m\/%y %T \"\r\n<\/pre>\n<p>and then, from terminal run,<\/p>\n<pre># source ~\/.bashrc\r\n<\/pre>\n<p>Explanation of commands and switches.<\/p>\n<ol>\n<li><strong>history<\/strong>\u00a0\u2013 GNU History Library<\/li>\n<li><strong>HISTIMEFORMAT<\/strong>\u00a0\u2013 Environmental Variable<\/li>\n<li><strong>%d<\/strong>\u00a0\u2013 Day<\/li>\n<li><strong>%m<\/strong>\u00a0\u2013 Month<\/li>\n<li><strong>%y<\/strong>\u00a0\u2013 Year<\/li>\n<li><strong>%T<\/strong>\u00a0\u2013 Time Stamp<\/li>\n<li><strong>source<\/strong>\u00a0\u2013 in short send the contents of file to shell<\/li>\n<li><strong>.bashrc<\/strong>\u00a0\u2013 is a shell script that BASH runs whenever it is started interactively.<\/li>\n<\/ol>\n<div id=\"attachment_11982\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/03\/History-Command-Logs.gif\"><img decoding=\"async\" class=\"size-medium wp-image-11982\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/03\/History-Command-Logs.gif\" alt=\"history Command Logs\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">history Command Logs<\/p>\n<\/div>\n<p><strong>2.<\/strong>\u00a0The next gem in the list is \u2013 how to check disk write speed? Well one liner\u00a0<strong>dd<\/strong>\u00a0command script serves the purpose.<\/p>\n<pre># dd if=\/dev\/zero of=\/tmp\/output.img bs=8k count=256k conv=fdatasync; rm -rf \/tmp\/output.img\r\n<\/pre>\n<div id=\"attachment_11983\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/03\/dd-Command-Example.gif\"><img decoding=\"async\" class=\"size-medium wp-image-11983\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/03\/dd-Command-Example.gif\" alt=\"dd Command Example\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">dd Command Example<\/p>\n<\/div>\n<p>Explanation of commands and switches.<\/p>\n<ol>\n<li><b>dd\u00a0\u2013 Convert and Copy a file<\/b><\/li>\n<li><b>if=\/dev\/zero\u00a0\u2013 Read the file and not stdin<\/b><\/li>\n<li><strong>of=\/tmp\/output.img<\/strong>\u00a0\u2013 Write to file and not stdout<\/li>\n<li><strong>bs<\/strong>\u00a0\u2013 Read and Write maximum upto M bytes, at one time<\/li>\n<li><strong>count<\/strong>\u00a0\u2013 Copy N input block<\/li>\n<li><strong>conv<\/strong>\u00a0\u2013 Convert the file as per comma separated symbol list.<\/li>\n<li><strong>rm<\/strong>\u00a0\u2013 Removes files and folder<\/li>\n<li><strong>-rf<\/strong>\u00a0\u2013 (-r) removes directories and contents recursively and (-f) Force the removal without prompt.<\/li>\n<\/ol>\n<p><strong>3.<\/strong>\u00a0How will you check the top six files that are eating out your space? A simple one liner script made from\u00a0<a title=\"Check Disk Space Usage in Linux\" href=\"https:\/\/www.tecmint.com\/check-linux-disk-usage-of-files-and-directories\/\" target=\"_blank\" rel=\"noopener\">du command<\/a>, which is primarily used as file space usages.<\/p>\n<pre># du -hsx * | sort -rh | head -6\r\n<\/pre>\n<div id=\"attachment_11984\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/03\/check-disk-space-usage.gif\"><img decoding=\"async\" class=\"size-medium wp-image-11984\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/03\/check-disk-space-usage.gif\" alt=\"Check Disk Space Usage\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Check Disk Space Usage<\/p>\n<\/div>\n<p>Explanation of commands and switches.<\/p>\n<ol>\n<li><strong>du<\/strong>\u00a0\u2013 Estimate file space usages<\/li>\n<li><strong>-hsx<\/strong>\u00a0\u2013 (-h) Human Readable Format, (-s) Summaries Output, (-x) One File Format, skip directories on other file format.<\/li>\n<li><strong>sort<\/strong>\u00a0\u2013 Sort text file lines<\/li>\n<li><strong>-rh<\/strong>\u00a0\u2013 (-r) Reverse the result of comparison, (-h) for compare human readable format.<\/li>\n<li><strong>head<\/strong>\u00a0\u2013 output first n lines of file.<\/li>\n<\/ol>\n<p><strong>4.<\/strong>\u00a0The next step involves statistics in terminal of a file of every kind. We can output the statistics related to a file with the help of\u00a0<strong>stat<\/strong>\u00a0(output file\/fileSystem status) command.<\/p>\n<pre># stat filename_ext  (viz., stat abc.pdf)\r\n<\/pre>\n<div id=\"attachment_11985\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/03\/Check-File-Statistics.gif\"><img decoding=\"async\" class=\"size-medium wp-image-11985\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/03\/Check-File-Statistics.gif\" alt=\"Check File Statistics\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Check File Statistics<\/p>\n<\/div>\n<p><strong>5.<\/strong>\u00a0The next and last but not the least, this one line script is for those, who are newbies. If you are an experienced user you probably don\u2019t need it, unless you want some fun out of it. Well newbies are Linux-command-line phobic and the below one liner will generate random man pages. The benefit is as a newbie you always get something to learn and never get bored.<\/p>\n<pre># man $(ls \/bin | shuf | head -1)\r\n<\/pre>\n<div id=\"attachment_11986\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/03\/Generate-Random-Man-Pages.gif\"><img decoding=\"async\" class=\"size-medium wp-image-11986\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/03\/Generate-Random-Man-Pages.gif\" alt=\"Generate Random Man Pages\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Generate Random Man Pages<\/p>\n<\/div>\n<p>Explanation of commands and switches.<\/p>\n<ol>\n<li><strong>man<\/strong>\u00a0\u2013 Linux Man pages<\/li>\n<li><strong>ls<\/strong>\u00a0\u2013 Linux Listing Commands<\/li>\n<li><strong>\/bin<\/strong>\u00a0\u2013 System Binary file Location<\/li>\n<li><strong>shuf<\/strong>\u00a0\u2013 Generate Random Permutation<\/li>\n<li><strong>head<\/strong>\u00a0\u2013 Output first n line of file.<\/li>\n<\/ol>\n<p>That\u2019s all for now. If you know any such tips and tricks you may share with us and we will post the same in your words on our reputed Tecmint.com website.<\/p>\n<p>If you want to share any tips and tricks that you cannot make into article you may share it at tecmint[dot]com[at]gmail[dot]com and we will include it in our article. Don\u2019t forget to provide us with your valuable feedback in the comments below. Keep connected. Like and share us and help us get spread.<\/p>\n<p><strong>Don\u2019t Miss<\/strong>:<\/p>\n<ol>\n<li><a href=\"https:\/\/www.tecmint.com\/10-useful-linux-command-line-tricks-for-newbies\/\" target=\"_blank\" rel=\"noopener\">10 Useful Commandline Tricks for Newbies \u2013 Part 2<\/a><\/li>\n<li><a href=\"https:\/\/www.tecmint.com\/manage-file-types-and-set-system-time-in-linux\/\" target=\"_blank\" rel=\"noopener\">5 Useful Commands to Manage Linux File Types and System Time \u2013 Part 3<\/a><\/li>\n<\/ol>\n<p><a href=\"https:\/\/www.tecmint.com\/5-linux-command-line-tricks\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Are you making most out of the Linux? There are lots of helpful features which appears to be Tips and Tricks for many of Linux Users. Sometimes Tips and Tricks become the need. It helps you get productive with the same set of commands yet with enhanced functionality. 5 Command Line Tips and Tricks Here &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/14\/5-interesting-command-line-tips-and-tricks-in-linux\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;5 Interesting Command Line Tips and Tricks in Linux&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-11444","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/11444","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=11444"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/11444\/revisions"}],"predecessor-version":[{"id":11445,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/11444\/revisions\/11445"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=11444"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=11444"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=11444"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}