Solved

Solaris find command- ignore subdirectories

Posted on 2008-06-11
5
1,684 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
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 …
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 navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

733 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