Free, tested & ready to use examples!
Web - convert files and webpages to any format!

Recursively delete backup files

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.
  • 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
    echo "recursively removing backup files from"
    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.

  • Always check you current working directory before calling 'cbackup'. You may delete necessary files.
  • It's not recommended to run 'cbackup' as root.
  • tested 
  • Mac OS X 10.4.8
  • FreeBSD 6.2

    © AnyExample 2010-2013
    License | Privacy | Contact