LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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, 04:19 AM   #1
qrange
Senior Member
 
Registered: Jul 2006
Location: Belgrade, Yugoslavia
Distribution: Debian stable/testing, amd64
Posts: 1,061

Rep: Reputation: 47
directory timestamp


is there a way to delete file, but keep the old timestamp of directory?
 
Old 09-08-2012, 07: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: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065
No.
 
1 members found this post helpful.
Old 09-08-2012, 07:49 AM   #3
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
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, 11:39 AM   #4
qrange
Senior Member
 
Registered: Jul 2006
Location: Belgrade, Yugoslavia
Distribution: Debian stable/testing, amd64
Posts: 1,061

Original Poster
Rep: Reputation: 47
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 11:42 AM.
 
Old 09-08-2012, 01: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: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065
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



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-15-2012 11:13 PM
[SOLVED] Updating timestamp in files in directory tuxtutorials Programming 5 08-21-2010 09:03 AM
sort oldest 5 files in a directory tree recursively based on timestamp Linux abhelp Programming 1 06-04-2010 04:58 AM
about timestamp George2 Programming 1 08-16-2006 09:13 AM

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

All times are GMT -5. The time now is 05:19 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
Open Source Consulting | Domain Registration