{"id":274,"date":"2007-02-27T06:16:00","date_gmt":"2007-02-27T13:16:00","guid":{"rendered":"http:\/\/www.elbeno.com\/blog\/?p=274"},"modified":"2007-07-29T12:41:25","modified_gmt":"2007-07-29T19:41:25","slug":"some-linuxunix-commands-worth-knowing","status":"publish","type":"post","link":"https:\/\/www.elbeno.com\/blog\/?p=274","title":{"rendered":"Some Linux\/Unix commands worth knowing&#8230;"},"content":{"rendered":"<p>It seems like not a day goes by when I don&#8217;t run across someone&#8217;s blog listing &#8220;top 10 Linux commands you must know&#8221; or something like it. I get the feeling these are mostly posted by people who switched to Linux recently and want to share the experience. I switched to Linux 12 years ago, so here&#8217;s my version of &#8220;some Linux (or really Unix&#8230;) commands worth knowing&#8221;. I&#8217;m not going to be more specific than that. They are in approximate order of increasing skill\/knowledge\/foolhardiness.<\/p>\n<ul>\n<li><em>ls -al<\/em><br \/>\nWe all know that ls is the command to list files in a directory. The -l option gives you details, and the -a option lists the &#8220;hidden&#8221; files that begin with . (period). So <em>ls -al<\/em> is the standard &#8220;power version&#8221; of <em>ls<\/em>.<\/li>\n<li><em>mv\/cp\/rm<\/em><br \/>\nMove, copy, remove files and directories. Move is also used to rename.<\/li>\n<li><em>&lt;command&gt; &#8211;help<\/em><br \/>\nPutting <em>&#8211;help<\/em> after a command usually tells you what arguments it takes. This is something I really really miss when having to use Windows. You can also try <em>-?<\/em> or <em>-h<\/em> (or simply nothing). If that fails, try <em>man &lt;command&gt;<\/em>.<\/li>\n<li><em>find \/ -iname &lt;filename&gt;<\/em><br \/>\nThe equivalent of Windows&#8217; directory search &#8211; but without the world&#8217;s worst UI. Running it with \/ (root directory) as the second parameter is liable to spit out some errors because (unless you are root, which you shouldn&#8217;t ordinarily be) you won&#8217;t be able to read some directories. <em>-iname<\/em> is probably the most useful option for the newbie &#8211; it means do a case-insensitive name match.<\/li>\n<li><em>vi<\/em><br \/>\nYou should know just enough to get by, although these days any distro is likely to have <em>nano<\/em> or something friendlier than <em>vi<\/em> anyway. You can get by pretty well just knowing: i to start &#8220;editing mode&#8221; (insert), x to delete a character, dd to delete a line, ESC to stop editing and enter &#8220;command mode&#8221; again, :q! to quit without saving, ZZ to save and quit.<\/li>\n<li><em>chmod<\/em><br \/>\nA vital command for mucking about with files. 90% of the time you will want <em>chmod 755 &lt;file&gt;<\/em> and 9.9% of the time you&#8217;ll want <em>chmod 644 &lt;file&gt;<\/em>. The first makes a file executable, the second makes it &#8220;normal&#8221; (usually to be used if it came from a bizarre place like a Windows filesystem).<\/li>\n<li><em>grep<\/em><br \/>\nA bit overrated. In the sense that one doesn&#8217;t often need it as a new user. But the real reason it&#8217;s one of the standard tutorial things is that what you really need to know are regexps (regular expressions). Grep can be viewed really just as a way to get familiar with regexps. Learn them and love them.<\/li>\n<li><em>less<\/em><br \/>\nForget <em>cat<\/em> and <em>more<\/em> &#8211; for reading text files, just use <em>less<\/em>. <em>Cat<\/em> and <em>more<\/em> you can learn later when you want to do other stuff besides just read files.<\/li>\n<li><em>ps aux | grep &lt;name&gt;<\/em> and <em>kill<\/em><br \/>\nUseful for when things go wrong. Find a rogue process with <em>ps<\/em>. Kill it with <em>kill<\/em>. Job done.<\/li>\n<li>Ctrl-Z and <em>bg<\/em><br \/>\nForgot to add the &amp; on the end of a command and your command prompt didn&#8217;t come back? No worries &#8211; hit Ctrl-Z and type <em>bg<\/em> and Bob&#8217;s your uncle.<\/li>\n<li><em>kill -HUP<\/em><br \/>\nUseful for restarting a process and\/or having it re-read the config files. A good example is when for whatever reason, X fails to start and you are left at a text prompt. So (using your minimal vi knowledge) you quite happily fix up your X config file, but then what? If you are a newbie, chances are you reboot (that being the only way you know to restart X). But probably all you need to do is something like <em>ps aux | grep gdm<\/em> followed by <em>kill -HUP<\/em>. And you&#8217;re back at a nice graphical login.<\/li>\n<li><em>tar -zxvf &lt;file&gt;<\/em><br \/>\nThe standard way to unpack a tarred and gzipped file. The options are: z for zipped, x for extract, v for view (you can leave this out if you like) and f for you guessed it, file. You can also use <em>-jxvf<\/em> if the file is bzipped rather than gzipped.<\/li>\n<\/ul>\n<p>That&#8217;s a good set of standards to get oneself up and running as a newbie. On the hairier side of things, some other useful commands to know are:<\/p>\n<ul>\n<li><em>lsmod<\/em> and <em>modprobe<\/em><br \/>\nFor listing and loading kernel modules.<\/li>\n<li><em>lspci<\/em> and <em>lsusb<\/em><br \/>\nFor inspecting your hardware.<\/li>\n<li><em>dmesg<\/em><br \/>\nFor seeing what went wrong when you just plugged in your iPod.<\/li>\n<li><em>lsof<\/em> and <em>dd<\/em><br \/>\nGiven that practically everything in Unix is abstracted as a file, there is almost nothing you can&#8217;t do with the combination of these two absurdly powerful tools.<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>It seems like not a day goes by when I don&#8217;t run across someone&#8217;s blog listing &#8220;top 10 Linux commands you must know&#8221; or something like it. I get the feeling these are mostly posted by people who switched to Linux recently and want to share the experience. I switched&#8230;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-274","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.elbeno.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/274","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.elbeno.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.elbeno.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.elbeno.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.elbeno.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=274"}],"version-history":[{"count":0,"href":"https:\/\/www.elbeno.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/274\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.elbeno.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=274"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.elbeno.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=274"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.elbeno.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=274"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}