Silas2
asked on
Linux Script File Attributes
Im trying to run a shell script on a cron (Ubuntu 16.01) which iterates all files in a folder, and checks that their last modified time is greater than 5mins. I think last modified time is one of the three file date/times stored by Linux. So far I've got :
for file in $(ls folder/*.wav)
do
name = $(file%%.wav)
chmod 777 $name.wav
//I want to do this:
if($name.wav).LastModified< now-5mins)
{
do something
}
And I just want to check that the last modified date is more than 5mins ago, I'm not sure of the syntax...anyone?
ASKER
Thanks for that, I just found on StackExchange this:
if test `find "text.txt" -mmin +120`
(http://stackoverflow.com/questions/552724/how-do-i-check-in-bash-whether-a-file-was-created-more-than-x-time-ago)
That does look a lot simpler, what makes you prefer the stat?
if test `find "text.txt" -mmin +120`
(http://stackoverflow.com/questions/552724/how-do-i-check-in-bash-whether-a-file-was-created-more-than-x-time-ago)
That does look a lot simpler, what makes you prefer the stat?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks v. much. I'm a Linux newbie.
That's fine, we all had to start! Welcome to the world of Linux :-)
Open in new window
Edit: clarified the text a bit, and put curly braces round the "name" variable - not strictly necessary here, because BASH knows that the name of the variable stops at the dot, but it makes it clearer to the human reader that the variable name is just "name". Note also that the whole "${name}.wav" has double quotes round it - that is in case the name has spaces in it. Also, I could have used "$(( $(date...) - $(stat...) ))" rather than the "expr" version, but I thought I already had enough parentheses in the statement!