Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

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

by ciderpunx (Vicar)
on Aug 21, 2013 at 13:08 UTC ( #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


Comment on One liner to print a file system tree on UNIX like systems
Select or Download Code
Re: One liner to print a file system tree on UNIX like systems
by toolic (Chancellor) 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 (Initiate) 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
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? | Other CB clients
Other Users?
Others musing on the Monastery: (13)
As of 2014-10-24 17:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (133 votes), past polls