coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Print modification time in compact form


From: Robin A. Meade
Subject: Re: Print modification time in compact form
Date: Tue, 16 Mar 2021 16:01:09 -1000
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.0

> $ stat -c '%y' file.txt
> 2017-07-31 17:50:54.000000000 +0100
>
> Is there a way to directly print it as 20170731-1750? Thanks.

gnu stat doesn't provide fine control over the formatting of the timestamps.
See Jan 7, 2021 request for enhancement:
https://lists.gnu.org/archive/html/coreutils/2021-03/msg00024.html

You can use gnu date, gnu find, or bsd stat:

# Replicate conditions of your example
TZ=GMT-1 bash
cd "$(mktemp -d)"
touch -m -d '2017-07-31 17:50:54.000000000 +0100' file.txt
stat -c '%y' file.txt
# 2017-07-31 17:50:54.000000000 +0100

# gnu date
date -r file.txt +'%Y%m%d-%H%M'
# 20170731-1750

# gnu find
find ./file.txt -printf '%TY%Tm%Td-%TH%TM\n'
# 20170731-1750

# bsd stat
stat -f "%Sm" -t "%Y%m%d-%H%M" file.txt
# 20170731-1750

Robin


On 3/15/21 4:16 PM, Peng Yu wrote:
Hi,

I see modification time can be printed in this format.

$ stat -c '%y' file.txt
2017-07-31 17:50:54.000000000 +0100

Is there a way to directly print it as 20170731-1750? Thanks.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]