Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

One liner to print a file system tree on UNIX like systems

by ciderpunx (Vicar)
on Aug 21, 2013 at 13:08 UTC ( [id://1050343]=CUFP: print w/replies, xml ) Need Help??

I just had occasion to type this and thought I'd share (fairly sure someone will have done this before, but my search-fu fails me).
ls -R | perl -ne 'if(/:$/){s/:$//;s/[^\/]*\//--/g;s/^-/\t|/;print}'
Result:
$ ls -R | perl -ne 'if(/:$/){s/:$//;s/[^\/]*\//--/g;s/^-/\t|/;print}' |---branches |---hooks |---info |---logs |-----refs |-------heads |-------remotes |---------origin |---objects |-----02 |-----0a |-----10 |-----24 |-----27 |-----3f |-----41 |-----4e |-----64 |-----69 |-----6e |-----70 |-----74 |-----76 |-----7b |-----82 |-----8d |-----94 |-----a7 |-----ac |-----b0 |-----b7 |-----d6 |-----dd |-----e2 |-----info |-----pack |---refs |-----heads |-----remotes |-------origin |-----tags |-Spider |---Muffet |-----Filter |-------Reader |-----Output |-------Writer


Replies are listed 'Best First'.
Re: One liner to print a file system tree on UNIX like systems
by toolic (Bishop) on Aug 21, 2013 at 13:35 UTC
    Golf! Fewer strokes...
    ls -R | perl -ne'if(s/:$//){s{[^/]*/}{--}g;s/^-/\t|/;print}'

    Or just tree -d

Re: One liner to print a file system tree on UNIX like systems
by goldenblue (Acolyte) on Oct 02, 2013 at 19:17 UTC
    That's actually pretty nice!

    --
    the singularity will happen.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: CUFP [id://1050343]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (4)
As of 2025-06-16 19:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.