LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
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.

Notices

Reply
 
Search this Thread
Old 01-20-2012, 01:51 AM   #1
dth4h
Member
 
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:
Code:
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, 02:13 AM   #2
barunparichha
Member
 
Registered: Jun 2006
Location: Bangalore,india
Distribution: Linux(Redhat,fedora,suse,ubantu), Solaris (s8/s9/s10/nevada/open-solaris)
Posts: 281

Rep: Reputation: 32
try this :

find . | grep VIDEO
 
Old 01-20-2012, 02:58 AM   #3
deep27ak
Senior Member
 
Registered: Aug 2011
Location: Bangalore, India
Distribution: rhel 5x,6.0,6.2, centOS 5x,6.0,6.2
Posts: 1,188
Blog Entries: 4

Rep: Reputation: 219Reputation: 219Reputation: 219
try this

Code:
#find /folder -t file -name VIDEO
this will search inside folder for all files with name VIDEO
 
Old 01-20-2012, 06:30 AM   #4
vinilvijayan
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.

Cheers,
vinil
 
Old 01-20-2012, 02:17 PM   #5
dth4h
Member
 
Registered: Mar 2009
Posts: 51

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

Rep: Reputation: 942Reputation: 942Reputation: 942Reputation: 942Reputation: 942Reputation: 942Reputation: 942Reputation: 942
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
Code:
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 02:24 PM.
 
Old 01-20-2012, 02:41 PM   #7
dth4h
Member
 
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, 02:44 PM   #8
Rory Glenn Pascua
Member
 
Registered: Jan 2012
Posts: 35

Rep: Reputation: Disabled
Find Command

I usually just do this:

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

ex:

find / -name firefox
 
  


Reply

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


All times are GMT -5. The time now is 11:54 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration