I recently removed a file in UNIX accidentally – I was running commands from my command history and thought I was after the second most recent command, rather than the third most recent command.
Luckily, I’d kept a copy of the file on my Windows system, so all I wanted to do was to put the file back. As expected, though, when I put the new file over, it took the UNIX timestamp rather than the Windows one. One of the first things that I check for when comparing a development and production environment, if something works in one environment and not in the other, is the timestamps on the two files – if they are the same then the chances are that the files are identical. This isn’t always true, but I’ve always found it a good starter for 10.
So, now I have a file in UNIX that is dated today, when it should have been date three months ago, and I wanted to change the timestamp. In Windows, I’ve got a utility that I can enter the new timestamp, and it updates the file information – in UNIX there is a standard command to do it!
If you run the touch command, you can provide a timestamp that it puts against the file, so all I needed was to run
touch -t 200703062257 [filename]
and the system set the timestamp on the file to 06-MAR-2007 at 22:57 – exactly what I wanted to hide my error in deleting files!
This is probably old-hat to someone who knows UNIX well, but it saved me having to remember the dates that I messed up files, and at least now I have somewhere I can always search to remind me how it’s done!!