简体   繁体   English

用于查找该目录中留下过去 7 天内创建的文件的空间的命令。 不使用`find`

[英]Command to find how much is the space in that directory leaving the files created in last 7 days. Without using `find`

I don't have appropriate access to the system in order to run the privileged find command.我没有适当的系统访问权限来运行特权find命令。 So I am trying to get a string of commands possibly using grep or awk or anything that could list me the files that where NOT created within last 7 days and how much space are they consuming.所以我试图获取一串命令,可能使用grepawk或任何可以列出过去 7 天内未创建的文件以及它们消耗多少空间的命令。

I came up with this command du -h | grep ^[0-9.]*G我想出了这个命令du -h | grep ^[0-9.]*G du -h | grep ^[0-9.]*G now I need to know how can I list which once are more than 7 days older. du -h | grep ^[0-9.]*G现在我需要知道如何列出超过 7 天的列表。

Output of the above command is:上面命令的输出是:

du: cannot read directory `./lost+found': Permission denied
1.5G    ./portal/portal-internal-crons/get_portal_logs/p3-proxy1.extranet.akamai.com
1.5G    ./portal/portal-internal-crons/get_portal_logs/p3-proxy2.extranet.akamai.com
1.5G    ./portal/portal-internal-crons/get_portal_logs/p3-proxy5.extranet.akamai.com
1.5G    ./portal/portal-internal-crons/get_portal_logs/p3-proxy6.extranet.akamai.com
1.1G    ./portal/portal-internal-crons/get_portal_logs/p3-sp01.extranet.akamai.com
1.2G    ./portal/portal-internal-crons/get_portal_logs/p3-sp02.extranet.akamai.com
1.5G    ./portal/portal-internal-crons/get_portal_logs/p3-proxy7.extranet.akamai.com
1.5G    ./portal/portal-internal-crons/get_portal_logs/p3-proxy8.extranet.akamai.com
1.1G    ./portal/portal-internal-crons/get_portal_logs/p3-sp03.extranet.akamai.com
1.1G    ./portal/portal-internal-crons/get_portal_logs/p3-sp04.extranet.akamai.com
1.5G    ./portal/portal-internal-crons/get_portal_logs/p3-proxy3.extranet.akamai.com
1.5G    ./portal/portal-internal-crons/get_portal_logs/p3-proxy4.extranet.akamai.com
18G ./portal/portal-internal-crons/get_portal_logs
18G ./portal/portal-internal-crons
18G ./portal
19G .

In case you can run ls -lR --time-style=+%s on the target, you could:如果您可以在目标上运行ls -lR --time-style=+%s ,您可以:

ls -lR --time-style=+%s | awk -v now=$(date +%s) '/^-/ && now - $6 > 7*24*3600 {s += $5} END {print s}'

Explanation: ls -lR --time-style=+%s produces this kind of output:解释: ls -lR --time-style=+%s产生这种输出:

.:
total 7168
drwxr-xr-x 2 john doe    4096 1439992030 dira
drwxr-xr-x 2 john doe    4096 1441870671 dirb
-rw-r--r-- 1 john doe   43980 1436264423 filea
-rw-r--r-- 1 john doe   15941 1436264418 fileb
-rw------- 1 john doe 7193171 1439374938 filec
-rw-r--r-- 1 john doe    2927 1436264418 filed

./dira:
total 8
-rw-r--r-- 1 john doe 1205 1439991207 filea
-rw-r--r-- 1 john doe  142 1439990672 fileb

./dirb:
total 4
-rw-r--r-- 1 john doe 116 1441870658 filea

where the last modification date is a timestamp in seconds.其中最后修改日期是以秒为单位的时间戳。 The awk code selects the lines corresponding to files (first field starting with - ) which timestamp is more than 7 days in the past. awk代码选择与时间戳超过过去 7 天的文件(第一个字段以-开头)对应的行。 It accumulates the sizes (field number 5) of the selected lines and prints the sum at the end.它累加所选行的大小(字段编号 5)并在最后打印总和。 The age of a file is computed as the difference between the current timestamp ( awk variable now ) and the file's timestamp (field number 6).文件的年龄计算为当前时间戳( awk变量now )和文件的时间戳(字段编号 6)之间的差异。 The current timestamp is passed to awk as variable now with the -v now=$(date +%s) option.当前时间戳now通过-v now=$(date +%s)选项作为变量传递给awk

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用find命令删除批处理文件中超过30天的文件时如何排除多个子目录(相同的目录名称)? - How to exclude multiple subdirectories (same directory name) when using find command to delete files older than 30 days in a batch file? 如何使用diff命令在目录中查找具有相同名称的文件? - How to find files with same name part in directory using the diff command? Linux-如何查找最近12个小时内未查找命令更改的文件 - Linux - How to find files changed in last 12 hours without find command 使用 Linux 上的 find 命令查找和删除带空格的文件 - find and remove files with space using find command on Linux Bash ,查找最近 x 天的修改过的文件 - Bash , Find modified files for the last x days 如何在Linux中查找没有目录路径的文件 - How to find files without a directory path in Linux 如何使用 linux find 命令列出特定分钟或天未访问的文件? - How to list files that are not accessed for particular mins or days using linux find command? 查找过去 x 天内未访问的文件 - Find files that were not accessed in the last x days 我试图在 Linux 中查找过去 10 天内创建或修改的最大文件 - im trying to find the largest files created or modified within the last 10 days within Linux 如何使用 find 命令和 wc 命令查找目录和所有子目录中所有 .txt 文件的数量? - How do I find the number of all .txt files in a directory and all sub directories using specifically the find command and the wc command?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM