[Sussex] Excluding hidden files and folders with find command
Fay Zee
sussex at eglug.org.uk
Mon Sep 19 23:37:10 UTC 2011
Hi All,
I want to refine one of my pre-backup commands.
The following command deletes tilde files throughout my user
directory:
$ find /home/fay/ -name '*~' -exec rm '{}' ; -print
But I want to keep the potentially valuable backup files in the hidden
dot directories or in the root of the user directory (I might need
those backups in case of corruption).
Examples of files that I want to exclude from the rm command are:
/home/fay/.bluefish/session~
/home/fay/.screenrc~
So I want to delete everything starting with '/home/fay/' EXCEPT
anything starting with '/home/fay/.' so the character after the
third slash mustn't be a dot.
I'm not sure what to feed the -name argument. This option looks at
just a file name not its path name.
The first example file, named 'session~' doesn't begin with a dot but
it's in a directory that begins with a dot.
Looking at the man find pages I see I need to follow a shell pattern.
I looked at the entries for -name, -iname and -path but I'm no nearer.
On a different tack, although there isn't a whole directory tree I
need to ignore this time, so -prune doesn't apply, I'd like help on
this one too, please. In the interests of future searches, I would
like to know how to use the find command when I want to exclude, say,
two complete directories, "dir1" and "dir2" when searching for a
filename containing the string 'form'. Would I have to type the -prune
once for each directory and what would the finished command look like?
Best Regards,
Fay
East Grinstead Linux User Group
www.eglug.org.uk
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.lug.org.uk/pipermail/sussex/attachments/20110919/bf53f3ed/attachment.htm>
More information about the Sussex
mailing list