LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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


Reply
  Search this Thread
Old 03-25-2017, 10:25 PM   #1
domoarigato
LQ Newbie
 
Registered: Feb 2017
Posts: 5

Rep: Reputation: Disabled
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.
 
Old 03-25-2017, 10:40 PM   #2
AuroraZero
Member
 
Registered: Oct 2009
Location: Michigan
Distribution: SlackWare 14.2, Android, Slax, Centos 5.9 Final, Centos 6
Posts: 188

Rep: Reputation: 32
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.
Old 03-25-2017, 10:59 PM   #3
domoarigato
LQ Newbie
 
Registered: Feb 2017
Posts: 5

Original Poster
Rep: Reputation: Disabled
Smile Thank you

AuroraZero: Thank you very much, I'll try that... I appreciate the help, and have a good day/night.
 
Old 03-25-2017, 11:00 PM   #4
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 18,478

Rep: Reputation: 3093Reputation: 3093Reputation: 3093Reputation: 3093Reputation: 3093Reputation: 3093Reputation: 3093Reputation: 3093Reputation: 3093Reputation: 3093Reputation: 3093
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.
Old 03-25-2017, 11:12 PM   #5
domoarigato
LQ Newbie
 
Registered: Feb 2017
Posts: 5

Original Poster
Rep: Reputation: Disabled
Searching with "find" and/or "locate"?

Quote:
Originally Posted by syg00 View Post
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.
 
Old 03-26-2017, 01:08 AM   #6
AwesomeMachine
LQ Guru
 
Registered: Jan 2005
Location: USA and Italy
Distribution: Debian testing/sid; OpenSuSE; Fedora; Mint
Posts: 5,511

Rep: Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007
Locate
Code:
$ locate file_name
 
1 members found this post helpful.
Old 03-26-2017, 01:23 AM   #7
domoarigato
LQ Newbie
 
Registered: Feb 2017
Posts: 5

Original Poster
Rep: Reputation: Disabled
Re: "locate"

Quote:
Originally Posted by AwesomeMachine View Post
Locate
Code:
$ locate file_name
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?
 
Old 03-26-2017, 05:54 AM   #8
nodir
Member
 
Registered: May 2016
Posts: 222

Rep: Reputation: Disabled
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.
Old 03-26-2017, 07:05 AM   #9
mddnix
Member
 
Registered: Mar 2013
Distribution: Redhat, Ubuntu
Posts: 537

Rep: Reputation: 149Reputation: 149
@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 mddnix; 03-26-2017 at 08:17 AM.
 
1 members found this post helpful.
Old 03-26-2017, 08:25 PM   #10
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 1,286

Rep: Reputation: 591Reputation: 591Reputation: 591Reputation: 591Reputation: 591Reputation: 591
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.
Old 03-28-2017, 08:57 AM   #11
domoarigato
LQ Newbie
 
Registered: Feb 2017
Posts: 5

Original Poster
Rep: Reputation: Disabled
Smile Much thanks

Thanks to everyone for your replies. I appreciate all the help and I'll try your suggested commands...
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to find the total number of files in a folder cnm Linux - Newbie 18 08-25-2015 02:01 AM
[SOLVED] Using terminal command -Find files in a folder and copy them to a different folder j-jock Linux - General 4 11-28-2011 03:20 AM
find the number of files in a folder swift2008 Programming 5 10-25-2010 04:22 AM
Find files and copy the results to desired folder? colbert Linux - Newbie 6 11-09-2008 12:21 AM
How to find a work within a folder full of text files? juanb Linux - General 4 05-03-2005 05:09 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:56 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration