Linux - Newbie This 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.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
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.
|
 |
03-25-2017, 09:25 PM
|
#1
|
LQ Newbie
Registered: Feb 2017
Posts: 5
Rep: 
|
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.
|
|
|
03-25-2017, 09:40 PM
|
#2
|
Member
Registered: Oct 2009
Location: memphis, TN
Distribution: SlackWare 14.2, Android, Slax, Centos 5.9 Final, Centos 6
Posts: 188
Rep:
|
The command ag might be what you are looking for here. It very versital and easy to use once you get the hang of its flags.
For example:
Code:
ad gentoo.txt -l --ignore-dir=/etc/man
will give you all the files names gentoo.txt except for the ones in /etc/man.
Code:
ad gentoo.txt -l --ignore-dir=/etc/man --ignore-dir=/usr/src
will give you all the gentoo.txt files except those in /etc/man and /usr/src.
Hope that is what you are looking for and helps out.
|
|
1 members found this post helpful.
|
03-25-2017, 09:59 PM
|
#3
|
LQ Newbie
Registered: Feb 2017
Posts: 5
Original Poster
Rep: 
|
Thank you
AuroraZero: Thank you very much, I'll try that... I appreciate the help, and have a good day/night.
|
|
|
03-25-2017, 10:00 PM
|
#4
|
LQ Veteran
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,445
|
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.
|
|
1 members found this post helpful.
|
03-25-2017, 10:12 PM
|
#5
|
LQ Newbie
Registered: Feb 2017
Posts: 5
Original Poster
Rep: 
|
Searching with "find" and/or "locate"?
Quote:
Originally Posted by syg00
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.
|
|
|
03-26-2017, 12:08 AM
|
#6
|
LQ Guru
Registered: Jan 2005
Location: USA and Italy
Distribution: Debian testing/sid; OpenSuSE; Fedora; Mint
Posts: 5,524
|
|
|
1 members found this post helpful.
|
03-26-2017, 12:23 AM
|
#7
|
LQ Newbie
Registered: Feb 2017
Posts: 5
Original Poster
Rep: 
|
Re: "locate"
Quote:
Originally Posted by AwesomeMachine
|
Awesome M: Thanks for the reply. How do I use "locate" to search for the file but make it ignore one or more folders? Also, what does the "$" do?
|
|
|
03-26-2017, 04:54 AM
|
#8
|
Member
Registered: May 2016
Posts: 222
Rep: 
|
Code:
locate file_name | grep -v ignorefolder
would work.
The $ is only there as an example for a command prompt. With a # (opposed to the $) you are told it has to be run as root.
|
|
1 members found this post helpful.
|
03-26-2017, 06:05 AM
|
#9
|
Member
Registered: Mar 2013
Distribution: Rocky, Fedora, Ubuntu
Posts: 541
Rep: 
|
@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
Code:
locate '*gentoo.txt' | grep -v 'UVWX*'
find / -type f -name 'gentoo.txt' ! -path '*UVWX*'
Last edited by Madhu Desai; 03-26-2017 at 07:17 AM.
|
|
1 members found this post helpful.
|
03-26-2017, 07:25 PM
|
#10
|
Senior Member
Registered: Dec 2011
Location: Simplicity
Distribution: Mint/MATE
Posts: 3,052
|
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.
|
|
1 members found this post helpful.
|
03-28-2017, 07:57 AM
|
#11
|
LQ Newbie
Registered: Feb 2017
Posts: 5
Original Poster
Rep: 
|
Much thanks
Thanks to everyone for your replies. I appreciate all the help and I'll try your suggested commands...
|
|
|
All times are GMT -5. The time now is 01:49 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|