ZoneO-tips for Mandriva Linux

Remove all those backup files

I edit text files on Linux and always end up with tons of backup files ending with ~ all over the place! How do you get rid of it?

 
 

If you edit files on linux, with emacs, vi, kate and others, chances are you'll end up with a lot of those backup files with names ending with ~, and removing them one by one is a pain.

Lucky enough, with a simple command you can get them all, and recursively. Simply go into the top of the directory tree you want to clean (be carefull, these commands are recursive, they will run through the subdirectories), and type

find ./ -name '*~' | xargs rm

Some explanations:

  • the command find ./ -name '*~' will look for all files ending with ~ in the local directory and its subdirectories,
  • the sign | is a 'pipe' that makes the outout of the previous command becoming the input of the next one,
  • xargs reads the arguments on the standard input and applies it to the following command
  • rm deletes whatever file you want.

And if you need a little help for all those unix commands, I really recommend the book Unix in a Nutshell. It's really good, with a nice summary of the most important Unix commands, shell references, and all those things you keep forgetting about sed, regular expressions, or vi.

02/2004
Edited and reformatted 10/2005
 
© ZoneO-soft - Contact us - Start page