2017-02-27 34 views
1

我想輸出如下面的例子所示。獲取與其絕對路徑hirarchically文件列表

[email protected]:~/.atom# du -sh */* | awk '{print $2}' 
blob-store/BLOB 
blob-store/INVKEYS 
blob-store/MAP 
compile-cache/less 
compile-cache/root 
compile-cache/style-manager 
packages/README.md 
storage/application.json 
[email protected]:~/.atom# 

但是,ls並沒有給出它的任何選項/參數的輸出。 'ls -R'給出路徑,然後其內容不是具有其絕對路徑的文件名。

我在編寫腳本時經常需要這個,有人可以幫助我嗎?感謝提前堆。

+1

可能的重複[如何列出文件的絕對路徑在Linux?](http://stackoverflow.com/questions/246215/how-can-i-list-files-with-their-absolute -path-in-linux) – putonspectacles

+0

請參閱http://stackoverflow.com/questions/246215/how-can-i-list-files-with-their-absolute-path-in-linux – putonspectacles

回答

0

您可以使用find,一個例子深度2:

find . -maxdepth 2 -mindepth 2 -printf '%P\n' 

如果要排除點文件:如果要對結果進行分類(如du -sh

find . -maxdepth 2 -mindepth 2 -not -path '*/\.*' -printf '%P\n' 

find . -maxdepth 2 -mindepth 2 -not -path '*/\.*' -printf '%P\n' | sort 
+0

非常感謝你解決這個問題完美。非常感謝伯特朗:) – Akplive139

+0

很高興幫助,如果你的問題解決了,你可以接受答案 –

0

試試這個 -

find/-name "*" |head 
/
/var 
/var/games 
/var/yp 
/var/kerberos 
/var/kerberos/krb5 
/var/kerberos/krb5/user 
/var/.updated 
/var/nis 
/var/account