[Sussex] Excluding hidden files and folders with find command
Dominic Humphries
linux at oneandoneis2.org
Tue Sep 20 16:01:50 UTC 2011
On Tue, 2011-09-20 at 14:32 +0100, Fay Zee wrote:
> Hi Dominic,
> Yes, that works perfectly, and it makes perfect sense now I see the
> command. Thanks so much :-)
No problem!
> Here, I've done some testing and there is a scenario I didn't
> properly explain.
>
> 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*' | 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
This is because the command enclosed in backticks returns nothing, so
the above is basically the same as 'ls -l' which will default to your
current directory.
It looks like
$ find . -name '*listit*' | grep -v 'Downloads' | grep -v '/home/fay/listit/'
would be the 'find' command you want, given the above scenario.
Dominic
More information about the Sussex
mailing list