{"id":11366,"date":"2019-03-13T08:11:12","date_gmt":"2019-03-13T08:11:12","guid":{"rendered":"http:\/\/www.appservgrid.com\/paw92\/?p=11366"},"modified":"2019-03-13T08:11:12","modified_gmt":"2019-03-13T08:11:12","slug":"10-interesting-linux-command-line-tricks-and-tips-worth-knowing","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/13\/10-interesting-linux-command-line-tricks-and-tips-worth-knowing\/","title":{"rendered":"10 Interesting Linux Command Line Tricks and Tips Worth Knowing"},"content":{"rendered":"<p>I passionately enjoy working with commands as they offer more control over a Linux system than\u00a0<strong>GUIs<\/strong>(<strong>Graphical User Interfaces<\/strong>) applications, therefore am always on the look out to discover or figure out interesting ways and ideas to make\u00a0<a href=\"https:\/\/www.tecmint.com\/20-funny-commands-of-linux-or-linux-is-fun-in-terminal\/\" target=\"_blank\" rel=\"noopener\">Linux so easy and fun to operate<\/a>, primarily from the terminal.<\/p>\n<p>It is always thrilling when we discover\u00a0<a href=\"https:\/\/www.tecmint.com\/tag\/linux-tricks\/\" target=\"_blank\" rel=\"noopener\">new tricks or tips while using Linux<\/a>\u00a0especially a command line geek like myself.<\/p>\n<p><b>Suggested Read:<\/b>\u00a0<a href=\"https:\/\/www.tecmint.com\/5-linux-command-line-tricks\/\" target=\"_blank\" rel=\"noopener\">5 Interesting Command Line Tips and Tricks in Linux \u2013 Part 1<\/a><\/p>\n<p>And the feeling of wanting to share newly learned practices or commands with millions of Linux users out there, particularly the newbies who are still getting their way around this exciting operating system normally sets in.<\/p>\n<p><b>Suggested Read:<\/b>\u00a0<a href=\"https:\/\/www.tecmint.com\/10-useful-linux-command-line-tricks-for-newbies\/\" target=\"_blank\" rel=\"noopener\">10 Useful Linux Command Line Tricks for Newbies \u2013 Part 2<\/a><\/p>\n<p>In this article, we will review a number of\u00a0<a href=\"https:\/\/www.tecmint.com\/10-useful-linux-command-line-tricks-for-newbies\/\" target=\"_blank\" rel=\"noopener\">useful command line tricks and tips<\/a>\u00a0that can significantly enhance your Linux usage skills.<\/p>\n<h3>1. Lock or Hide a File or Directory in Linux<\/h3>\n<p>The simplest way of locking a file or directory is by using Linux file permissions. In case your the owner of a file or directory, you can block (remove read, write and execute privileges) other users and groups from accessing it as follows:<\/p>\n<pre>$ chmod 700 tecmint.info\r\nOR\r\n$ chmod go-rwx tecmint.info\r\n<\/pre>\n<p>To know more about Linux file permissions, read this article\u00a0<a href=\"https:\/\/www.tecmint.com\/manage-users-and-groups-in-linux\/\" target=\"_blank\" rel=\"noopener\">Managing Users &amp; Groups, File Permissions &amp; Attributes in Linux<\/a>.<\/p>\n<p>To hide the file\/directory from other system users, rename it with a\u00a0<code>(.)<\/code>\u00a0at the start of the file or directory:<\/p>\n<pre>$ mv filename .tecmint.info\r\n<\/pre>\n<h3>2. Translate rwx Permissions into Octal Format in Linux<\/h3>\n<p>By default, when you run the\u00a0<a href=\"https:\/\/www.tecmint.com\/tag\/linux-ls-command\/\" target=\"_blank\" rel=\"noopener\">ls command<\/a>, it displays file permissions in\u00a0<code>rwx<\/code>\u00a0format, but to understand the equivalence of this format and the octal format, you can learn how to\u00a0<a href=\"https:\/\/www.tecmint.com\/check-linux-file-octal-permissions-using-stat-command\/\" target=\"_blank\" rel=\"noopener\">translate rwx permissions into Octal format in Linux<\/a>.<\/p>\n<h3>3. How to Use \u2018su\u2019 When \u2018sudo\u2019 Fails<\/h3>\n<p>Although\u00a0<a href=\"https:\/\/www.tecmint.com\/su-vs-sudo-and-how-to-configure-sudo-in-linux\/\" target=\"_blank\" rel=\"noopener\">sudo command<\/a>\u00a0is used to execute commands with superuser privileges, there are moments when it fails to work as in the example below.<\/p>\n<p>Here, I want to\u00a0<a href=\"https:\/\/www.tecmint.com\/empty-delete-file-content-linux\/\" target=\"_blank\" rel=\"noopener\">empty the contents of a large file<\/a>\u00a0named\u00a0<code>uptime.log<\/code>\u00a0but the operation has failed even when I used\u00a0<strong>sudo<\/strong>.<\/p>\n<pre>$ cat \/dev\/null &gt;\/var\/log\/uptime.log \r\n$ sudo cat \/dev\/null &gt;\/var\/log\/uptime.log\r\n<\/pre>\n<div id=\"attachment_23979\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/12\/Empty-Large-File-Content-in-Linux.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-23979\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/12\/Empty-Large-File-Content-in-Linux.png\" alt=\"Empty Large File Content in Linux\" width=\"630\" height=\"97\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Empty Large File Content in Linux<\/p>\n<\/div>\n<p>In such as case, you need to switch to the\u00a0<strong>root<\/strong>\u00a0user account using\u00a0<strong>su<\/strong>\u00a0command to perform the operation like so:<\/p>\n<pre>$ su\r\n$ sudo cat \/dev\/null &gt;\/var\/log\/uptime.log\r\n$ cat \/var\/log\/uptime.log\r\n<\/pre>\n<div id=\"attachment_23980\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/12\/Switch-to-Super-User.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-23980\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/12\/Switch-to-Super-User.png\" alt=\"Switch to Super User\" width=\"626\" height=\"134\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Switch to Super User<\/p>\n<\/div>\n<p>Try to understand the\u00a0<a href=\"https:\/\/www.tecmint.com\/su-vs-sudo-and-how-to-configure-sudo-in-linux\/\" target=\"_blank\" rel=\"noopener\">difference between su and sudo<\/a>, in addition, read through their man pages for more guidelines:<\/p>\n<pre>$ man sudo\r\n$ man su\r\n<\/pre>\n<h3>4. Kill a Process in Linux<\/h3>\n<p>Sometimes when you want to\u00a0<a href=\"https:\/\/www.tecmint.com\/how-to-kill-a-process-in-linux\/\" target=\"_blank\" rel=\"noopener\">terminate a process using kill or killall or pkill<\/a>\u00a0commands, it may fail to work, you realize that the process still continues to run on the system.<\/p>\n<p>In order to destructively kill a process, send the\u00a0<code>-KILL<\/code>\u00a0siganl to it.<\/p>\n<p>First\u00a0<a href=\"https:\/\/www.tecmint.com\/find-process-name-pid-number-linux\/\" target=\"_blank\" rel=\"noopener\">determine its process ID<\/a>\u00a0and then kill it like so:<\/p>\n<pre>$ pidof vlc\r\n$ sudo kill -KILL 10279\r\n<\/pre>\n<div id=\"attachment_23981\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/12\/Find-and-Kill-Process-in-Linux.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-23981\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/12\/Find-and-Kill-Process-in-Linux.png\" alt=\"Find and Kill Process in Linux\" width=\"452\" height=\"97\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Find and Kill Process in Linux<\/p>\n<\/div>\n<p>Check the\u00a0<a href=\"https:\/\/www.tecmint.com\/how-to-kill-a-process-in-linux\/\" target=\"_blank\" rel=\"noopener\">kill command<\/a>\u00a0for additional usage options and information.<\/p>\n<h3>5. Delete File Permanently in Linux<\/h3>\n<p>Normally, we use the\u00a0<strong>rm command<\/strong>\u00a0to delete files from a Linux system, however, these files do not completely get deleted, they are simply stored and hidden on the hard disk and can still be\u00a0<a href=\"https:\/\/www.tecmint.com\/recover-deleted-file-in-linux\/\" target=\"_blank\" rel=\"noopener\">recovered these files in Linux<\/a>and viewed by another person.<\/p>\n<p>To prevent this, we can use the\u00a0<strong>shred command<\/strong>\u00a0which overwrites the file content and optionally deletes the file as well.<\/p>\n<pre>$ shred -zvu tecmint.pdf\r\n<\/pre>\n<p>The options used in the above command:<\/p>\n<ol>\n<li><code>-z<\/code>\u00a0\u2013 adds a final overwrite with zeros to hide shredding.<\/li>\n<li><code>-u<\/code>\u00a0\u2013 helps to truncate and remove file after overwriting.<\/li>\n<li><code>-v<\/code>\u00a0\u2013 shows progress.<\/li>\n<\/ol>\n<div id=\"attachment_23982\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/12\/Delete-File-Permanently-in-Linux.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-23982\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/12\/Delete-File-Permanently-in-Linux.png\" alt=\"Delete File Permanently in Linux\" width=\"512\" height=\"363\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Delete File Permanently in Linux<\/p>\n<\/div>\n<p>Read through shred man page for additional usage instructions:<\/p>\n<pre>$ man shred<\/pre>\n<h3>6. Rename Multiple Files in Linux<\/h3>\n<p>You can\u00a0<a href=\"https:\/\/www.tecmint.com\/rename-multiple-files-in-linux\/\" target=\"_blank\" rel=\"noopener\">rename multiple files in Linux<\/a>\u00a0on the go by invoking the\u00a0<strong>rename<\/strong>\u00a0command.<\/p>\n<p>It renames the filenames supplied according to a rule specified in the first argument.<\/p>\n<p>The command below renames all\u00a0<code>.pdf<\/code>\u00a0files to\u00a0<code>.doc<\/code>, here\u00a0<code>'s\/\\.pdf$\/\\.doc\/'<\/code>\u00a0is the rule:<\/p>\n<pre>$ rename -v 's\/\\.pdf$\/\\.doc\/' *.pdf\r\n<\/pre>\n<div id=\"attachment_23983\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/12\/Rename-Multiple-Files-in-Linux.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-23983\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/12\/Rename-Multiple-Files-in-Linux.png\" alt=\"Rename Multiple Files in Linux\" width=\"609\" height=\"135\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Rename Multiple Files in Linux<\/p>\n<\/div>\n<p>The next example renames all files matching\u00a0<code>\"*.bak\"<\/code>\u00a0to strip the extension, where\u00a0<code>'s\/\\e.bak$\/\/'<\/code>\u00a0is the rule:<\/p>\n<p>&nbsp;<\/p>\n<h3>7. Check for Spelling of Words in Linux<\/h3>\n<p>The\u00a0<strong>look command<\/strong>\u00a0displays lines beginning with a given string, it can help you to check for the spelling of word from within the command line. Although it is not so effective and reliable,\u00a0<strong>look<\/strong>\u00a0is still a useful alternative to other powerful spelling-checkers:<\/p>\n<pre>$ look linu\r\n$ look docum\r\n<\/pre>\n<div id=\"attachment_23984\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/12\/Spell-Checking-in-Linux.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-23984\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/12\/Spell-Checking-in-Linux.png\" alt=\"Spell Checking in Linux\" width=\"369\" height=\"306\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Spell Checking in Linux<\/p>\n<\/div>\n<h3>8. Search for Description of Keyword in Manual Page<\/h3>\n<p>The\u00a0<strong>man command<\/strong>\u00a0is used to display manual entry pages of commands, when used with the\u00a0<code>-k<\/code>\u00a0switch, it searches the short descriptions and manual page names for the keyword\u00a0<code>printf<\/code>\u00a0(such as adjust, apache and php in the commands below) as regular expression.<\/p>\n<pre>$ man -k adjust\r\n$ man -k apache\r\n$ man -k php\r\n<\/pre>\n<div id=\"attachment_23985\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/12\/Show-Description-of-Keyword-in-Manual-Pages.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-23985\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/12\/Show-Description-of-Keyword-in-Manual-Pages.png\" sizes=\"auto, (max-width: 781px) 100vw, 781px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/12\/Show-Description-of-Keyword-in-Manual-Pages.png 781w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/12\/Show-Description-of-Keyword-in-Manual-Pages-768x600.png 768w\" alt=\"Show Description of Keyword in Manual Pages\" width=\"781\" height=\"610\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Show Description of Keyword in Manual Pages<\/p>\n<\/div>\n<h3>9. Watch Logs in Real-Time in Linux<\/h3>\n<p>With\u00a0<strong>watch command<\/strong>, you can run\u00a0<a href=\"https:\/\/www.tecmint.com\/run-repeat-linux-command-every-x-seconds\/\" target=\"_blank\" rel=\"noopener\">another Linux command periodically<\/a>\u00a0while displaying its output on fullscreen and alongside\u00a0<a href=\"https:\/\/www.tecmint.com\/view-contents-of-file-in-linux\/\" target=\"_blank\" rel=\"noopener\">tail command<\/a>\u00a0which is used to view the last parts of a file, it is possible to watch the recording of log entries in a logfile.<\/p>\n<p>In the example below, you will watch the system authentication logfile. Open two terminal windows, display the logfile for watching in real-time in the first window like so:<\/p>\n<pre>$ sudo watch tail \/var\/log\/auth.log\r\n<\/pre>\n<p>You can also use\u00a0<a href=\"https:\/\/www.tecmint.com\/view-contents-of-file-in-linux\/\" target=\"_blank\" rel=\"noopener\">tail command<\/a>\u00a0which shows the last parts of a file. Its\u00a0<code>-f<\/code>\u00a0flag enables watching changes in a file in real-time, therefore it is possible to watch the recording of log entries in a logfile.<\/p>\n<pre>$ sudo tail -f \/var\/log\/auth.log\r\n<\/pre>\n<p>And run the commands below in the second terminal as you observe the logfile content from the first window:<\/p>\n<pre>$ sudo mkdir -p \/etc\/test\r\n$ sudo rm -rf \/etc\/test\r\n<\/pre>\n<h3>10. List All Shell builtin Commands<\/h3>\n<p>A\u00a0<strong>shell builtin<\/strong>\u00a0is a command or a function, called from within and executed directly in the shell itself, instead of an external executable program which the shell would load from the hard disk and execute.<\/p>\n<p>To list all shell builtins and their usage syntax, run:<\/p>\n<pre>$ help\r\n<\/pre>\n<p>As a concluding remark,\u00a0<a href=\"https:\/\/www.tecmint.com\/tag\/linux-tricks\/\" target=\"_blank\" rel=\"noopener\">command line tricks and tips<\/a>\u00a0always come in handy and make learning and using Linux easy and fun especially for newbies.<\/p>\n<p>You can as well share with us other\u00a0<a href=\"https:\/\/www.tecmint.com\/5-linux-command-line-tricks\/\" target=\"_blank\" rel=\"noopener\">useful and interesting command line tricks or tips<\/a>\u00a0in Linux that you have come across via the comment form below.<\/p>\n<p><a href=\"https:\/\/www.tecmint.com\/linux-command-line-tricks-and-tips-worth-knowing\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I passionately enjoy working with commands as they offer more control over a Linux system than\u00a0GUIs(Graphical User Interfaces) applications, therefore am always on the look out to discover or figure out interesting ways and ideas to make\u00a0Linux so easy and fun to operate, primarily from the terminal. It is always thrilling when we discover\u00a0new tricks &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/13\/10-interesting-linux-command-line-tricks-and-tips-worth-knowing\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;10 Interesting Linux Command Line Tricks and Tips Worth Knowing&#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-11366","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\/11366","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=11366"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/11366\/revisions"}],"predecessor-version":[{"id":11367,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/11366\/revisions\/11367"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=11366"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=11366"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=11366"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}