Monday, November 28, 2011

Uninstalling all gems

This is very similar to the last post, but I want to run a command that will list all of the gems currently installed on my system, and use the output to uninstall them.

To be continued....

Executing multiple commands with the output from find

I want to sync two directories with rsync, but I only want to copy files that appear in the first directory. There may be a way to do this with rsync only, but I want to use the output from a find to accomplish this.

find .   will give a list of all files needed, but also with an extra ./ in each name, so we will need to format that.


cut -c3-  will cut out the first two characters

awk '{print "rsync -a " $1 " . "}'   will do the rest

So we have two directories, DirA and DirB.
DirA has two files, 'blah', and 'foo'
DirB also has 'blah' and 'foo', but it also has two others: 'tar' and 'bar'.

We only want to sync the files that exist in A, so from the parent directory we will type this command:
find DirA | awk '{print "rsync -u " $1 " DirB"}'
find DirA | cut -c6- | grep '\w' |awk '{print "rsync -u DirB/" $1 " DirA"}'

So a quick overview, we needed to cut 5 characters rather then 2. This is because DirA/ is 5 characters. Also grep '\w' removed the blank line.

Now we actually have to run this command


To be continued.....