![]() |
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 VIDEOSo 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? |
try this :
find . | grep VIDEO |
try this
Code:
#find /folder -t file -name VIDEO |
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 |
Thanks vinilvijayan, that's what I wanted.
|
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'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). |
Nominal Animal, you are a genius! This is exactly what I wanted! THANK YOU so much!!!
|
Find Command
I usually just do this:
find / -name <file you're looking for> ex: find / -name firefox |
| All times are GMT -5. The time now is 06:36 AM. |