how to list recursive dirs only using ls

Dark Atheist

OSNN Veteran Addict
Political Access
Joined
8 Apr 2003
Messages
6,376
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

OSNN Veteran Addict
Political Access
Joined
8 Apr 2003
Messages
6,376
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 🙂
 

Geffy

OSNN Veteran Addict
Joined
18 Mar 2002
Messages
7,805
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".
 

X-Istence

*
Political Access
Joined
5 Dec 2001
Messages
6,498
My solution is cooler than the find solution proposed above:

Code:
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.

Code:
ls -Rl / | grep ".*/.*:$" | sed "s/\:$//"

Lists just directories as found by ls.
 

Dark Atheist

OSNN Veteran Addict
Political Access
Joined
8 Apr 2003
Messages
6,376
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 😛
 

Members online

No members online now.

Latest profile posts

Xie Electronic Punk Xie wrote on Electronic Punk's profile.
Impressed you have kept this alive this long EP! So many sites have come and gone. 🙁

Just did some crude math and I apparently joined almost 18yrs ago, how is that possible???
hello peeps... is been some time since i last came here.
Electronic Punk Sazar Electronic Punk wrote on Sazar's profile.
Rest in peace my friend, been trying to find you and finally did in the worst way imaginable.
Terrahertz Electronic Punk Terrahertz wrote on Electronic Punk's profile.
Yo fellas!
Electronic Punk Sazar Electronic Punk wrote on Sazar's profile.
Where are you buddy?

Forum statistics

Threads
62,017
Messages
673,508
Members
5,636
Latest member
GLOCKTOR642
Back