Bash 如何使用命令输出的输入列出带有时间戳和大小的文件
你能在bash shell中澄清我的疑问吗。我正在使用命令列出前10个文件 命令显示前10个大文件 但它将输出列为Bash 如何使用命令输出的输入列出带有时间戳和大小的文件,bash,shell,sh,Bash,Shell,Sh,你能在bash shell中澄清我的疑问吗。我正在使用命令列出前10个文件 命令显示前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}'|whil
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
命令
ls -lSh | head -10 | awk '{print $5 " " $1 " " $6 " " $7 " " $8 " " $9}'
包括您可以使用的所有子目录查找:
find . -type f -exec ls -l {} \; | sort -nrk5 | head -10
这是不高效的,而且您得到的文件大小不是人类可读的形式,但它可以完成以下任务:
[root@myserver /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
我很困惑,你说你只想使用
du
,但是在你的尝试中,你是在用ls
尝试du
。为什么不只使用ls
?无论如何,使用du--time
参数,您还可以获得日期。谢谢-Mario Keller和zumo de Vidrio谢谢-Mario Keller,但是如何获得子目录文件列表呢因为我不想使用find命令。ls和du中是否有其他选项?是否只需要子目录的大小或子目录中的所有文件(递归)?我认为没有发现就没有那么简单。
[root@myserver /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