tree명령 없이 ls로 treeview로 보기(Treeview without tree command as ls)
개인적으로 시스템 취약점 분석 ~ 개인 리눅스 사용 모두 tree 명령을 굉장히 자주 사용합니다. 다만 간혹, tree가 없는 환경에서 treeview로 보고 싶은 경우가 있는데, ls, grep, sed 3개를 이용하면 tree와 비슷한 형태의 출력을 얻어낼 수 있습니다.
1. ls -R 옵션으로 하위 모든 파일을 출력
2. pipe로 grep에 넘겨 directory만 뽑아냅니다. (Directory만 볼 경우)
3. pipe로 sed로 넘겨 tree와 비슷하게 출력 포맷을 맞춰줍니다.
hbxss(https://github.com/hahwul/hbxss) 코드로 테스트해봅시다.
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와 비슷하게 출력 포맷을 맞춰줍니다.
hbxss(https://github.com/hahwul/hbxss) 코드로 테스트해봅시다.
Directory
#> ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/'
.
|-hbxss
|---app
|-----assets
|-------config
|-------images
|-------javascripts
|---------channels
|-------stylesheets
|-----channels
|-------application_cable
|-----controllers
|-------concerns
|-----helpers
|-----jobs
|-----mailers
|-----models
|-------concerns
|-----views
|-------layouts
|-------logs
|---bin
|---config
|-----environments
|-----initializers
|-----locales
|---db
|-----migrate
|---lib
|-----assets
|-----tasks
|---log
|---public
|---test
|-----controllers
|-----fixtures
|-------files
|-----helpers
|-----integration
|-----mailers
|-----models
|-----system
|---tmp
|---vendor
Files
#> ls -R | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/'
.
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
controllers
helpers
jobs
mailers
models
views
|-----assets
config
images
javascripts
stylesheets
|-------config
manifest.js
|-------images
|-------javascripts
application.js
cable.js
channels
logs.coffee
|---------channels
|-------stylesheets
application.css
logs.scss
scaffolds.scss
|-----channels
application_cable
|-------application_cable
channel.rb
connection.rb
|-----controllers
application_controller.rb
concerns
logs_controller.rb
|-------concerns
|-----helpers
application_helper.rb
logs_helper.rb
|-----jobs
application_job.rb
|-----mailers
application_mailer.rb
|-----models
application_record.rb
concerns
log.rb
|-------concerns
|-----views
layouts
logs
|-------layouts
application.html.erb
mailer.html.erb
mailer.text.erb
|-------logs
edit.html.erb
_form.html.erb
index.html.erb
index.json.jbuilder
_log.json.jbuilder
new.html.erb
savelog.html.erb
show.html.erb
show.json.jbuilder
|---bin
bundle
rails
rake
setup
spring
update
yarn
|---config
application.rb
boot.rb
cable.yml
database.yml
environment.rb
environments
initializers
locales
puma.rb
routes.rb
secrets.yml
spring.rb
|-----environments
development.rb
production.rb
test.rb
|-----initializers
application_controller_renderer.rb
assets.rb
backtrace_silencers.rb
cookies_serializer.rb
filter_parameter_logging.rb
inflections.rb
mime_types.rb
wrap_parameters.rb
|-----locales
en.yml
|---db
migrate
schema.rb
seeds.rb
|-----migrate
20171110094537_create_logs.rb
20171120023128_addreferer_to_log.rb
20171120023639_addreferer_to_logs.rb
20171120023958_addreferer_tologs.rb
20171120024103_add_referer_to_log.rb
|---lib
assets
tasks
|-----assets
|-----tasks
|---log
|---public
404.html
422.html
500.html
apple|touch-icon.png
apple|touch-icon-precomposed.png
favicon.ico
index.html
logo.png
payload.js
robots.txt
|---test
application_system_test_case.rb
controllers
fixtures
helpers
integration
mailers
models
system
test_helper.rb
|-----controllers
logs_controller_test.rb
|-----fixtures
files
logs.yml
|-------files
|-----helpers
|-----integration
|-----mailers
|-----models
log_test.rb
|-----system
logs_test.rb
|---tmp
|---vendor