{"id":225,"date":"2013-06-05T03:15:10","date_gmt":"2013-06-04T21:45:10","guid":{"rendered":"http:\/\/sandeepmathew.wordpress.com\/?p=225"},"modified":"2013-06-05T03:15:10","modified_gmt":"2013-06-04T21:45:10","slug":"linux-bash-commonly-used-commands","status":"publish","type":"post","link":"https:\/\/sandeepmathew.com\/index.php\/2013\/06\/05\/linux-bash-commonly-used-commands\/","title":{"rendered":"Linux &#8211; bash ( commonly used commands )"},"content":{"rendered":"<p>I know no one really reads my blog , so here is again another note to myself on commonly used\u00a0 linux commands for the heck of it ! . Hopefully someones finds it useful . Hoping that writing this down refreshes my frail memory<\/p>\n<p><span style=\"text-decoration:underline;\">Getting help<\/span><\/p>\n<p>[sourcecode language=&#8221;bash&#8221;]<br \/>\n$ # try &#8211;help with the command<br \/>\n$ man &lt;command name&gt;<br \/>\n$ info &lt;command name&gt;<br \/>\n$ apropos &lt;command name&gt;<br \/>\n[\/sourcecode]<\/p>\n<p><span style=\"text-decoration:underline;\">Listing Directories<\/span><\/p>\n<p>[sourcecode language=&#8221;bash&#8221;]<br \/>\n$ls -a #lists all files<br \/>\n$ls -l #long listing<br \/>\n$ls -t # time<br \/>\n$ls -s # size<br \/>\n$ls -r # reverse<br \/>\n$ ls -ar # combination<br \/>\n[\/sourcecode]<\/p>\n<p><span style=\"text-decoration:underline;\">Changing Directories<\/span><\/p>\n<p>[sourcecode language=&#8221;bash&#8221;]<br \/>\n$pwd # returns the current directory<br \/>\n$cd  &lt;dirname&gt; # change directory to the given directory<br \/>\n[\/sourcecode]<\/p>\n<p><span style=\"text-decoration:underline;\">Copying files<\/span><\/p>\n<p>[sourcecode language=&#8221;bash&#8221;]<br \/>\n$cp<br \/>\n$cp -r   #recursive copy<br \/>\n$cp -i   #interactive<br \/>\n[\/sourcecode]<\/p>\n<p><span style=\"text-decoration:underline;\">Creating\/Removing directories<\/span><\/p>\n<p>[sourcecode language=&#8221;bash&#8221;]<br \/>\n$mkdir    #Creates<br \/>\n$rmdir    #Removes<br \/>\n[\/sourcecode]<\/p>\n<p><span style=\"text-decoration:underline;\">Displaying file contents<\/span><\/p>\n<p>[sourcecode language=&#8221;bash&#8221;]<br \/>\n$cat &lt;file1&gt; &lt;file2&gt; &lt;file3&gt;<br \/>\n$more &lt;file1&gt; &lt;file2&gt; &lt;file3&gt;<br \/>\n$less &lt;file1&gt; &lt;file2&gt;  &lt;file3&gt; # you do more with less !<br \/>\n$head -n  &lt;file&gt; # top n lines of the file<br \/>\n$tail -n &lt;file&gt; #bottom n lines of the file<br \/>\n[\/sourcecode]<\/p>\n<p><span style=\"text-decoration:underline;\">Pattern matching with grep<\/span><\/p>\n<p>[sourcecode language=&#8221;bash&#8221;]<br \/>\n$grep &lt;pattern&gt; &lt;files&gt;<br \/>\n$grep -i &lt;pattern&gt; &lt;files&gt; #case insensitive <\/p>\n<p>[\/sourcecode]<\/p>\n<p><span style=\"text-decoration:underline;\">Sorting<\/span><\/p>\n<p>[sourcecode language=&#8221;bash&#8221;]<br \/>\n$sort &lt;filename&gt;<br \/>\n$sort -r &lt;filename&gt; #sort in reverse<br \/>\n[\/sourcecode]<\/p>\n<p><span style=\"text-decoration:underline;\">Sed<\/span><\/p>\n<p>[sourcecode language=&#8221;bash&#8221;]<br \/>\n$# See : http:\/\/www.regular-expressions.info\/ , sed can be used to parsing text and performing various transformations<br \/>\n$sed &#8216;s\/&lt;pattern&gt;\/&lt;pattern to replace&gt; &lt;filename&gt;<br \/>\n$#man  sed<br \/>\n[\/sourcecode]<\/p>\n<p><span style=\"text-decoration:underline;\">Symbolic Links<\/span><\/p>\n<p>[sourcecode language=&#8221;bash&#8221;]<br \/>\n$ln -s &lt;filename&gt; &lt;link name&gt; #soft link , omit -s for hard links<br \/>\n[\/sourcecode]<\/p>\n<p><span style=\"text-decoration:underline;\">Changing Permissions<\/span><\/p>\n<p>[sourcecode language=&#8221;bash&#8221;]<br \/>\n$chmod &lt;permissions&gt; &lt;files&gt; #  permissions &#8211; a,b,c = r*4+w*2+x<\/p>\n<p>[\/sourcecode]<\/p>\n<p><span style=\"text-decoration:underline;\">Switch Users<\/span><\/p>\n<p>[sourcecode language=&#8221;bash&#8221;]<br \/>\n$su (switch user)<\/p>\n<p>[\/sourcecode]<\/p>\n<p><span style=\"text-decoration:underline;\">Tee send output to 2 devices<\/span><\/p>\n<p>[sourcecode language=&#8221;bash&#8221;]<br \/>\n$tee [a]  file<\/p>\n<p>[\/sourcecode]<\/p>\n<p><span style=\"text-decoration:underline;\">Fill standard output with same thing<\/span><\/p>\n<p>[sourcecode language=&#8221;bash&#8221;]<br \/>\n$yes &lt;string&gt; | &lt;command&gt;<\/p>\n<p>[\/sourcecode]<\/p>\n<p><span style=\"text-decoration:underline;\">Useful process control commands<\/span><\/p>\n<p>[sourcecode language=&#8221;bash&#8221;]<br \/>\n$jobs<br \/>\n$fg<br \/>\n$bg<br \/>\n$kill &lt;pid&gt;<br \/>\n$ps<\/p>\n<p>[\/sourcecode]<\/p>\n<p><span style=\"text-decoration:underline;\">Environment Variables<\/span><\/p>\n<p>[sourcecode language=&#8221;bash&#8221;]<br \/>\n$export varname = value<\/p>\n<p>[\/sourcecode]<\/p>\n<p><span style=\"text-decoration:underline;\">Shortcuts with alias<\/span><\/p>\n<p>[sourcecode language=&#8221;bash&#8221;]<br \/>\n$alias ls=&#8217;ls la&#8217;<\/p>\n<p>[\/sourcecode]<\/p>\n<p><span style=\"text-decoration:underline;\">which is the executable<\/span><\/p>\n<p>[sourcecode language=&#8221;bash&#8221;]<br \/>\n$which commandname<\/p>\n<p>[\/sourcecode]<\/p>\n<p><span style=\"text-decoration:underline;\">Disk utilities<\/span><\/p>\n<p>[sourcecode language=&#8221;bash&#8221;]<br \/>\n$du # disk usage<br \/>\n$df # disk free <\/p>\n<p>[\/sourcecode]<\/p>\n<p><span style=\"text-decoration:underline;\"> Compression utilities<\/span><\/p>\n<p>[sourcecode language=&#8221;bash&#8221;]<br \/>\n$gzip \/ gunzip<br \/>\n$tar<br \/>\n$bunzip2<br \/>\n$lzma \/ unlzma<\/p>\n<p>[\/sourcecode]<\/p>\n<p><span style=\"text-decoration:underline;\">Checking integrity<\/span><\/p>\n<p>[sourcecode language=&#8221;bash&#8221;]<br \/>\n$md5sum<\/p>\n<p>[\/sourcecode]<\/p>\n<p><span style=\"text-decoration:underline;\">File Comparison<\/span><\/p>\n<p>[sourcecode language=&#8221;bash&#8221;]<br \/>\n$diff<\/p>\n<p>[\/sourcecode]<\/p>\n<p><span style=\"text-decoration:underline;\">Location of files <\/span><\/p>\n<p>[sourcecode language=&#8221;bash&#8221;]<br \/>\n$find  &lt;path&gt;  -name &lt;name&gt;<br \/>\n$locate &lt;filename&gt;<\/p>\n<p>[\/sourcecode]<\/p>\n<p><span style=\"text-decoration:underline;\"> Downloading websites offline <\/span><\/p>\n<p>[sourcecode language=&#8221;bash&#8221;]<br \/>\n$wget<br \/>\n[\/sourcecode]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I know no one really reads my blog , so here is again another note to myself on commonly used\u00a0 linux commands for the heck of it ! . Hopefully someones finds it useful . Hoping that writing this down refreshes my frail memory Getting help [sourcecode language=&#8221;bash&#8221;] $ # try &#8211;help with the command [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[5],"tags":[],"_links":{"self":[{"href":"https:\/\/sandeepmathew.com\/index.php\/wp-json\/wp\/v2\/posts\/225"}],"collection":[{"href":"https:\/\/sandeepmathew.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sandeepmathew.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sandeepmathew.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sandeepmathew.com\/index.php\/wp-json\/wp\/v2\/comments?post=225"}],"version-history":[{"count":0,"href":"https:\/\/sandeepmathew.com\/index.php\/wp-json\/wp\/v2\/posts\/225\/revisions"}],"wp:attachment":[{"href":"https:\/\/sandeepmathew.com\/index.php\/wp-json\/wp\/v2\/media?parent=225"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sandeepmathew.com\/index.php\/wp-json\/wp\/v2\/categories?post=225"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sandeepmathew.com\/index.php\/wp-json\/wp\/v2\/tags?post=225"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}