-4

I want to edit some file in my linux for example

ls -ltr /etc/some_file

-rw-r--r-- 1 root root 188 Jul  1  2010 sysstat

.

       echo "Server101_IP=187.0.98.4" >> /etc/some_file

.

I expect to get the following date:

 ls -ltr /etc/some_file

-rw-r--r-- 1 root root 188 Jul  1  2010 sysstat

but the date & time of this file must be not change !

I just want to edit file but I Wondering how to change the file without effect on the date & time of the file - is it possible ?

yael
  • 2,433
  • 5
  • 31
  • 43
  • 2
    One question: why? – EEAA Dec 02 '12 at 21:26
  • because I build some script that search the IP - 187.0.98.4 in all Linux directories but this script ignore if file is old then the OS creation - that the reason , so I want to test my script and see if it really ignore the old files – yael Dec 02 '12 at 21:35

1 Answers1

6

You could do something with stat to get the file's Access, Modify and Change timestamps and then after editing the file you can use touch to set the relevant times back to what they were originally.

user9517
  • 115,471
  • 20
  • 215
  • 297
  • @LAIN please give me exaample – yael Dec 02 '12 at 21:40
  • 2
    @yael Tis not a "gimmeh teh c0dez" site - It is a resource for professionals who want to further their knowledge while solving a problem. Read the manual pages that Iain was good enough to link to, learn about the tools, and apply them to your situation. – voretaq7 Dec 03 '12 at 03:15
  • simple solution that I find: touch -t 200805101024 /etc/filename – yael Dec 05 '12 at 13:46