[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Find behavior (HP UNIX 11)

Posted on 2006-05-10
6
Medium Priority
?
400 Views
Last Modified: 2013-12-26
Hi Exprts,

I have to use a "find" command to list all files of a directory avoiding the files in any of the sub-directory:

If following is a diroctory structure:

-----------------------<START of dir structure >-----------------

/dir1/sdir2:

file1
file2
file3
dir1
dir2

/dir1/sdir2/dir1:

file4
file5

/dir1/sdir2/dir2:

file6
file7

-----------------------<END of dir structure >-----------------

I would like to list only files under "/dir1/sdir2" :

file1
file2
file3



Thanks in advance.
0
Comment
Question by:myrizvi
  • 3
  • 2
6 Comments
 
LVL 65

Expert Comment

by:rockiroads
ID: 16649112
Not sure if -prune would be helpful here

Alternative is to create your own shellscript, make use of the test command


test -f <name>  returns true if <name> is a file

e.g.


for i in `ls /dir1`          
do                    
        if test -f $i  
        then          
                echo $i
        fi            
done                  
0
 
LVL 7

Accepted Solution

by:
glassd earned 375 total points
ID: 16650975
&#65279;find *  \( -type d -a -prune \) -o -print
works in Solaris and Linux
0
 

Author Comment

by:myrizvi
ID: 16673207
Hi Exprts,

Sorry for late response.

I am accepting "glassd's" solution as I want to use "find" tool only.

This one is also doing the same:

# find ./dir1/sdir2/ -type f ! -path "./dir1/sdir2/*/*"

Thanks to you all.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:myrizvi
ID: 16673215
Hi Glassd,

One thing I want to mention that your find command doesnt work if I put pathname instead of "*" :


# find *  \( -type d -a -prune \) -o -print      <-------- Working fine

# find /dir1/sdir2 \( -type d -a -prune \) -o -print      <-------------- not working

Isnt it strange?
0
 
LVL 7

Expert Comment

by:glassd
ID: 16680165
No, you would need /dir1/sdir2/*, otherwise it prunes the specified directory and does not descend into it.
0
 

Author Comment

by:myrizvi
ID: 16688463
Thanks galssd, u were right.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Suggested Courses
Course of the Month19 days, 6 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question