[SOLVED] Can a file's timestamp be auto-updated when moved to a directory?
Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
You could always create a subdirectory of that main Dropbox directory and use a cron script to check the main directory for files and move them to the subdirectory, touching the filestamp as you move then. Your second purging cron script would then work only on the subdirectory.
Yeah, that's basically what I did. I hoped there might be some secret tool I didn't know about. Here's my script:
Code:
. /etc/profile.d/tomcat.sh
DROPDIR="$CATALINA_HOME/webapps/ohprs/dropbox"
CURFILES=`find ${DROPDIR} -type f | sort`
# If our previous list is missing, use the current list
if [ ! -e /root/.dropfiles ]
then
echo reset .dropfiles
echo "$CURFILES" >/root/.dropfiles
exit
fi
# Compare old and new
find ${DROPDIR} -type f | sort | comm -13 /root/.dropfiles - | \
while read
do
echo `date "+%Y-%m-%d %H:%M"` touching "$REPLY"
touch "$REPLY"
done
# Reset list
echo "$CURFILES" >/root/.dropfiles
exit 0
This is run from cron every minute between 7:00AM and 6:00PM, Monday through Friday. It doesn't do the purging since there is another job that does that for this and many other temp files. I run this one minutely since the other purging script runs periodically as well.
# Compare old and new
echo "$CURFILES" | comm -13 /root/.dropfiles - | \
while read
do
Furthermore, maybe you can improve your deletion job, by considering atime and/or ctime in addition to the mtime? Or by skipping file deletion in directories with a recent mtime?
Is there a way to auto-touch the timestamp on a file when moved to a directory?
incron, as opposed to cron, can be configured to trigger your script whenever a file is added to a watched directory. Whether that works with Dropbox's directory, I don't know but you could give it a test.
# Compare old and new
echo "$CURFILES" | comm -13 /root/.dropfiles - | \
while read
do
Yes, I actually saw that after I posted, but was too lazy to change it. I wondered if anyone would catch that ... and someone did!
Quote:
Originally Posted by Turbocapitalist
incron, as opposed to cron, can be configured to trigger your script whenever a file is added to a watched directory. Whether that works with Dropbox's directory, I don't know but you could give it a test.
Excellent! That exactly the "magic tool" I was looking for. I'll experiment with that.
Quote:
Originally Posted by rknichols
You could base your deletion on ctime rather than mtime. The ctime stamp does get updated when a file is moved.
Excellent! That exactly the "magic tool" I was looking for. I'll experiment with that.
I used 'incrond' many years ago. Here is a small pseudo-mini-tutorial that I made in another thread.
It might give you a quick overview of how 'incron' is set up. In the example it was used to change the permissions of a newly created file. Of course, you should change the corresponding command to, e.g.,
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.