LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   directory timestamp (https://www.linuxquestions.org/questions/linux-newbie-8/directory-timestamp-4175426221/)

qrange 09-08-2012 04:19 AM

directory timestamp
 
is there a way to delete file, but keep the old timestamp of directory?

tronayne 09-08-2012 07:02 AM

No.

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.

qrange 09-08-2012 11:39 AM

thanks for the help, I solved the problem by hexediting the file so it has zero size.
btw, is it possible to modify the file and keep its timestamp? I'd like the zero sized file to have old timestamp.

tronayne 09-08-2012 01:21 PM

You can create an empty file with
Code:

>filename
You can manipulate its time stamp with the method suggested by @colucix (as well as the directory time stamp where you created the empty file).


All times are GMT -5. The time now is 04:55 PM.