[Sussex] Excluding hidden files and folders with find command
Fay Zee
sussex at eglug.org.uk
Tue Sep 20 13:32:13 UTC 2011
Hi Dominic,
Thanks you very much for replying.
On 20 September 2011 08:57, Dominic Humphries wrote:
> Looks like you could use:
>
> $ find /home/fay/ -path '/home/fay/[^.]*~' -exec rm '{}' ; -print
>
> to do what you want.
Yes, that works perfectly, and it makes perfect sense now I see the
command. Thanks so much :-)
> For your other issue, you can probably do it cleverly with find, but
in
> the interests of just getting it done, I would just use backticks to
> string a couple of commands together to do this:
>
> ls -l `find . -name 'form' | grep -v 'dir1' | grep -v 'dir2'`
>
> This will run the find command to get all 'form' files, then pipes
that
> output through two greps to remove dir1 then the output of THAT
> is sent to 'ls' in this case to show you all the files it has found.
Here, I've done some testing and there is a scenario I didn't
properly explain.
Looking for filenames containing the word 'list'.
Because so many filenames contain the name 'list' I'll use 'listit'
instead to simplify the test.
So these are my test files:
/home/fay/Downloads/dokuwiki/loads-of-files-containing-listit.txt
/home/fay/Documents/what_to_buy/listit/testlistit.html
/home/fay/Documents/what_to_buy/listit/webcam.html
/home/fay/listit/january_listit.txt
I want to exclude the 'Downloads' folder and 'listit' which is a sub
sub folder in another folder.
I only want to return the single result 'testlistit.html'.
$ find . -name '*listit*'
./Downloads/docuwiki/loads-of-files-containing-listit.txt
./Documents/how_to_choose_what_to_buy/listit
./Documents/how_to_choose_what_to_buy/listit/testlistit.html
./listit
./listit/january_listit.txt
So far, so good.
$ find . -name '*listit*' | grep -v 'Downloads'
./Documents/how_to_choose_what_to_buy/listit
./Documents/how_to_choose_what_to_buy/listit/testlistit.html
./listit
./listit/january_listit.txt
Still good: excludes the Downloads folder.
$ find . -name '*listit*' | grep -v 'Downloads' | grep -v 'listit'
Returns nothing of course.
$ ls -l `find . -name '*listit*' | grep -v 'Downloads' | grep -v
'listit'`
What I don't understand about this command is that it just returns an
alphabetised list of the root folders and files inside /home/fay
I've tried various commands to achieve the exclusion of
/home/fay/listit/
(without excluding /home/fay/Documents/what_to_buy/listit/) but
nothing has worked so far.
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/20110920/fdbae5b2/attachment.htm>
More information about the Sussex
mailing list