Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


  Search this Thread
Old 01-20-2012, 02:51 AM   #1
Registered: Mar 2009
Posts: 51

Rep: Reputation: 10
Need help with find command

I want to use the find command to well, find stuff (this much is obvious lol)
Let's say I have a directory named Folder, (when I run the find command I will be in that directory) and in that directory are a bunch of sub-directories. In those sub-directories are a whole bunch of stuff, but I just want to see all the files named VIDEO.
This will do that:
find -name VIDEO
But I have a problem, some of the VIDEO files I do not want to see. All the VIDEO files I do not want to see also have this file in the same sub-directory as it named DONOTLIST.

So how do I use find to find all the files named VIDEO under the Folder directory, but tell it not to look in any sub-directories that have the file DONOTLIST in it?
Old 01-20-2012, 03:13 AM   #2
Registered: Jun 2006
Location: Bangalore,india
Distribution: Linux(Redhat,fedora,suse,ubantu), Solaris (s8/s9/s10/nevada/open-solaris)
Posts: 285

Rep: Reputation: 32
try this :

find . | grep VIDEO
Old 01-20-2012, 03:58 AM   #3
Senior Member
Registered: Aug 2011
Location: Bangalore, India
Distribution: RHEL 7.x, SLES 11 SP2/3/4
Posts: 1,195
Blog Entries: 4

Rep: Reputation: 221Reputation: 221Reputation: 221
try this

#find /folder -t file -name VIDEO
this will search inside folder for all files with name VIDEO
Old 01-20-2012, 07:30 AM   #4
LQ Newbie
Registered: Mar 2008
Location: Bangalore, India
Distribution: Fedora,Ubuntu,RHEL
Posts: 8

Rep: Reputation: 0
1. Get the list of directories with "DONOTLIST". Using "find . |grep DONOTLIST"
2. Give the directory names from point:1, <excludedir1>,excludedir2>,... with -prune switch and search for "VIDEO" keyword in the end.

find . -path './<excludedir1>' -prune -o -path './<excludedir2>' -prune -o \( -name VIDEO -print \)

Better use a small shell script to do this.

Old 01-20-2012, 03:17 PM   #5
Registered: Mar 2009
Posts: 51

Original Poster
Rep: Reputation: 10
Thanks vinilvijayan, that's what I wanted.
Old 01-20-2012, 03:22 PM   #6
Nominal Animal
Senior Member
Registered: Dec 2010
Location: Finland
Distribution: Xubuntu, CentOS, LFS
Posts: 1,723
Blog Entries: 3

Rep: Reputation: 947Reputation: 947Reputation: 947Reputation: 947Reputation: 947Reputation: 947Reputation: 947Reputation: 947
Because the DONOTLIST file is in the same directory as the VIDEO files you want to see, I don't know if there is a find option for this case. (Specifically, I don't think -prune helps here, except if all directories containing DONOTLIST is also supplied like vinilvijayan suggested.)

I do know that
find . -type d -print0 | bash -c 'while read -rd "" DIR ; do [ -f "$DIR/VIDEO" ] && [ ! -f "$DIR/DONOTLIST" ] && printf "%s\\n" "$DIR/VIDEO" ; done'
does work. It's probably not the shortest or most efficient way to go about it, though.

The idea is that find just searches for all directories. It uses the ASCII NUL, zero byte, as the separator, so that all file names are handled correctly. The Bash snippet reads in the directories. If the directory contains file VIDEO but not file DONOTLIST, then it prints the path to the VIDEO file.

If you want the DONOTLIST file to affect both the current directory and subdirectories, I'd use GNU awk, since it handles RS="\0";FS="/+" separators correctly. I'd construct an array of directories that contain the VIDEO file, and another of directories that contain the DONOTLIST file, both with trailing slashes, then remove the entries in the former array that begin with any entry in the latter. Finally, print the ones left over (adding the VIDEO to the directory path).

Last edited by Nominal Animal; 01-20-2012 at 03:24 PM.
Old 01-20-2012, 03:41 PM   #7
Registered: Mar 2009
Posts: 51

Original Poster
Rep: Reputation: 10
Nominal Animal, you are a genius! This is exactly what I wanted! THANK YOU so much!!!
Old 01-20-2012, 03:44 PM   #8
Rory Glenn Pascua
Registered: Jan 2012
Posts: 35

Rep: Reputation: Disabled
Find Command

I usually just do this:

find / -name <file you're looking for>


find / -name firefox


exclude, find

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
[SOLVED] Find a file in directories without using find command sikanders Linux - Newbie 14 08-06-2010 09:47 PM
Find/grep/wc command to find matching files, print filename and word count dbasch Linux - Newbie 10 09-14-2009 06:55 PM
Single find command to find multiple files? thok Linux - Newbie 7 01-31-2009 05:45 PM
Using a single "Find" Command to find files bases on multiple criteria roboxooo Linux - Newbie 6 01-15-2009 05:13 AM
can't find my find command! how to replace? dave247 Debian 4 11-19-2008 11:51 AM > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 06:16 PM.

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