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
 

ben, 17 August 2004

or you can use :

find ./ -name '*~' -exec rm {} ; -print

This will execute the command rm for any files found. -print is optional, but it is nice to see what you are deleting!

xcristi, 05 November 2005

If you have problem with the last variant (find: missing argument to `-exec'), write this way:

find ./ -name '*~' -exec rm '{}' ';' -print

Silvia, 24 June 2006

For find: missing argument to `-exec` error, I use:

find ./ -name '*~' -exec rm '{}' ; -print

Silvia, 24 June 2006

Sorry, it's: find ./ -name '*~' -exec rm '{}' \; -print (the slash disappears at submit)

Cezar, 23 November 2007

for correctly handling files with spaces in their names:

find . -name "*~" -type f -print0|xargs -0 rm

Add a comment

Name:
Email or URL: (optional)
Security code
Code shown above:
 
 
© ZoneO-soft - Contact us - Start page