• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

how to list recursive dirs only using ls

Dark Atheist

Staff member
Political User
atm im trying

ls * >> list.txt but its only going 2 folders deep - i require 3 maybe 4 and just to list the dirs - not their content

using -R lists the files before anyone says - i did try that, and yes i have also done man ls :)

Dark Atheist

Staff member
Political User
thanks lord, was looking at the tree option also, will try your suggestion out in a bit, if it works and if i can reps will be coming your way, if i cant you get a cookie :)
It varies from OS to OS but you sometimes need to include the -print option in find to have it print out the things it finds. Also if you have directories with spaces in them you can use -print0 to have find print a NULL byte at the end of each found item. This is mainly useful for teaming with "| xargs -0".


Political User
My solution is cooler than the find solution proposed above:

ls -Rl * | egrep -E "^d........" | rev | awk '{ print $1 }' | rev
However, that won't list full paths of the directories involved, and can cause duplicates.

ls -Rl / | grep ".*/.*:$" | sed "s/\:$//"
Lists just directories as found by ls.

Dark Atheist

Staff member
Political User
thanks X - although i guess i should have put the dir i wanted to list n there instead of the / - as i only require one folder and its sub dirs not the whole filesystem :p

Members online

Latest posts

Latest profile posts

Perris Calderon wrote on Electronic Punk's profile.
Ep, glad to see you come back and tidy up...did want to ask a one day favor, I want to enhance my resume , was hoping you could make me administrator for a day, if so, take me right off since I won't be here to do anything, and don't know the slightest about the board, but it would be nice putting "served administrator osnn", if can do, THANKS

Been running around Quora lately, luv it there https://tinyurl.com/ycpxl
Electronic Punk wrote on Perris Calderon's profile.
All good still mate?
Hello, is there anybody in there? Just nod if you can hear me ...
What a long strange trip it's been. =)

Forum statistics

Latest member