Free, tested & ready to use examples : recursively delete backup jEdit emacs vim tilde
AnyExample.com
 
Webanyexample.com
 

Recursively delete backup files

abstract 
This is a simple example of a unix command, which recursively deletes backup files. Many advanced text-editors (jEdit, emacs, vim) produce temporary backup copies of edited files. They usually look Like "file~" (with tilde at the end). While it's not a bad idea to have backup files, they are not needed if you want, for example, redistribute your source code.
compatible 
  • Linux, FreeBSD, Mac OS X, Cygwin...
  • Nearly any unix-compatible system with rm and find

We use find command to find all *~ files beginning from current directory.

$ find ./ -name '*~' -print

To include .*~ files (beginning with dot) we're adding -or clause to find.

$ find ./ -name '*~' -print -or -name ".*~" -print

Finally, we use -exec option of find to remove all found files.

$ find ./ -name '*~' -exec rm '{}' \; -print -or -name ".*~" -exec rm {} \; -print

So, this will remove every backup~ file beginning from current directory.

source code: bash script
#!/bin/sh
echo "recursively removing backup files from"
pwd
find ./ -name '*~' -exec rm '{}' \; -print -or -name ".*~" -exec rm {} \; -print

You may save this script as /usr/bin/cbackup (or put in any other binary folder included in system's path) and use later to get 'clean' project source without typing lengthy commands.

warning 
  • Always check you current working directory before calling 'cbackup'. You may delete necessary files.
  • It's not recommended to run 'cbackup' as root.
tested by AnyExample.com on 2007-01-24
  • Mac OS X 10.4.8
  • FreeBSD 6.2
 


 
© AnyExample 2007
License | Privacy | Contact