Change file’s date or time using console in Linux

For most of your this task is as obvious as it can be and writing separate blog post about such simple thing is… simply useless. For me, a total Linux newbie, it isn’t that obvious and I found myself spending way too much time on finding this simple thing. Thus, I decided to write it down for my own future reference.

Touch is able to change file date to any, if properly called up. For example:

touch -t 200607210833 Ticket.jpg

You may omit entire year in your date, if you’re referencing current year. Or you may specify it with only two digits, if you’re referencing to current century.

If you need to specify time including seconds, type them as fractional part, after period. Don’t forget about double quotes, if your filename contains spaces:

touch -t 200607210833.21 "Ticket Machine Hangup #2.jpg"

That would be all folks! :]

Leave a Reply