LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to find files that aren't in a given folder(s)? (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-find-files-that-arent-in-a-given-folder-s-4175602542/)

domoarigato 03-25-2017 09:25 PM

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.

AuroraZero 03-25-2017 09:40 PM

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.

domoarigato 03-25-2017 09:59 PM

Thank you
 
AuroraZero: Thank you very much, I'll try that... I appreciate the help, and have a good day/night.

syg00 03-25-2017 10:00 PM

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.

domoarigato 03-25-2017 10:12 PM

Searching with "find" and/or "locate"?
 
Quote:

Originally Posted by syg00 (Post 5688273)
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.

AwesomeMachine 03-26-2017 12:08 AM

Locate
Code:

$ locate file_name

domoarigato 03-26-2017 12:23 AM

Re: "locate"
 
Quote:

Originally Posted by AwesomeMachine (Post 5688291)
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?

nodir 03-26-2017 04:54 AM

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.

Madhu Desai 03-26-2017 06:05 AM

@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*'


MadeInGermany 03-26-2017 07:25 PM

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.

domoarigato 03-28-2017 07:57 AM

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 03:49 PM.