I am making a bash script to run in a directory with files generated everyday and copy the most recent file to another directory.
I am using this now
for [FILE in directory]
do
if [ls -Art | tail -n 1]
something...
else
something...
fi
done
I know this is not alright. I would like to compare the date modified of the files with the current date and if it was equal, copy that file then.
How would that work or is there an easier method to do it?
ls, look intofindwith option-mtime. It will list files that are older than ? day(s). You can then use the-execoption to do something simple, or loop on the files (see FAQ001) if it is more complex (mywiki.wooledge.org/BashFAQ/001).