Solved

Solaris find command- ignore subdirectories

Posted on 2008-06-11
5
1,664 Views
Last Modified: 2013-12-27
I am looking for a simple script to do some cleanup on directories older than n days.  As part of that script, I need to do a find on directories within my pwd.  However, I only want the top level directories returned, not subdirectories.

For instance, give the following:
ls
/mydir
/mydir/myotherdir/mythirddir
/yourdir
/yourdir/yourotherdir/yourthirddir
file.txt
file.sh

I only want my find command to return mydir and yourdir

Again, this is on solaris, so I don't have maxdepth.
0
Comment
Question by:krussell222
5 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 21763651
do you have -prune
0
 
LVL 84

Accepted Solution

by:
ozo earned 200 total points
ID: 21763689
find .  ! -name . -prune
0
 

Author Comment

by:krussell222
ID: 21763694
yes
0
 
LVL 40

Assisted Solution

by:omarfarid
omarfarid earned 200 total points
ID: 21765918
try

ls | while read line
do
   if [ -d $line ]
   then
        echo $line
   fi
done
0
 
LVL 48

Assisted Solution

by:Tintin
Tintin earned 100 total points
ID: 21766114

ls -1F|grep /

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

864 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now