Toggle navigation
DevOps Knowledge
作成
作成
下書き一覧
ストック
一覧
複合検索
サインイン
更新履歴
incmplt
2018/07/05 7:04
現在との差分
過去のナレッジの内容
コンテンツ
Linuxシステムの資料を作成しているときにディレクトリ構成(ディレクトリツリー)をExcelなどでまとめたい場合に便利なワンライナー。 ## 必要なコマンド - tree - sed ## ディレクトリ構成のCSV出力コマンド ディレクトリ構成(ディレクトリツリー)を出力したいディレクトリで以下のコマンドを実行。 ```bash $ tree -a -I \.git -F -l --noreport | sed -e "s/├── /,/g" -e "s/└── /,/g" -e "s/│ /,/g" -e "s/ /,/g" -e "s/│ /,/g" ``` treeの表示は、以下のオプションで調整ができる。 - **-F** ディレクトリの後ろに /(スラッシュ)を追加する - **-l** シンボリックリンクを追跡する - **-L x** ディレクトリを x 階層分まで対象とする ## 表示例 treeを実行すると以下のように表示される。 ``` $ tree . ├── LICENSE ├── Makefile ├── README.md ├── redmine-hook-bin │ ├── issue-bluk-edit.sh │ ├── issue-edit.sh │ └── issue-new.sh └── redmine_issue_exec ├── README.rdoc ├── app │ ├── controllers │ ├── helpers │ ├── models │ └── views ├── assets │ ├── images │ ├── javascripts │ └── stylesheets ├── config │ ├── locales │ │ └── en.yml │ └── routes.rb ├── db │ └── migrate ├── init.rb ├── lib │ ├── redmine_issue_exec │ │ └── hooks.rb │ └── tasks └── test ├── fixtures ├── functional ├── integration ├── test_helper.rb └── unit 23 directories, 12 files ``` このディレクトリに対して、上記コマンドを実行すると次のような表示になる。 ``` $ tree -a -I \.git -F -l --noreport | sed -e "s/├── /,/g" -e "s/└── /,/g" -e "s/│ /,/g" -e "s/ /,/g" -e "s/│ /,/g" . ,LICENSE ,Makefile ,README.md ,redmine-hook-bin/ ,,issue-bluk-edit.sh* ,,issue-edit.sh* ,,issue-new.sh* ,redmine_issue_exec/ ,,README.rdoc ,,app/ ,,,controllers/ ,,,helpers/ ,,,models/ ,,,views/ ,,assets/ ,,,images/ ,,,javascripts/ ,,,stylesheets/ ,,config/ ,,,locales/ ,,,,en.yml ,,,routes.rb ,,db/ ,,,migrate/ ,,init.rb ,,lib/ ,,,redmine_issue_exec/ ,,,,hooks.rb ,,,tasks/ ,,test/ ,,,fixtures/ ,,,functional/ ,,,integration/ ,,,test_helper.rb ,,,unit/ ``` 空白の扱いがOSによって異なるため、`| ` など余計なtreeの表示が残ったら、該当文字列をsed の -e 部分にコピー&ペースとして条件を追加していると良い。 出力内容をファイルにリダイレクトして、ExcelなどでCSV形式で読み込むことでディレクトリ一覧のデータを簡単に作成することが出来る。
現在のナレッジの内容
コンテンツ
Linuxシステムの資料を作成しているときにディレクトリ構成(ディレクトリツリー)をExcelなどでまとめたい場合に便利なワンライナー。 ## 必要なコマンド - tree - sed ## ディレクトリ構成のCSV出力コマンド ディレクトリ構成(ディレクトリツリー)を出力したいディレクトリで以下のコマンドを実行。 ```bash $ tree -a -I \.git -F -l --noreport | sed -e "s/├── /,/g" -e "s/└── /,/g" -e "s/│ /,/g" -e "s/ /,/g" -e "s/│ /,/g" ``` treeの表示は、以下のオプションで調整ができる。 - **-F** ディレクトリの後ろに /(スラッシュ)を追加する - **-l** シンボリックリンクを追跡する - **-L x** ディレクトリを x 階層分まで対象とする - **-d** ディレクトリのみを表示する システム資料などの場合には、ディレクトリ表示までが現実的なので `-d -F -l` のオプションを付けると簡潔にディレクトリ構成のCSVを作成できる。 詳しいtrreのオプションは、マニュアルもしくは [【 tree 】コマンド――ディレクトリをツリー状に表示する(外部サイト)](http://www.atmarkit.co.jp/ait/articles/1802/01/news025.html) を参照 ## 表示例 treeを実行すると以下のように表示される。 ``` $ tree . ├── LICENSE ├── Makefile ├── README.md ├── redmine-hook-bin │ ├── issue-bluk-edit.sh │ ├── issue-edit.sh │ └── issue-new.sh └── redmine_issue_exec ├── README.rdoc ├── app │ ├── controllers │ ├── helpers │ ├── models │ └── views ├── assets │ ├── images │ ├── javascripts │ └── stylesheets ├── config │ ├── locales │ │ └── en.yml │ └── routes.rb ├── db │ └── migrate ├── init.rb ├── lib │ ├── redmine_issue_exec │ │ └── hooks.rb │ └── tasks └── test ├── fixtures ├── functional ├── integration ├── test_helper.rb └── unit 23 directories, 12 files ``` このディレクトリに対して、上記コマンドを実行すると次のような表示になる。 ``` $ tree -a -I \.git -F -l --noreport | sed -e "s/├── /,/g" -e "s/└── /,/g" -e "s/│ /,/g" -e "s/ /,/g" -e "s/│ /,/g" . ,LICENSE ,Makefile ,README.md ,redmine-hook-bin/ ,,issue-bluk-edit.sh* ,,issue-edit.sh* ,,issue-new.sh* ,redmine_issue_exec/ ,,README.rdoc ,,app/ ,,,controllers/ ,,,helpers/ ,,,models/ ,,,views/ ,,assets/ ,,,images/ ,,,javascripts/ ,,,stylesheets/ ,,config/ ,,,locales/ ,,,,en.yml ,,,routes.rb ,,db/ ,,,migrate/ ,,init.rb ,,lib/ ,,,redmine_issue_exec/ ,,,,hooks.rb ,,,tasks/ ,,test/ ,,,fixtures/ ,,,functional/ ,,,integration/ ,,,test_helper.rb ,,,unit/ ``` 空白の扱いがOSによって異なるため、`| ` など余計なtreeの表示が残ったら、該当文字列をsed の -e 部分にコピー&ペースとして条件を追加していると良い。 出力内容をファイルにリダイレクトして、ExcelなどでCSV形式で読み込むことでディレクトリ一覧のデータを簡単に作成することが出来る。
戻る