| www.delorie.com/gnu/docs/findutils/find_51.html | search |
![]() Buy GNU books! | |
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This section gives examples of removing unwanted files in various situations. Here is a command to remove the CVS backup files created when an update requires a merge:
find . -name '.#*' -print0 | xargs -0r rm -f |
You can run this command to clean out your clutter in `/tmp'. You might place it in the file your shell runs when you log out (`.bash_logout', `.logout', or `.zlogout', depending on which shell you use).
find /tmp -user $LOGNAME -type f -print0 | xargs -0 -r rm -f |
To remove old Emacs backup and auto-save files, you can use a command like the following. It is especially important in this case to use null-terminated file names because Emacs packages like the VM mailer often create temporary file names with spaces in them, like `#reply to David J. MacKenzie<1>#'.
find ~ \( -name '*~' -o -name '#*#' \) -print0 | xargs --no-run-if-empty --null rm -vf |
Removing old files from `/tmp' is commonly done from cron:
find /tmp /var/tmp -not -type d -mtime +3 -print0 | xargs --null --no-run-if-empty rm -f find /tmp /var/tmp -depth -mindepth 1 -type d -empty -print0 | xargs --null --no-run-if-empty rmdir |
The second find command above uses `-depth' so it cleans out
empty directories depth-first, hoping that the parents become empty and
can be removed too. It uses `-mindepth' to avoid removing
`/tmp' itself if it becomes totally empty.
| webmaster donations bookstore | delorie software privacy |
| Copyright © 2003 by The Free Software Foundation | Updated Jun 2003 |