如果你要打印的文件夾內容的一個漂亮的樹和它的子文件夾,您可以使用「樹」。
如果這不是你的系統上安裝,你必須這樣做第一:
sudo apt-get install tree
那麼語法是非常簡單的。如果你想輸出保存到一個文件:
tree -h -A path/to/dir > output.txt
-A
用於確保輸出使用ASCII字符。
-h
將以人們可讀的格式打印每個文件大小。
您有更多的選擇來限制輸出,您可以通過使用「--help」選項得到:
> tree --help
-a All files are listed.
-d List directories only.
-l Follow symbolic links like directories.
-f Print the full path prefix for each file.
-L level Descend only level directories deep.
-o filename Output to file instead of stdout.
-s Print the size in bytes of each file.
-h Print the size in a more human readable way.
--dirsfirst List directories before files (-U disables).
感謝sharpner,就像一個魅力。怎麼打印文件大小? – Jim 2011-03-23 16:37:52
ls -la或-ls -lach不管你看起來不錯 – sharpner 2011-03-23 16:38:42
對不起,但我不明白。如果[$#-gt 0];然後 ls $ 1> textfile.txt ls -la不能按我想要的方式工作。我想有filename1 size1(在第一行)filename2 size2(在第二行)等...對不起,所有的麻煩 – Jim 2011-03-23 16:44:51