Skip navigation

Here’s something interesting I just learned about. You can echo a command to see it’s syntaxis before running it in the command line, and then, pipe it to the shell, like this:

echo ls -ltra | awk '/.html~/' | xargs rm

(examine it carefully) and call it again adding ” bash

echo ls -ltra | awk '/.html~/'| xargs rm | bash

Another recent use I gave to it is in this command:

svn status | grep ^M | awk '{print "scp ",$2," me@xxx:/home/myTemp/"}' | tr -d '\n' | bash

1) pulls the status from the svn,
2) filters the modified files,
3) prints the scp command with the name of the file and the destination,
4) makes that a sequence in one line (by removing the newlines “\n”),
5) and finally pipes all to bash to execute all the commands and get the modified files moved elsewhere.

find . -type f -mtime -22 | awk '/gif/' | cut -c 3- | awk '{print "scp ",$0, " me@xxx:/home/ignacio/myTemp"}' | bash -i

This last example doesn’t need the (\n) newlines removed to run thanks to the “-i” option after bash

Ain’t it sweet?


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: