Linux

Today I had to copy several PDFs from various subdirectories to another folder. To find all occurrences of a certain type of file I used find and piped the result to cp.

cd /home/andreas/papers
find . -name *.pdf -exec cp {} /destination/path \;

All arguments to find are taken to be arguments to the command until an argument consisting of ';' is encountered[1]. The '\' escapes that character to protect it expansion by the shell. '{}' represents the list of files retrieved by find. So we can use find for a lot of different tasks which actually makes life quite easy ;)

 

[1] man page of find

Last Updated (Wednesday, 11 November 2009 20:11)

 

I had a bunch of files containing a certain string "foo" that I'd like to substitute with "bar". That can be done in Linux within seconds. I don't know anything shipped with Windows that is capable of recursively renaming files like rename does.

e.g.  You want to substitute every string "foo" of  your set of PNG images with "bar".

foo001.png
foo002.png
foo003.png
rename 's/foo/bar/'g *.png
bar001.png
bar002.png
bar003.png

If you don't trust your regular-expression skills just add -n after rename to get a list showing old and new filenames.

 

 

Last Updated (Thursday, 08 October 2009 15:34)

 
Sponsored links: