I tried
stat -c %Y ./* 2>/dev/null | awk -v d="$(date +%s)" 'BEGIN {m=d} $0 < m {m = $0} END {print d - m}'
to find the age of the oldest file in the current directory, and I get a number in seconds with this line.
How do I get a number in days in that one line? Thank you
days=seconds/(24*60*60)
– pLumo Apr 23 '20 at 12:17ls -t1 | tail -1
will give you the oldest file by modification date. Then you canstat -c %Y
that file to get the number of seconds. Divide by 86400 (seconds in a day) to get days. In one line it would be something likeecho `stat -c %Y \`ls -t1 | tail -1\``/86400 | bc | tr -d '\n';echo " days"
– Fubar Apr 23 '20 at 13:50ls
will break badly if the names have spaces or glob characters or newlines. See Why *not* parse `ls` (and what to do instead)? – terdon Apr 23 '20 at 14:08file=`ls -t1 | tail -1`;echo `stat -c %Y "$file"`/86400 | bc | tr -d '\n';echo " days"
– Fubar Apr 23 '20 at 14:35