Check if the file is longer than 30 days without the find command

I wrote a bash shell, and part of it is checked if the file is older than 30 days using the find command, unfortunately, when I uploaded it to my host, it did not work as the find command was blocked.

Does anyone know how to check if a file is longer than 30 days without the find command?

I think I need to do "ls -a $ filename", then parse the date string, convert it to unix date, and then compare it to today's date, but I'm very rusty on unix.

thank

+3
source share
5 answers

stat -c %Z filename gives last time changes to unixtime

stat -c %Y filenameif you want a recent modification time.

+6

if [ $file -ot $timestamp_file ] (-ot ", " ). , , touch ( ). , , .

+2

ls unix, :

ls -l --time-style='+%s'

, 30 ; 24 & times; 60 & times; 60 ls.

,

date '+%s';
0

Linux: no -v

t=`date +%Y%m%d%H%M`
let u=$t-1000000
touch -t "$u" $DATEFILE
if [ $SERVERFILE -ot $DATEFILE ]; then
  rm $SERVERFILE
fi
0

, ...

  • I touched a file with today's date - 1 month.

touch -t "$(date -v -1m +%Y%m%d%H%M)" ${DATEFILE}

  • Was there an older test for 2 files.

if [ ${SERVERFILE} -ot ${DATEFILE} ]

Thanks to everyone.

-1
source

Source: https://habr.com/ru/post/1774248/


All Articles