> $ 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.
