LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-08-2012, 05:19 AM   #1
qrange
Member
 
Registered: Jul 2006
Location: Belgrade, Yugoslavia
Distribution: Debian stable, amd64
Posts: 827

Rep: Reputation: 32
directory timestamp


is there a way to delete file, but keep the old timestamp of directory?
 
Old 09-08-2012, 08:02 AM   #2
tronayne
Senior Member
 
Registered: Oct 2003
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,541

Rep: Reputation: 1060Reputation: 1060Reputation: 1060Reputation: 1060Reputation: 1060Reputation: 1060Reputation: 1060Reputation: 1060
No.
 
1 members found this post helpful.
Old 09-08-2012, 08:49 AM   #3
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978
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.
 
1 members found this post helpful.
Old 09-08-2012, 12:39 PM   #4
qrange
Member
 
Registered: Jul 2006
Location: Belgrade, Yugoslavia
Distribution: Debian stable, amd64
Posts: 827

Original Poster
Rep: Reputation: 32
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.

Last edited by qrange; 09-08-2012 at 12:42 PM.
 
Old 09-08-2012, 02:21 PM   #5
tronayne
Senior Member
 
Registered: Oct 2003
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,541

Rep: Reputation: 1060Reputation: 1060Reputation: 1060Reputation: 1060Reputation: 1060Reputation: 1060Reputation: 1060Reputation: 1060
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).
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Retaining timestamp of a directory. sysmicuser Linux - Newbie 6 03-16-2012 12:13 AM
[SOLVED] Updating timestamp in files in directory tuxtutorials Programming 5 08-21-2010 10:03 AM
sort oldest 5 files in a directory tree recursively based on timestamp Linux abhelp Programming 1 06-04-2010 05:58 AM
about timestamp George2 Programming 1 08-16-2006 10:13 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:12 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration