Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux:如何按时间对给定目录进行排序,并列出文件/目录的大小_Linux_Bash - Fatal编程技术网

Linux:如何按时间对给定目录进行排序,并列出文件/目录的大小

Linux:如何按时间对给定目录进行排序,并列出文件/目录的大小,linux,bash,Linux,Bash,在Linux中,您可以使用 ls -lt <dir> ls-lt 根据修改时间列出文件/目录 你也可以使用 du -hs <dir>/* du-hs/* 看看尺寸 如何将两者结合起来以获得按时间排序的文件/目录的大小?请尝试以下选项: ls-lt | xargs du-hs 或 du-hs*| sort-h 或 du-k*| sort-nr | cut-f2 | xargs-d'\n'du-sh 此操作适用于当前目录中的目录。 如果任何目录名包含换行符,它将中断。

在Linux中,您可以使用

ls -lt <dir>
ls-lt
根据修改时间列出文件/目录

你也可以使用

du -hs <dir>/*
du-hs/*
看看尺寸

如何将两者结合起来以获得按时间排序的文件/目录的大小?

请尝试以下选项:

ls-lt | xargs du-hs

du-hs*| sort-h

du-k*| sort-nr | cut-f2 | xargs-d'\n'du-sh

此操作适用于当前目录中的目录。

如果任何目录名包含换行符,它将中断。

我在执行第一个命令时出现了很多错误(例如du:invalid option--“r”)。“sort-h”也按修改时间排序吗?试试这个:ls-tr | xargs-d'\n'du-sh
command ls -dt */ | while IFS= read -r dir; do du -sh "$dir"; done