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 🙂
 
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".
 
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.
 
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.

Forum statistics

Threads
62,021
Messages
673,242
Members
5,641
Latest member
cpomd
Back
Top