how to list recursive dirs only using ls

Discussion in 'Linux & BSD' started by Dark Atheist, Sep 15, 2008.

  1. Dark Atheist

    Dark Atheist Moderator Political User Folding Team

    Messages:
    6,376
    Location:
    In The Void
    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 :)
     
  2. LordOfLA

    LordOfLA Godlike!

    Messages:
    7,027
    Location:
    Maidenhead, Berkshire, UK
    hmm "find . -type d" should do the trick for you :)
     
    Dark Atheist likes this.
  3. falconguard

    falconguard Carbon based lifeform Political User Folding Team

    Messages:
    3,406
    Location:
    SoCal
    ls -R ~/dir
     
    Dark Atheist likes this.
  4. LordOfLA

    LordOfLA Godlike!

    Messages:
    7,027
    Location:
    Maidenhead, Berkshire, UK
    that won't do what he wants :)

    my find command will :)
     
  5. zeke_mo

    zeke_mo (value not set) Staff Member Political User Folding Team

    Messages:
    1,984
    Location:
    Placerville, CA


    Yeah stupid...geez






    :lick:
     
  6. Dark Atheist

    Dark Atheist Moderator Political User Folding Team

    Messages:
    6,376
    Location:
    In The Void
    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 :)
     
  7. Geffy

    Geffy Moderator Folding Team

    Messages:
    7,805
    Location:
    United Kingdom
    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".
     
  8. X-Istence

    X-Istence * Political User

    Messages:
    6,498
    Location:
    USA
    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 likes this.
  9. Dark Atheist

    Dark Atheist Moderator Political User Folding Team

    Messages:
    6,376
    Location:
    In The Void
    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
     
  10. X-Istence

    X-Istence * Political User

    Messages:
    6,498
    Location:
    USA
    So replace / with the directory.
     
  11. Dark Atheist

    Dark Atheist Moderator Political User Folding Team

    Messages:
    6,376
    Location:
    In The Void