How to find files that aren't in a given folder(s)?
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
How to find files that aren't in a given folder(s)?
Could anyone please tell me a command to search my computer for a file ("gentoo.txt") but ignore one folder ("UVWX")
or ignore multiple folders ("UVWX2", "UVWX3", and "UVWX4")?
Thanks in advance for helping a command line newbie.
Sounds like homework - in the normal course of events, why would a user care ?.
"find" is the obvious answer, but "locate" is easier on the machine if the updatedb has been run.
Sounds like homework - in the normal course of events, why would a user care ?.
"find" is the obvious answer, but "locate" is easier on the machine if the updatedb has been run.
syg00: Thanks for the reply.
If I use "find" and "locate", how do I enter the command, and with what flags or options? Thank you.
@domoarigato, I'm bit confused here. The title says 'How to find files that aren't in a given folder(s)?' Well, you cannot find those files there, because they are NOT there... What I'm missing here?
Why would search result will show folders like UVWX, UVWX3 etc, when you search for file gentoo.txt? Are there multiple copies of gentoo.txt files also available in folders that you have mentioned earlier?
Is this specific to Gentoo Distro?
Anyway, possible two ways to find gentoo.txt file are
Find files that are not in UVWX* directories.
Most precise is
Code:
locate 'gentoo.txt' | grep -v '/UVWX[^/]*/'
find / -type d -name 'UVWX*' -prune -o -type f -name 'gentoo.txt' -print
grep takes a regular expression, while find takes a shell-glob pattern.
-prune actually skips the directories - this is faster than processing but not printing them.
You need -print in order to suppress the default print at -prune.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.