How-To Exclude Directory in find command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How-To Exclude Directory in find command
# 8  
Old 06-29-2016
Quote:
Originally Posted by mohtashims
@Don: Thank you for the suggestion.

But where can i put the -print option which you can see in the OP ?

Becoz in the next line i was reading the output file as you can see below.

Code:
find . -type f \( ! -name "*.log*"  ! -name "*.jar*" \) -print |
while read file
do

Please suggest.
I suggest that you read post #6 and decide whether you want to use:
Code:
find . -type f \( ! -name "*.log*"  ! -name "*.jar*" \) | grep -v '^./tmp/logs/' |
while IFS= read -r file
do	: Do whatever you want to do with "$file"
done

or:
Code:
find . -type f \( ! -name "*.log*"  ! -name "*.jar*" \) | grep -v '/tmp/logs/' |
while IFS= read -r file
do	: Do whatever you want to do with "$file"
done

based on your answer to the question I asked in post #6. If you really, really want to, you can change those suggestions to:
Code:
find . -type f \( ! -name "*.log*"  ! -name "*.jar*" \) -print | grep -v '^./tmp/logs/' |
while IFS= read -r file
do	: Do whatever you want to do with "$file"
done

or:
Code:
find . -type f \( ! -name "*.log*"  ! -name "*.jar*" \) -print | grep -v '/tmp/logs/' |
while IFS= read -r file
do	: Do whatever you want to do with "$file"
done

respectively, and get exactly the same results with more typing. (In cases where you do not specify any primaries to find that produce output (such as -exec, -ok, or -print), find supplies a -print primary by default.)

I sincerely apologize for assuming that you would realize that I was just suggesting a couple of possible replacements for your find command (based on your answer to the question about what files you are trying to exclude) in your pipeline. Based on the title of this thread, I didn't realize that I needed to repeat and improve the rest of your pipeline as well.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Exclude directories in FIND command

Can you please help tweak the below command to exclude all directories with the name "logs" and "tmp" find . -type f \( ! -name "*.tar*" ! -name "*.bkp*" \) -exec /usr/xpg4/bin/grep -i "user_1" /dev/null {} + >result.out bash-3.2$ uname -a SunOS mymac 5.10 Generic_150400-26 sun4v sparc sun4v... (9 Replies)
Discussion started by: mohtashims
9 Replies

2. Red Hat

Find command to exclude a specific path

Hi Folks, I want to run the below command and to exclude the specific path like /var/test/support/... . How to achieve using the below command find / -type f \( –perm –4000 –o –perm –2000 \) –print -Siva Please do not use FONT tags inside CODE tags. And, there is usually no reason to... (2 Replies)
Discussion started by: gsiva
2 Replies

3. UNIX for Dummies Questions & Answers

cmd find: exclude directory when using option -depth

hello, i want to use "-depth" in command "find" and want to exclude a directory. the find command should work in HP-UX and Linux. i see in the find man page: -prune If -depth is not given, true; do not descend the current directory. If -depth is given, false; no effect. -depth... (3 Replies)
Discussion started by: bora99
3 Replies

4. Shell Programming and Scripting

Find command with exclude

I had a Shell script that removes the files that are in a directory older than the specified days. find /test/files -mtime +10 I would like to add another condition to the find command above that is to exclude any file starting with ‘CGU' Thanks (1 Reply)
Discussion started by: db2dbac
1 Replies

5. Shell Programming and Scripting

SunOS: How to exclude directory in find command?

Hi All, First my OS version is: ksh:0$ uname -a SunOS 5.9 Generic_122300-48 sun4u sparc SUNW,Sun-Fire-V440 I want to exclude the following DIR(./country111) in my search pattern: ksh:0$ find . -name "*.tar" ./country111/COUNTRY_BATCH-801.tar ./country111/COUNTRY_BATCH-802.tar... (3 Replies)
Discussion started by: saps19
3 Replies

6. Shell Programming and Scripting

Exclude a directory in 'find'

Hi, I'm in the process of writing a shell script which will be ran under cron hourly and will check for files of specific age in my ftp folder, then moves those over inside a folder called "old" (which is within the ftp dir). But, I'm unable to figure out how to exclude the "old" folder when... (1 Reply)
Discussion started by: mutex1
1 Replies

7. Shell Programming and Scripting

Help - Find command to exclude sub-directories

Hi Forum. I'm trying to write a script that finds and deletes files that are older than 300 days. The script will read a table that contains the following 3 columns: 1st col: “Y” means sub-directory scan; "N" means no subdirectory scan 2nd col: sub-directory location 3rd col: File prefix... (7 Replies)
Discussion started by: pchang
7 Replies

8. UNIX for Dummies Questions & Answers

find command to exclude directories

Howdy I have this directory structure ... eep eepaptest eepfatest eepgltest eep.old eeppoptest ehf ehfaptest ehfgltest ehp ehpgltest I want to find files in these directories, but I want to exclude eep, ehf & ehp. Cany anyone help with the correct command ?? (1 Reply)
Discussion started by: SmurfGGM
1 Replies

9. Shell Programming and Scripting

How to exclude top level directory with find?

I'm using bash on cygwin/windows. I'm trying to use find and exclude the directory /cygdrive/c/System\ Volume\ Information. When I try to use the command below I get the error "rm: cannot remove `/cygdrive/c/System Volume Information': Is a directory. Can someone tell me what I am doing... (3 Replies)
Discussion started by: siegfried
3 Replies

10. Shell Programming and Scripting

how do i exclude the current directory when using find?

i want to compile a list of files in all sub directories but exclude the current directory. the closest i could get was to search 'only' the current directory, which is the opposite of what i wanted. find . ! -name . -prune (7 Replies)
Discussion started by: mjays
7 Replies
Login or Register to Ask a Question