개인적으로 tree 명령을 굉장히 자주 사용합니다. 다만 간혹, tree가 없는 환경에서 treeview로 보고 싶은 경우가 있는데, ls, grep, sed 3개를 이용하면 tree와 비슷한 형태의 출력을 얻어낼 수 있습니다.

ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/'
  1. ls -R 옵션으로 하위 모든 파일을 출력
  2. pipe로 grep에 넘겨 directory만 뽑아냅니다. (Directory만 볼 경우)
  3. pipe로 sed로 넘겨 tree와 비슷하게 출력 포맷을 맞춰줍니다.

Directory

Command

ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/'

Output

 .
 |-hbxss
 |---app
 |-----assets
 |-------config
 |-------images
 |-------javascripts
 |---------channels
 |-------stylesheets
 |-----channels
 |-------application_cable
 |-----controllers
 ....

Files

Command

ls -R | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/'

Output

 .
 db_reset.txt
 hbxss
 LICENSE
 README.md
 update.rb

 |-hbxss
 app
 bin
 config
 config.ru
 db
 Gemfile
 Gemfile.lock
 lib
 log
 package.json
 public
 Rakefile
 README.md
 test
 tmp
 vendor

 |---app
 assets
 channels
 ...