I have found the ‘xargs’ command line utility to be very useful sometimes. Often you can avoid writing a special shell script to perform a task by using xargs to perform a task on a list of files. Its use can best be described through an example. I have recenlty be migrating files from one svn repository to another. I began by copying all of the files over using rsync. This copied all of the .svn files from the old repository, which I didn’t want. This left me with at least 30 directories, each with a .svn directory that needed to be removed. What to do? Use xargs. Here is the command:
command-prompt> find -name .svn | xargs rm -rf
This uses the find command to generate a list of all files and directories names ‘.svn’ (case sensistive). This list is then piped to the xargs command, which runs ‘rm -rf’ on each file in the list. That’s it! Note that as this command is written it will seach the current directory and all subdirectories for files with name ‘.svn’. If you want to have ‘find’ search a directory other than the current directory you can add the path of that directory after the file name to search for. See the man page for find for more info.