[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: display directories only



On Mon, 05 Jan 2004 08:47:38 -0600
Rick Weinbender <rwein@central-ph.k12.mo.us> wrote:

> I have a basic question.
> Is there a method using "ls" from the command line to
> have it display only directories.
> I've looked thru the help (ls --help), but cant' guess the right
> switches.
> 
> Thanks,
> -Rick

I don't know if this is of any use; it's what I use:-

==============================================
#!/bin/sh
# ldirs - Richard Kimber
# 
# By default ldirs lists all the sub-directories in the current directory
# in columns. It has the syntax:  ldirs [-h] [<path of directory>]
# -h will cause dot directories not to be listed
# specifying a directory path will list the sub-directories in the
# directory specified. ldirs --version  will print the version number of
# ldirs ldirs --help  will print a simple help message
ver="0.1"
date="6 Dec 2000"
arg1="$1"
arg2="$2"
narg=$#
if [ ${#arg1} -eq 1 ]
then
num1=`expr ${#arg1} + 1`
num2=`expr ${#arg2} + 1`
else
num1=`expr ${#arg1} + 2`
num2=`expr ${#arg2} + 2`
fi
if [ $narg -eq 0 ]
then
	     find . -type d -maxdepth 1|sed s/"^.\/"//g|sort|tail +2|column
elif [ $narg -eq 1 -a "$arg1" = "-h" ]
then
	     find . -type d -maxdepth 1|sed s/^".\/"//g|sort|sed /^"\."/d|column
elif [ $narg -eq 1 -a "$arg1" = "--help" ]
then
             echo
             echo "ldirs ver $ver Richard Kimber $date"
             echo "       ldirs [-h][<path>]"
             echo "-h  hides dot files"
             echo "By default ldirs lists the current directory"
             echo "a path argument lists directories in that path"
             echo "ldirs --version  gives the version number"
             echo "ldirs --help  lists this help"
elif [ $narg -eq 1 -a $arg1 = '--version' ]
then
             echo "ldirs ver $ver"
elif [ $narg -eq 1 -a ! -d $arg1 ]
then
             echo "path does not exist"
elif [ $narg -eq 1 -a -d $arg1 ]
then
             find $arg1 -type d -maxdepth 1|cut -b $num1-|sort|column
elif [ $narg -eq 2 -a ! -d $arg2 ]
then
             echo "path does not exist, or parameters in wrong order" 
elif [ $narg -eq 2 -a -d $arg2 ]
then
             find $arg2 -type d -maxdepth 1|cut -b $num2-|sort|sed
/^"\."/d|column
else
             echo
             echo "Aaargh! ldirs does not understand"
             echo "ver $ver by Richard Kimber $date"
             echo "      ldirs [-h][<path>]"
             echo "-h  hides dot files"
             echo "by default ldirs lists the current directory"
             echo "a path argument lists directories in that path"
             echo "ldirs --version  gives the version number"
             echo "ldirs --help  lists this help"
fi
==========================================================

- Richard.
-- 
Richard Kimber
http://www.psr.keele.ac.uk/



Reply to: