Sponsored Content
Top Forums UNIX for Dummies Questions & Answers cmd find: exclude directory when using option -depth Post 302605915 by bora99 on Friday 9th of March 2012 03:54:45 AM
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
 

10 More Discussions You Might Find Interesting

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

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

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

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

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

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

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

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

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

10. 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
prune(1)						      General Commands Manual							  prune(1)

NAME
prune - Prune directed graphs SYNOPSIS
prune [ -n node ] [ -N attrspec ] [ files ... ] DESCRIPTION
prune reads directed graphs in the same format used by dot(1) and removes subgraphs rooted at nodes specified on the command line via options. These nodes themselves will not be removed, but can be given attributes so that they can be easily located by a graph stream edi- tor such as gvpr(1). prune correctly handles cycles, loops and multi-edges. Both options can appear multiple times on the command line. All subgraphs rooted at the respective nodes given will then be processed. If a node does not exist, prune will skip it and print a warning message to stderr. If multiple attributes are given, they will be applied to all nodes that have been processed. prune writes the result to the stdout. OPTIONS
-n name Specifies name of node to prune. -N attrspec Specifies attribute that will be set (or changed if it exists) for any pruned node. attrspec is a string of the form attr=value. EXAMPLES
An input graph test.dot of the form digraph DG { A -> B; A -> C; B -> D; B -> E; } , processed by the command prune -n B test.dot would produce the following output (the actual code might be formatted in a slightly different way). digraph DG { A -> B; A -> C; } Another input graph test.dot of the form digraph DG { A -> B; A -> C; B -> D; B -> E; C -> E; } (note the additional edge from C to E ), processed by the command prune -n B -N color=red test.dot results in digraph DG { B [color=red]; A -> B; A -> C; C -> E; } Node E has not been removed since its second parent C is not being pruned. EXIT STATUS
prune returns 0 on successful completion. It returns 1 if an error occurs. SEE ALSO
dot(1), gvpr(1) AUTHOR
Marcus Harnisch <marcus.harnisch@gmx.net> prune(1)
All times are GMT -4. The time now is 04:43 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy