cmd find: exclude directory when using option -depth


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers cmd find: exclude directory when using option -depth
# 1  
Old 03-09-2012
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.
Code:
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
    Process each directory's contents before the directory itself.

so my tests , in the example in want to exclude directory "excludedir", only the example with "-path" works , is there another option to use "-prune" and "-depth" ?

OK
Code:
find . -depth ! \( -path "./excludedir/*" -o -type d -name excludedir -prune \) -print

OK
Code:
find . ! \( -name excludedir -type d -prune \) -print

NOTOK
Code:
find . -depth ! \( -name excludedir -type d -prune \) -print

NOTOK , syntax error in Linux:
Code:
find . ! \( -name excludedir -type d -prune \) -depth -print

find: warning: you have specified the -depth option after a non-option argument !,
but options are not positional (-depth affects tests specified before it as well as those
specified after it). Please specify options before other arguments.

regards
# 2  
Old 03-15-2012
No Help ?
# 3  
Old 03-15-2012
Bumping up posts or double posting is not permitted in these forums.

Please read the rules, which you agreed to when you registered, if you have not already done so.

You may receive an infraction for this. If so, don't worry, just try to follow the rules more carefully. The infraction will expire in the near future

Thank You.

The UNIX and Linux Forums.
# 4  
Old 03-15-2012
You already have not one but two ways that work with -depth and -prune. I have no idea what else you want.

The warning is just a warning. Put the -depth immediately after the . and it will go away.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How-To Exclude Directory in find command

How can i tweak the below find command to exclude directory/s -> "/tmp/logs" find . -type f \( ! -name "*.log*" ! -name "*.jar*" \) -printNote: -path option/argument does not work with the version of find that i have. bash-3.2$ uname -a SunOS mymac 5.10 Generic_150400-26 sun4v sparc sun4v (7 Replies)
Discussion started by: mohtashims
7 Replies

2. Shell Programming and Scripting

Understand the importance of -depth option in find command.

Hi All, Can you please help me in understanding the importance of -depth of find. I am trying to execute below code.find . -mtime +5 -name "*" -depth -exec ls -l {} \; But it is throwing below error.find: warning: you have specified the -depth option after a non-option argument -mtime,... (2 Replies)
Discussion started by: Girish19
2 Replies

3. Ubuntu

[Solved] Using Find with an exclude/exclude file

I am familiar with using tar and exclude/include files: tar zcf backup.dirs.tgz --files-from=include.mydirs --exclude-from=exclude.mydirs --no-recursion but was wondering if I could use find in the same way. I know that you can just specify the directories to exclude but my list is... (2 Replies)
Discussion started by: metallica1973
2 Replies

4. 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

5. 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

6. Shell Programming and Scripting

complicated exclude option in find command

Hi all, In a directory, I have many video files. Example : As you can see, some of the video files come with a .aspx file (wich means the video is actually being uploaded and not entirely written on the FS) I try to write a bash script that would find all video files in the ... (1 Reply)
Discussion started by: gniagnia
1 Replies

7. Shell Programming and Scripting

rsync exclude option

Hi Frdz, i am using rsync to transfer files from source to destination. but i have one criteria like i have to tranfer only links from source to destination. in home/test/po folder i have kiran/test1 -> /home/test/lo/fg kiran/test2 -> /home/test/lo/fg2 like links are available.... (1 Reply)
Discussion started by: KiranKumarKarre
1 Replies

8. 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

9. UNIX for Dummies Questions & Answers

TAR : option to exclude absolute path

Dear All , :D I have a question ... I need to exclude the absolute path in the TAR process. For example : system("tar cvf /root/BACKUPS_$fecha.tar /root/BKP/"); system("gzip /root/BACKUPS_$fecha.tar"); I need to exclude de path " /root/BKP/ " in the file.tar.gz What is the parameter to... (1 Reply)
Discussion started by: telco
1 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