Making find and tar play nicely
Because I’ll forget #1023
Problem
Use Linux’s “find” command to hunt recursively through the current directory tree and find all matching files. While this is simple enough, I’m an idiot and tend to delete important files when drinking working too much — which we all know sucks. It would be nice to have it take all found files, tar them up and move it to the trash.
Solution
The evil, but oh-so-useful xargs command is your saving grace. While I hate using xargs its damn useful. If you take the output of find and pipe it into tar then pipe THAT into rm you get the job done.
Example
This is just a simple hack I’ve put together which seems to work and is relatively simple. (done as a bash function)
frm(){
find . -name "$1" | xargs tar rvf "$1.tar" | xargs rm -rfv && mv $1.tar ~/.trash
}
I just needed this because I had to wipe all ./.svn directories so i just typed frm .svn and it created a .svn.tar and moved that to ~/.trash. Good stuff







Add Yours
YOU