unix

How do I create a file with a specific timestamp or update the timestamp of an existing file?

To create a file with a specific timestamp or update the timestamp of a file, you can use the touch command.

An example is shown below.

touch -t 201009011200 /path/to/my/file

This will create the file /path/to/my/file with the timestamp 09/01/2010 12:00.

# ls -lt /path/to/my/file

-rw-r–r–  1 root  root  0 Sep  1  2010 /path/to/my/file

A timestamped file can be useful for doing things like this:

find /var ! -newer /path/to/my/file

This will find files in /var that are older than /path/to/my/file (9/1/2010).

Click to comment

Leave a Reply

Your email address will not be published. Required fields are marked *

To Top