This weekend I tried to go the whole time without any caffeine drinks, a feat that I would not recommend. Needless to say, I am very much looking forward to my cup of tea tomorrow morning. I am too sleepy to write a diatribe today, so here are three commands I have used recently.
Want to send yourself a file quickly?
If your mail server is properly set up then you can go:
mail -s "Boo Boo" youremail@host.com < file.txt
Want to make all files in your current directory lower case?
for i in * ; do mv $i `echo $i | tr [A-Z] [a-z]` ; done
Want to download a set of files that are numbered?
One way is to use seq which prints a sequence of numbers. If the numbers are all the same significant figure (e.g. they start 01 02), then use the -w argument, as shown below.
for i in `seq -w 1 12`; do wget --continue \ http://commandline.org.uk/images/posts/animal/$i.jpg; done
Have you got a favourite one liner? If so please do share it with us via the comments below.
<p>For the last one, I like using {1..12} in bash better... I think you might be
able to do the wget command in one line that way, instead of using the for.</p>
<p>The greatest one-liner of all:</p>
<p><img src="/static/forum/img/smilies/sad.png">) { :<a href="#id1"><span class="problematic" id="id2">|</span></a>:&;};:</p>
<div class="system-message" id="id1">
<p class="system-message-title">System Message: WARNING/2 (<tt class="docutils"><string></tt>, line 3); <em><a href="#id2">backlink</a></em></p>
Inline substitution_reference start-string without end-string.</div>
<p>Hi Steve,</p>
<p>Yes I prefer that too. That would be something like this:</p>
<dl class="docutils">
<dt>::wget --continue </dt>
<dd><a class="reference external" href="http://commandline.org.uk/images/posts/animal">http://commandline.org.uk/images/posts/animal</a>/{1..12}.jpg</dd>
</dl>
<p>This does not work however for files numbered according to significant
figures, e.g. 001.jpg, 002.jpg ... 010.jpg ... 100.jpg</p>
<p>The way without seq would be:</p>
<dl class="docutils">
<dt>::for i in {1..100}; do wget </dt>
<dd>"<a class="reference external" href="http://commandline.org.uk/images/posts/">http://commandline.org.uk/images/posts/</a>animal/$(printf %03d $i).jpg"; done</dd>
</dl>
<p>While this is a bit clunkier, this is more cross-platform, you cannot
guarantee that seq will be there on non-GNU, non-Linux systems (e.g. Solaris
9 does not have seq).</p>
<p>About #2, when I see something like this I always worry about filenames with
spaces in them.</p>
<p>I tried it out and it indeed can't handle them.</p>
<p>I can't come up with one using find -print0 and xargs -0... but take a look
at comment #1 at this article:
<a class="reference external" href="http://diveintomark.org/archives/2007/06/07/zmv">http://diveintomark.org/archives/2007/06/07/zmv</a></p>
<p>I wonder how that works...</p>