I don't have appropriate access to the system in order to run the privileged find
command. 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.
I came up with this command 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.
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 | 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:
.:
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. It accumulates the sizes (field number 5) of the selected lines and prints the sum at the end. 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). The current timestamp is passed to awk
as variable now
with the -v now=$(date +%s)
option.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.