Using find with -prune to skip a specific pathname using Solaris


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Using find with -prune to skip a specific pathname using Solaris
# 1  
Old 02-23-2009
Using find with -prune to skip a specific pathname using Solaris

I'm trying to prune out the findings of a certain directory path and have something like the following workiing on Linux (Linux 2.6.9-67.0.7.ELsmp #1 SMP x86_64):
find . -path 'test/tmp' -prune -o -print

I now need to have this working on sun/solaris (SunOS 5.8 Generic_117350-34 sun4u sparc SUNW,Netra-T12) and noticed that the find command there doesn't support the "-path" argument:
$ find . -path 'test/tmp' -prune -o -print
find: bad option -path
find: path-list predicate-list
$

I tried using '-name' instead of '-path', however, when I use
find . -name 'test/tmp' -prune -o -print
all the files and dirs under the test/tmp hierarchy is found as if there was no matching expression to be pruned out.

I also tried to use just 'tmp' within '-name' as in
find . -name 'tmp' -prune -o -print
and even though this suppressed the finding of the test/tmp hierarchy, it also excluded other "tmp" directories under different paths that I don't want "find" to exclude (ie. /var/tmp, /etc/tmp, /tmp, ...)

I read that some versions of the "find" command also supports a "-wholename" variant, but I'm afraid the /usr/bin/find command on the Sun/Solaris machine I'm using doesn't seem to have it available.

Any ideas on how I can use find on sun/solaris to recursively find all the files and directories but skipping a single specific directory tree?

Thanks in advance!
# 2  
Old 02-24-2009
Not the best solution, but one alternative would be filtering out the lines that you don't need using an external command, something like ...

Code:
find . -print | egrep -v '/dir1/temp/*'

AFAIK -wholename option is GNU specific.
# 3  
Old 03-23-2009
Quote:
Originally Posted by rubin
Not the best solution, but one alternative would be filtering out the lines that you don't need using an external command, something like ...

Code:
find . -print | egrep -v '/dir1/temp/*'

AFAIK -wholename option is GNU specific.
What about if I was wanting to delete files using this mehod?

Code:
find . -name "*" -type f -exec rm {} \; | egrep -v './abc/*'

Something like that, except that deletes everything because the egrep is ran after the find command.
# 4  
Old 03-23-2009
Quote:
Originally Posted by cbo0485
...Something like that, except that deletes everything because the egrep is ran after the find command.
Exactly, when egrep comes it's too late, rm has already done its job ..., try something like this instead:

Code:
find . -type f | egrep -v '\./abc/.*' | xargs rm

Proceed carefully, this will remove files.
# 5  
Old 03-23-2009
if you wanna exclude file then use following..
Code:
find . ! -name "\./abc/.*" -type f -exec rm {} \;

# 6  
Old 03-23-2009
This takes place in Solaris, and the find's default RE ( globbing ) is limited, that's why you need a finer filter.
# 7  
Old 03-23-2009
i don't think
Code:
find . -type f | egrep -v '\./abc/.*' | xargs rm

this command and
Code:
find . ! -name "\./abc/.*" -type f -exec rm {} \;

will produce different output
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Using prune with find

Hi, I have two files under two separate directories as in: find . -name test.sh ./test.sh ./abc/test.sh I want my find to only look for the file test.sh that is under the current directory and not one under /abc How do I use prune to achieve this? I am on AIX (3 Replies)
Discussion started by: swasid
3 Replies

2. Solaris

Usage of -prune and -name in find

I am into cd /home/work/amey/history-*/ Under amey I have directories history, history-1, history-2 and under history-2 I have got 2 files 3 and 2. When I run the find command I get the below o/p. find /home/work/amey/history-*/. -name . -o -prune -type f /home/work/amey/history-1/.... (1 Reply)
Discussion started by: ameyrk
1 Replies

3. Shell Programming and Scripting

find: -prune and -name options

I am trying to find all .rhosts files on some unix systems. I tried just -name ".rhosts" but we have a lot of really large NFS and MVFS systems that I do not want to crawl and I am having a hard time excluding them. I also need to scan more than just /root /home and /users, so I really need to scan... (1 Reply)
Discussion started by: nitrobass24
1 Replies

4. Shell Programming and Scripting

Find + prune + mtime

Hi, i try to catch all files in a dir ,without going down in subdir , which don't have file extension and older than 10 days for example: my dir : drwxr-xr-x 7 notes01 notes 4096 Mar 8 14:11 . drwxr-xr-x 116 root system 4096 Mar 9 11:17 .. -rw-r----- 1 notes01... (4 Replies)
Discussion started by: Nicol
4 Replies

5. Shell Programming and Scripting

How to use -path and -prune with find

OK, I'm trying search and destroy tabs again. This time I'm having trouble excluding certain directories from my search. Here is what I have tried and it is not ignoring the top level build directory: find . -path ./build -prune -name \*.java -o -print | xargs grep -i ' ' I don't... (6 Replies)
Discussion started by: siegfried
6 Replies

6. Shell Programming and Scripting

find with prune option

Hi, I want to list files only from the current dir and its child dir (not from child's child dir). i have the following files, ./ABC/1.log ./ABC/2.log ./ABC/ABC1/A.log ./ABC/ABC1/B.log ./ABC/ABC1/XYZ/A1.log ./ABC/ABC1/XYZ/A2.log Here i want to list only the log file from current... (1 Reply)
Discussion started by: apsprabhu
1 Replies

7. UNIX for Advanced & Expert Users

how to find out pathname from inode number

Hi all when I execute pmap command on one of my daemon process, I am able to see the following output. Address Kbytes RSS Anon Locked Mode Mapped File 00010000 40 40 - - r-x-- irs026bmd 00028000 56 56 16 - rwx-- irs026bmd 00036000... (3 Replies)
Discussion started by: axes
3 Replies

8. UNIX for Dummies Questions & Answers

Using prune with find command

Hi, I am using a find command like below in my script: find /outfiles -type f -name cat -o -name vi -o -name grep 2>/dev/null Which will search for files like "cat" , "vi" or "grep" in the "/outfiles" and subdirectories. I want to ignore a particular subdirectory from the search. I... (4 Replies)
Discussion started by: deepakgang
4 Replies

9. UNIX for Dummies Questions & Answers

find command with prune help

I have a directory named https-abcd Under that I have some directories, files and links. One of those directories is with name logs and the logs directory has lot of files in it. I need to tar the whole https-abcd directory excluding the logs directory only, I should get all the links, files and... (2 Replies)
Discussion started by: venu_nbk
2 Replies

10. UNIX for Dummies Questions & Answers

find without pathname

How can I get the results of a find back without the pathname for example if i do find ../../ -name \*.sql i dont want to see directory/directory/filename.sql I only want to see filename.sql (3 Replies)
Discussion started by: MBGPS
3 Replies
Login or Register to Ask a Question