Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Really easy question about ls 2

Status
Not open for further replies.

Stretchwickster

Programmer
Apr 30, 2001
1,746
GB
I'm trying to display all the entries in my home directory that are directories rather than files. I've tried using ls -d as indicated in the man pages for ls but this just gives me a dot as output. Can anyone help?
 
Stretch:

How about writing your own? Give me everything that starts with 'd':

ls -l |awk ' { if($0 ~ /^d/)
print $0 } '

Regards,

Ed
Schaefer
 
Don't forget those hidden directories. Note: some have '/' at the end.

ls -la | awk '/^d/{print $9}'
ls -aF | grep /
find .* ./* -type d -prune

Cheers,
ND [smile]
 
I like to set an alias in my .profile for listing only directories.

ksh:

Code:
alias -x lsd='ls -l | grep ^d'

that way you can see all the subdirectories of the current directory by typing lsd

Someone asked a while ago about a command that would accept a parameter that is a specific directory to start from. It was determined that a function would be the best way to handle that.

Code:
dir () {
  ls -l $1 | awk '{ if (substr($1,1,1)=="d") {print}}'
}

You could put that in your .profile or .kshrc. However, I think the awk reference could be replaced with grep. Einstein47
(Love is like PI - natural, irrational, endless, and very important.)
 
Robert was the closest with his 'find' but you can even cut that down to: find . -type d

you don't need the ... './*' or the '-prune'


Adam
 
Trust me to open my GOB without thinking!

Mikes option misses directories with a leading '.' and mine gives repeated output.

So.... I had a re-think and mofified Mikes other option. This works a treat!

ls -aF|grep /|tr -d '/'|grep -vw '.'



Adam
 
Another way:
Code:
find . ! -name . -type d -print -prune
Cheers, Neil
 
Neil,

What does the ! do? Is it "not"? Mike
"Experience is the comb that Nature gives us after we are bald."

Is that a haiku?
I never could get the hang
of writing those things.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top