2017-02-27 45 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