{"id":812,"date":"2013-01-26T18:15:59","date_gmt":"2013-01-26T22:15:59","guid":{"rendered":"http:\/\/www.timelordz.com\/blog\/?p=812"},"modified":"2013-01-26T18:17:54","modified_gmt":"2013-01-26T22:17:54","slug":"lslt-bash-function","status":"publish","type":"post","link":"https:\/\/www.timelordz.com\/blog\/2013\/01\/lslt-bash-function\/","title":{"rendered":"lslt Bash Function"},"content":{"rendered":"<p>I&#8217;m always typing: ls -lhatr | tail<\/p>\n<p>I decided this was getting old. &#8216;Alias&#8217; was not going to really do what I wanted, so I made a little bash function instead, which can be put in your .bashrc, etc. Simple &#8211; but handy. And (of course) maintains colors.<\/p>\n<p>The full script version :<\/p>\n<pre lang=\"BASH\" line=\"1\" file=\"lslt.sh\" colla=\"+\">\r\n#!\/bin\/bash\r\n# List the last N items in specified directory in\r\n# reverse time order (newest on bottom).\r\n#\r\n# Note however, the 'alias' commanad alone will not correctly handle args.\r\n\r\nif [ $# -lt 1 ]\r\nthen\r\n        echo \"Usage: $0 \/foo N (optional)\"\r\n        echo \"Will perform ls -lhatr | tail -N\"\r\n        exit 1  \r\nfi\r\n\r\ndir=$1\r\necho \"Listing $dir . . . \"\r\nls -lhatr --color=always $dir | tail -$2\r\n<\/pre>\n<p>But you can achieve the same thing with a bash function, perhaps in your ~\/.bashrc e.g.:<\/p>\n<pre lang=\"BASH\" line=\"1\" file=\"lsltFunction.sh\" colla=\"+\">\r\n# lslt () { command ls -lhatr --color=always \"$1\" | tail -\"$2\"; }\r\n#\r\n# Or even fancier . . .\r\n\r\nlslt () {\r\nif [ $# -lt 1 ]\r\nthen\r\n        #type lslt \/\/Works, but a nicer way is . . .\r\n        echo \"Usage: lslt \/foo N (optional)\"\r\n        echo \"Will perform ls -lhatr | tail -N\"\r\nelse\r\n        command ls -lhatr --color=always \"$1\" | tail -\"$2\";\r\nfi\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;m always typing: ls -lhatr | tail I decided this was getting old. &#8216;Alias&#8217; was not going to really do what I wanted, so I made a little bash function instead, which can be put in your .bashrc, etc. Simple &#8211; but handy. And (of course) maintains colors. The full script version : #!\/bin\/bash # [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"class_list":["post-812","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.timelordz.com\/blog\/wp-json\/wp\/v2\/posts\/812","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.timelordz.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.timelordz.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.timelordz.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.timelordz.com\/blog\/wp-json\/wp\/v2\/comments?post=812"}],"version-history":[{"count":5,"href":"https:\/\/www.timelordz.com\/blog\/wp-json\/wp\/v2\/posts\/812\/revisions"}],"predecessor-version":[{"id":821,"href":"https:\/\/www.timelordz.com\/blog\/wp-json\/wp\/v2\/posts\/812\/revisions\/821"}],"wp:attachment":[{"href":"https:\/\/www.timelordz.com\/blog\/wp-json\/wp\/v2\/media?parent=812"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.timelordz.com\/blog\/wp-json\/wp\/v2\/categories?post=812"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.timelordz.com\/blog\/wp-json\/wp\/v2\/tags?post=812"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}