"-maxdepth 1" argument for Solaris find. Other way to restrict find in only one directory?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers "-maxdepth 1" argument for Solaris find. Other way to restrict find in only one directory?
# 1  
Old 11-17-2011
"-maxdepth 1" argument for Solaris find. Other way to restrict find in only one directory?

Hi

I wish to find only files in dir /srv/container/content/imz06/. It means exclude subfolder /srv/container/content/imz06/archive/

Code:
> uname -a
SunOS testbox6 5.10 Generic_139555-08 sun4v sparc SUNW,Sun-Blade-T6320

Its Solaris default "find"

Code:
> find /srv/container/content/imz06/* -name "Output_Z_1_*" -type f -mtime +2 -exec mv {} /srv/container/content/imz06/archive/ \;
mv: /srv/container/content/imz06/archive/Output_Z_1_1387868585.Output_Z_1 and /srv/container/content/imz06/archive/Output_Z_1_1387868585.Output_Z_1 are identical
mv: /srv/container/content/imz06/archive/Output_Z_1_403754036.res and /srv/container/content/imz06/archive/Output_Z_1_403754036.res are identical
mv: /srv/container/content/imz06/archive/Output_Z_1_1905205135.Output_Z_1 and /srv/container/content/imz06/archive/Output_Z_1_1905205135.Output_Z_1 are identical
mv: /srv/container/content/imz06/archive/Output_Z_1_ext1692374936.Output_Z_1 and /srv/container/content/imz06/archive/Output_Z_1_ext1692374936.Output_Z_1 are identical
mv: /srv/container/content/imz06/archive/Output_Z_1_ext312589099.res and /srv/container/content/imz06/archive/Output_Z_1_ext312589099.res are identical
mv: /srv/container/content/imz06/archive/Output_Z_1_ext1189439122.Output_Z_1 and /srv/container/content/imz06/archive/Output_Z_1_ext1189439122.Output_Z_1 are identical
mv: /srv/container/content/imz06/archive/Output_Z_1_1888958124.res and /srv/container/content/imz06/archive/Output_Z_1_1888958124.res are identical
mv: /srv/container/content/imz06/archive/Output_Z_1_1387868585.res and /srv/container/content/imz06/archive/Output_Z_1_1387868585.res are identical
mv: /srv/container/content/imz06/archive/Output_Z_1_403754036.Output_Z_1 and /srv/container/content/imz06/archive/Output_Z_1_403754036.Output_Z_1 are identical
mv: /srv/container/content/imz06/archive/Output_Z_1_1888958124.Output_Z_1 and /srv/container/content/imz06/archive/Output_Z_1_1888958124.Output_Z_1 are identical
mv: /srv/container/content/imz06/archive/Output_Z_1_ext1189439122.res and /srv/container/content/imz06/archive/Output_Z_1_ext1189439122.res are identical
mv: /srv/container/content/imz06/archive/Output_Z_1_ext312589099.Output_Z_1 and /srv/container/content/imz06/archive/Output_Z_1_ext312589099.Output_Z_1 are identical
mv: /srv/container/content/imz06/archive/Output_Z_1_ext1692374936.res and /srv/container/content/imz06/archive/Output_Z_1_ext1692374936.res are identical
mv: /srv/container/content/imz06/archive/Output_Z_1_1905205135.res and /srv/container/content/imz06/archive/Output_Z_1_1905205135.res are identical

# 2  
Old 11-17-2011
Hi.

I don't have those paths, but as an idea:
Code:
$ find ./tmp/* -type f -name file1                     
./tmp/B/file1
./tmp/file1

$ find ./tmp/* -type f -path tmp/ -o -prune -name file1
./tmp/file1

This User Gave Thanks to Scott For This Post:
# 3  
Old 11-17-2011
thats my find

Code:
User Commands                                             find(1)

NAME
     find - find files

SYNOPSIS
     /usr/bin/find  [-H |  -L] path... expression

     /usr/xpg4/bin/find  [-H |  -L] path... expression

there is no such option "-path"

Code:
find: bad option -path
find: [-H | -L] path-list predicate-list

Code:
> which find
/bin/find

# 4  
Old 11-17-2011
Ah! And not even /usr/xpg4/bin/find can help us. My ability to master some of the find command options is limited!

So here's a quick hack that might work, but it means replacing exec with xargs.

Code:
# find ./tmp/* -name file1 | grep -v /tmp/[^/]*/
./tmp/file1
#                                              
# mkdir tmp2
# find ./tmp/* -name file1 | grep -v /tmp/[^/]*/ | xargs -n1 -I{} mv {} tmp2
# ll tmp2
total 18
drwxr-xr-x   2 root     root         512 Nov 17 13:13 .
drwxr-xr-x  22 root     root        7680 Nov 17 13:13 ..
-rw-r--r--   1 root     root           0 Nov 17 13:09 file1

Code:
# uname -a
SunOS sol10 5.10 Generic_141445-09 i86pc i386 i86pc

# 5  
Old 11-18-2011
To find all files under a directory (not including sub directories) without using maxdepth:
Code:
find /full/path/dir \( ! -name dir -o -type f \) -prune -type f

Here we use prune to not descending to and directory other than "dir". But if you happen to have a file called "dir" under the directory "dir", it will not be included, thus the "-o -type f" part. If you are sure it won't happen, then you can omit that.
These 3 Users Gave Thanks to binlib For This Post:
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

find . -path "*_nobackup*" -prune -iname "*.PDF" \( ! -name "*_nobackup.*" \)

These three finds worked as expected: $ find . -iname "*.PDF" $ find . -iname "*.PDF" \( ! -name "*_nobackup.*" \) $ find . -path "*_nobackup*" -prune -iname "*.PDF" They all returned the match: ./folder/file.pdf :b: This find returned no matches: $ find . -path "*_nobackup*" -prune... (3 Replies)
Discussion started by: wolfv
3 Replies

2. Shell Programming and Scripting

Find lines with "A" then change "E" to "X" same line

I have a bunch of random character lines like ABCEDFG. I want to find all lines with "A" and then change any "E" to "X" in the same line. ALL lines with "A" will have an "X" somewhere in it. I have tried sed awk and vi editor. I get close, not quite there. I know someone has already solved this... (10 Replies)
Discussion started by: nightwatchrenba
10 Replies

3. UNIX for Dummies Questions & Answers

find/xargs/*grep: find multi-line empty "try-catch" blocks - eg, missing ; not in a commented block

How can I recursively find all files in a directory and print out the file and first line number of any text blocks that match the below cases? This would seem to involve find, xargs, *grep, regex, etc. In summary, I want to find so-called empty "try-catch blocks" that do not contain code... (0 Replies)
Discussion started by: lifechamp
0 Replies

4. Shell Programming and Scripting

Using sed to find text between a "string " and character ","

Hello everyone Sorry I have to add another sed question. I am searching a log file and need only the first 2 occurances of text which comes after (note the space) "string " and before a ",". I have tried sed -n 's/.*string \(*\),.*/\1/p' filewith some, but limited success. This gives out all... (10 Replies)
Discussion started by: haggismn
10 Replies

5. Shell Programming and Scripting

"find . -printf" without prepended "." path? Getting path to current working directory?

If I enter (simplified): find . -printf "%p\n" then all files in the output are prepended by a "." like ./local/share/test23.log How can achieve that a.) the leading "./" is omitted and/or b.) the full path to the current directory is inserted (enclosed by brackets and a blank)... (1 Reply)
Discussion started by: pstein
1 Replies

6. Shell Programming and Scripting

find error?? find / -name "something.txt" 2>/dev/null

why is this giving me errors? i type this in: find / -name "something.txt" 2>/dev/null i get the following error messages: find: bad option 2 find: path-list predicate-list :confused: (5 Replies)
Discussion started by: magiling
5 Replies

7. Solaris

Find all "regular" files open for write on solaris?

How do I find all "regular" files on solaris(8) that are open for write ( +read as well). I tried using pfiles, and lsof commands, but not sure how to get exactly what I wanted. ps -e | awk '{ print $1 }' | xargs -i pfiles {} 2>/dev/null (10 Replies)
Discussion started by: kchinnam
10 Replies

8. Shell Programming and Scripting

Error to "find" a matching array element in a directory

Hi, I have defined an array which holds a couple of elements which are nothing but files names. I want to find the files in a directory for the matching file name(array elements) with less than 1 day old. When I am trying to execute the code (as below), it gives an error. Your help in this... (1 Reply)
Discussion started by: mkbaral
1 Replies

9. Shell Programming and Scripting

"find command" to find the files in the current directories but not in the "subdir"

Dear friends, please tell me how to find the files which are existing in the current directory, but it sholud not search in the sub directories.. it is like this, current directory contains file1, file2, file3, dir1, dir2 and dir1 conatins file4, file5 and dir2 contains file6,... (9 Replies)
Discussion started by: swamymns
9 Replies

10. Shell Programming and Scripting

grep to find content in between curly braces, "{" and "},"

problem String ~~~~~~~~~~~~~~~~~~ icecream= { smart peopleLink "good" LC "happy" , smartpeopleLink "dull" LC "sad" } aend = {smart vc4 eatr kalu} output needed ~~~~~~~~~~~~~~~~~~ smart peopleLink "good" LC "happy" , smartpeopleLink "dull" LC "sad" smart vc4... (4 Replies)
Discussion started by: keshav_rk
4 Replies
Login or Register to Ask a Question

Featured Tech Videos