2017-03-08 39 views
0

請您在bash shell中澄清我的疑問。我使用的是命令列出前10個文件如何使用輸入的命令輸出列出具有時間戳和大小的文件

命令顯示前10個大文件

du -ah|sort -rh|head -n 10 

但它列出輸出

size filename 
3.0 MB test.xml 
..... ....... 
..... ....... 
so on 

我想要顯示的時間戳和權限,所以我試圖:

du -ah|sort -rh|head -n 10|xargs ls -lrt '{}' 

du -ah|sort -rh|head -n 10|awk '{print $2}'|while read i; do ls -lrt $i;done 

但他們都沒有工作

你能提供建議嗎?我想用du命令只

+0

我很困惑,你說你想用'du' onl但是,在你試圖用'ls'試着'du'的時候。你爲什麼不使用'ls'?無論如何,使用'du - time'參數你也可以得到日期。 –

回答

0

ls -lSh | head -10 | awk '{print $5 " " $1 " " $6 " " $7 " " $8 " " $9}' 

包括你可以使用查找所有子目錄:

find . -type f -exec ls -l {} \; | sort -nrk5 | head -10 

這是沒有效率的,你會得到的文件大小不是人類可讀的形式,但它做的工作:

[[email protected] /etc]# find . -type f -exec ls -l {} \; | sort -nrk5 | head -10 2>/dev/null 
    -r--r--r-- 1 root root 7259752 Jan 30 15:32 ./udev/hwdb.bin 
    -rw-r--r-- 1 root root 3703827 Jan 30 15:28 ./selinux/targeted/policy/policy.30 
    -rw-r--r-- 1 root root 3703827 Jan 30 15:28 ./selinux/targeted/active/policy.kern 
    -rw-r--r-- 1 root root 1394978 Jan 30 15:28 ./selinux/targeted/contexts/files/file_contexts.bin 
    -rw-r--r-- 1 root root 670293 Jun 7 2013 ./services 
    -rw-r--r-- 1 root root 384788 Apr 18 2016 ./vmware-tools/locations 
    -rw-r--r-- 1 root root 378732 Jan 30 15:28 ./selinux/targeted/contexts/files/file_contexts 
    -rw------- 1 root root 378732 Jan 30 15:28 ./selinux/targeted/active/file_contexts 
    -rw-r--r-- 1 root root 368001 Apr 15 2016 ./selinux/targeted/contexts/files/file_contexts.pre 
    -r--r--r-- 1 root root 346654 Jan 30 15:26 ./pki/ca-trust/extracted/openssl/ca-bundle.trust.crt 
+0

謝謝 - 馬里奧凱勒和zumo-de-vidrio –

+0

謝謝 - 馬里奧凱勒,但如何獲得子目錄文件列表以及? - 因爲我不想使用find命令。是ls和du中的其他選項嗎? –

+0

你只需要子目錄或任何子目錄內的所有文件(遞歸)的大小?我認爲沒有發現就不那麼簡單。 –