
たくさんのサブディレクトリとファイルを含むディレクトリがあります。各ファイル名とソースディレクトリのパス情報を提供するファイルを作成したいと思います。
例えば:
- フォルダ名sampleがあり、その中にsample1とsample2のサブディレクトリが含まれています。
- サンプル1にはex1.csv、ex2.csvがあり、サンプル2ディレクトリにはex3.csv、ex4.csvがあります。
次の方法で情報を提供するテキストファイル(または)csvファイルを作成する必要があります
ex1.csv、サンプル/サンプル1
ex2.csv、サンプル/サンプル1
ex3.csv、サンプル/サンプル2
誰かがUNIXでスクリプトファイルを作成するのを手伝ってくれたら嬉しいです
前もって感謝します
答え1
次のような構造を考えてみましょう
$ tree sample
sample
├── sample1
│ ├── ex1.csv
│ └── ex2.csv
└── sample2
├── ex3.csv
└── ex4.csv
2 directories, 4 files
使用できます
$ find sample -type f -printf '%f,%h\n'
ex2.csv,sample/sample1
ex1.csv,sample/sample1
ex3.csv,sample/sample2
ex4.csv,sample/sample2
からman find
、関連する-printf
書式指定子は次のようになります。
%f File's name with any leading directories removed (only
the last element).
%h Leading directories of file's name (all but the last ele‐
ment). If the file name contains no slashes (since it is
in the current directory) the %h specifier expands to
".".
結果をファイルに出力したい場合は、>
演算子を使用してコマンド出力をリダイレクトします。例:
find sample -type f -printf '%f,%h\n' > filelist