Ghi102
Ghi102

Reputation: 163

Getting the creation date of a file on Cygwin

I'm trying to get the creation date of a file using console commands. I've managed to use this:

stat -c "%w" file

which outputs the date and time:

2015-05-01 09:33:22.503525000 -0400

But I'd like to extract only the date (without the time) from the result. Is there a way to do this using only stat, or do I have to separate the result using another command? And what might that command be?

Upvotes: 1

Views: 1348

Answers (2)

Jahid
Jahid

Reputation: 22428

Try this:

stat -c "%w" file | cut -d" " -f1

The output of stat will be piped into cut and the string will be cut at the first concurrence of a white space.

Upvotes: 1

Politank-Z
Politank-Z

Reputation: 3729

Assuming you are using bash:

date -d "@$(stat -c %W file)" +%F

Will do the trick. %W on stat returns the epoch date, date +%F converts it to a YYYY-MM-DD format.

Upvotes: 0

Related Questions