colucix |
09-08-2012 07:49 AM |
Since a directory is just a (special) file containg a list of the files inside and some attributes, every time you delete a file the directory is changed and the timestamp is altered. The rm command doesn't provide any option to preserve the original timestamp of the container, but you can always restore it later using the touch command. Example:
Code:
#
# Create a temporary file with the same timestamp of the directory
#
touch -r directory /tmp/file
#
# Remove what do you want to remove
#
rm directory/file
#
# Restore the original timestamp
#
touch -r /tmp/file directory && rm /tmp/file
In this case only the access and modification times are restored, whereas the change time cannot be managed (but usually it's somenthing you have not to worry about). You can easily verify the behaviour using the stat command. Hope this helps.
|