I've written a bash shell script and part of it is checks if a file is over 30 days old using the find command, sadly when I uploaded it to my host it did not work as the find command is locked down.
Does anybody know how to check if a file is over 30 days old WITHOUT the find command?
I'm thinking I need to do an "ls -a $filename" then parse the date string out, convert it to a unix date and then compare it with todays date but I'm very rusty at unix.
Thanks
stat -c %Z filename gives the last change time in unixtime
stat -c %Y filename if you want the last modification time.
You can use if [ $file -ot $timestamp_file ] (-ot meaning "older than"). You would have to construct the appropriate file, for example with touch (which takes timestamp options). If this is a periodic task you can also create the timestamp file on each run to use next time.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With