{"id":148,"date":"2012-10-17T11:24:50","date_gmt":"2012-10-17T16:24:50","guid":{"rendered":"https:\/\/code.angelmarquez.com\/blog\/?p=148"},"modified":"2012-10-17T11:34:16","modified_gmt":"2012-10-17T16:34:16","slug":"commandline-fu","status":"publish","type":"post","link":"https:\/\/code.angelmarquez.com\/blog\/2012\/10\/17\/commandline-fu\/","title":{"rendered":"Commandline-fu"},"content":{"rendered":"<p>Derping around a GUI is all fine and good for many things but sometimes you really just need to\u00a0<strong>get things done <\/strong>and your GUI just won&#8217;t cut it.\u00a0Having a powerful command line interface and being knowing how to use it are critical skills. I&#8217;ve recently found myself having to use the command line a bit more than usual, so below are some of the learned or re-learned tidbits of knowledge that might help others.<\/p>\n<p>Note: I&#8217;m a Windows developer, but the commands below all use bash in Cygwin.<\/p>\n<p><strong>Q: How can I generate a file of an arbitrary size with random data?<\/strong><\/p>\n<p><strong><\/strong>A: Use dd in conjunction with \/dev\/urandom<\/p>\n<pre># 2 Megs\r\ndd if=\/dev\/urandom of=a.log bs=1M count=2\r\n\r\n# 2 Gigs (1 Meg * 2 * 1024)\r\ndd if=\/dev\/urandom of=a.log bs=1M count=2K \r\n<\/pre>\n<div>Note that 1k<strong>B<\/strong> = 1000 and 1K = 1024, 1M<strong>B<\/strong> = 1000 * 1000 while 1M =1024 * 1024, and so on.<\/div>\n<div><\/div>\n<div>Credit for this protip goes to the Linux Commando blog: <a href=\"http:\/\/linuxcommando.blogspot.com\/2008\/06\/create-file-of-given-size-with-random.html\">http:\/\/linuxcommando.blogspot.com\/2008\/06\/create-file-of-given-size-with-random.html<\/a><\/div>\n<p>&nbsp;<\/p>\n<p><strong>Q: How can I sort a file, remove duplicate elements, and do it all in-place?<\/strong><\/p>\n<p>A:\u00a0sort temp.txt -o temp.txt<\/p>\n<p><strong>Q:\u00a0How can I pipe the output from foo.exe to bar.exe if bar.exe does not accept input from stdin?<\/strong><\/p>\n<p>A: The obvious answer is to redirect stdout to a file then use the file as an input parameter.<br \/>\n(Note: md5sum *does* accept stdin input. Ignore that for the sake of the example)<\/p>\n<pre class=\"brush: bash; gutter: true\">echo -n hello &gt; temp.dat\r\nmd5sum temp.dat\r\nrm temp.dat<\/pre>\n<p>The command below can skip the intermediate step.<\/p>\n<pre>md5sum &lt;(echo -n hello)<\/pre>\n<div>I wasn&#8217;t familiar with this syntax till recently. I discovered it in this bash redirections cheat sheet: <a href=\"http:\/\/www.catonmat.net\/download\/bash-redirections-cheat-sheet.pdf\">http:\/\/www.catonmat.net\/download\/bash-redirections-cheat-sheet.pdf<\/a><\/div>\n<div><\/div>\n<div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Derping around a GUI is all fine and good for many things but sometimes you really just need to\u00a0get things done and your GUI just won&#8217;t cut it.\u00a0Having a powerful command line interface and being knowing how to use it are critical skills. I&#8217;ve recently found myself having to use the command line a bit [&hellip;]<\/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-148","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/code.angelmarquez.com\/blog\/wp-json\/wp\/v2\/posts\/148","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/code.angelmarquez.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/code.angelmarquez.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/code.angelmarquez.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/code.angelmarquez.com\/blog\/wp-json\/wp\/v2\/comments?post=148"}],"version-history":[{"count":4,"href":"https:\/\/code.angelmarquez.com\/blog\/wp-json\/wp\/v2\/posts\/148\/revisions"}],"predecessor-version":[{"id":151,"href":"https:\/\/code.angelmarquez.com\/blog\/wp-json\/wp\/v2\/posts\/148\/revisions\/151"}],"wp:attachment":[{"href":"https:\/\/code.angelmarquez.com\/blog\/wp-json\/wp\/v2\/media?parent=148"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/code.angelmarquez.com\/blog\/wp-json\/wp\/v2\/categories?post=148"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/code.angelmarquez.com\/blog\/wp-json\/wp\/v2\/tags?post=148"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}