Unix & Linux Stack Exchange
Q&A for users of Linux, FreeBSD and other Unix-like operating systems
Latest Questions
14
votes
2
answers
1829
views
What is that "T" in the pattern string of the date-command?
What is that "T" in the pattern string of the date-command? While there is decent information about the output format string, I can only find unexplained examples for the pattern string ( the one used by the `-d`-option) on the net. What I did is: ``` $ echo TZ=America/Los_Angeles date -d '20250721T...
What is that "T" in the pattern string of the date-command?
While there is decent information about the output format string, I can only find unexplained examples for the pattern string ( the one used by the
-d
-option) on the net.
What I did is:
$ echo
TZ=America/Los_Angeles date -d '20250721T01:02' +'%Y %m %d %H %M %S %z'
TZ=America/Los_Angeles date -d '20250721 01:02' +'%Y %m %d %H %M %S %z'
echo ---
TZ=America/New_York date -d '20250721T01:02' +'%Y %m %d %H %M %S %z'
TZ=America/New_York date -d '20250721 01:02' +'%Y %m %d %H %M %S %z'
echo ---
TZ=Australia/Melbourne date -d '20250721T01:02' +'%Y %m %d %H %M %S %z'
TZ=Australia/Melbourne date -d '20250721 01:02' +'%Y %m %d %H %M %S %z'
$ 2025 07 21 01 02 00 -0700
$ 2025 07 21 01 02 00 -0700
$ ---
$ 2025 07 21 04 02 00 -0400
$ 2025 07 21 01 02 00 -0400
$ ---
$ 2025 07 21 18 02 00 +1000
$ 2025 07 21 01 02 00 +1000
Looking at the hour, there is a mysterious difference when "T" is used or not.
How to explain this?
As suggested by @maxime.bochon, here comes the environment information:
$ echo $0
/bin/bash
$ $0 --version
GNU bash, version 5.2.21(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2022 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later
This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
$ date --version
date (GNU coreutils) 9.4
Copyright (C) 2023 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later .
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Written by David MacKenzie.
$ echo $LANG
en_US.UTF-8
Gyro Gearloose
(455 rep)
Jul 22, 2025, 09:18 AM
• Last activity: Jul 23, 2025, 01:43 PM
6
votes
1
answers
15679
views
How to find files that were most recently created on file system?
I am trying to track the completion of a silent installer by detecting the presence of the last file created by it, but in order to do that I need to find out which file that is. Is there any way to do this? I have found a lot of answers on how to find the most recently *modified* file, but that is...
I am trying to track the completion of a silent installer by detecting the presence of the last file created by it, but in order to do that I need to find out which file that is. Is there any way to do this? I have found a lot of answers on how to find the most recently *modified* file, but that is not effective since many of these files were modified by the original creator in a different order than they are added to the system by the installer.
Pav
(61 rep)
Nov 17, 2015, 03:52 PM
• Last activity: Jul 8, 2025, 11:11 PM
4
votes
2
answers
2242
views
Make date change permanent in EC2
How can I manually set date and time to future in EC2 instance and make it permanent, so it won't reset after reboot ? I can change date using this command: $ sudo timedatectl set-time "2017-12-09 16:00:00" $ timedatectl Local time: Sat 2017-12-09 16:00:01 UTC Universal time: Sat 2017-12-09 16:00:01...
How can I manually set date and time to future in EC2 instance and make it permanent, so it won't reset after reboot ?
I can change date using this command:
$ sudo timedatectl set-time "2017-12-09 16:00:00"
$ timedatectl
Local time: Sat 2017-12-09 16:00:01 UTC
Universal time: Sat 2017-12-09 16:00:01 UTC
RTC time: Sat 2017-12-09 16:00:02
Time zone: Etc/UTC (UTC, +0000)
Network time on: no
NTP synchronized: no
RTC in local TZ: no
OS on EC2:
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 16.04.3 LTS
Release: 16.04
Codename: xenial
What else should I do to make this permanent ?
The purpose of this adjustment is to set the date to future, so I can test few things.
Michal Przybylowicz
(471 rep)
Nov 2, 2017, 01:58 PM
• Last activity: Jul 6, 2025, 01:08 AM
3
votes
1
answers
2851
views
I'm trying to compile alsa-driver-RTv5.18 but get date-time error for gcc 4.9.2
/home/user/Downloads/Rt-Linux-HDaudio-5.18/alsa-driver-RTv5.18/alsa/acore/info.c:1065:22: error: macro "__DATE__" might prevent reproducible builds [-Werror=date-time] "Compiled on " __DATE__ " for kernel %s" ^ cc1: some warnings being treated as errors I've tried to export CFLAGS="-Wno-error=date-t...
/home/user/Downloads/Rt-Linux-HDaudio-5.18/alsa-driver-RTv5.18/alsa/acore/info.c:1065:22: error: macro "__DATE__" might prevent reproducible builds [-Werror=date-time]
"Compiled on " __DATE__ " for kernel %s"
^
cc1: some warnings being treated as errors
I've tried to
export CFLAGS="-Wno-error=date-time"
but nothing changed.
Vyacheslav
(231 rep)
Oct 28, 2015, 04:19 PM
• Last activity: Jun 8, 2025, 10:10 PM
3
votes
2
answers
104
views
Get all log lines from last minute with busybox
I have an openwrt router (so no journalctl and only busybox commands), and would like to extract the logs from the last minute. The logs are like this: ``` Tue Jun 3 11:06:43 2025 authpriv.info dropbear[7018]: Child connection from Tue Jun 3 11:06:44 2025 authpriv.notice dropbear[7018]: Pubkey auth...
I have an openwrt router (so no journalctl and only busybox commands), and would like to extract the logs from the last minute.
The logs are like this:
Tue Jun 3 11:06:43 2025 authpriv.info dropbear: Child connection from
Tue Jun 3 11:06:44 2025 authpriv.notice dropbear: Pubkey auth succeeded
And my problem is that it's not numeric... I can generate the date from which I want to extract:
date -d "@$(( $(date +%s) - 60 ))" +"%c"
Tue Jun 3 11:05:00 2025
But now I'm stuck on how to catch the rows that are after this date.
Can anyone help me on this?
Paulo
(63 rep)
Jun 3, 2025, 10:18 AM
• Last activity: Jun 4, 2025, 06:22 AM
259
votes
6
answers
262953
views
date command --iso-8601 option
This [answer][1] and comments mention `--rfc-3339` and a "hidden" `--iso-8601` option that I have used for a long time and now seems to be undocumented. When did that option documentation get removed from the `--help` text? Will the option go away anytime soon? [1]: https://unix.stackexchange.com/a/...
This answer and comments mention
--rfc-3339
and a "hidden" --iso-8601
option that I have used for a long time and now seems to be undocumented.
When did that option documentation get removed from the --help
text?
Will the option go away anytime soon?
Angelo
(2599 rep)
Oct 29, 2014, 02:58 PM
• Last activity: May 27, 2025, 01:47 PM
0
votes
1
answers
1027
views
bash + grep only the time stamp from output
we want to capture the time from the output and not the time from the command sshpass expected output Sun Jul 14 12:47:49 UTC 2019 Sun Jul 14 12:47:49 UTC 2019 Sun Jul 14 12:47:49 UTC 2019 but from the command we get: sshpass -p customer pssh -H "presto01 presto02 presto03" -l root -A -i "date" | gr...
we want to capture the time from the output
and not the time from the command sshpass
expected output
Sun Jul 14 12:47:49 UTC 2019
Sun Jul 14 12:47:49 UTC 2019
Sun Jul 14 12:47:49 UTC 2019
but from the command we get:
sshpass -p customer pssh -H "presto01 presto02 presto03" -l root -A -i "date" | grep '[0-9][0-9]:[0-9][0-9]:[0-9][0-9]'
12:45:45 [SUCCESS] presto01
Sun Jul 14 12:45:45 UTC 2019
12:45:45 [SUCCESS] presto03
Sun Jul 14 12:45:45 UTC 2019
12:45:45 [SUCCESS] presto02
Sun Jul 14 12:45:45 UTC 2019
we can do
sshpass -p customer pssh -H "presto01 presto02 presto03" -l root -A -i "date" | grep '[0-9][0-9]:[0-9][0-9]:[0-9][0-9]' | grep -v "^\["
Sun Jul 14 12:50:24 UTC 2019
Sun Jul 14 12:50:24 UTC 2019
Sun Jul 14 12:50:24 UTC 2019
but this is ugly way
yael
(13936 rep)
Jul 14, 2019, 12:50 PM
• Last activity: May 15, 2025, 10:57 PM
1
votes
2
answers
650
views
ksh: appending date-time in history
Does anyone have a solution to append date and time to this as another column? It seems like it would be very useful with sorting, etc... $ history 3 history Thank you!
Does anyone have a solution to append date and time to this as another column? It seems like it would be very useful with sorting, etc...
$ history
3 history
Thank you!
Nick
(205 rep)
Oct 30, 2019, 07:22 PM
• Last activity: May 12, 2025, 09:35 AM
9
votes
4
answers
47361
views
How to change time zone in a bash script?
I am working on Linux Ubuntu, and I want a bash script whose output is to convert the timezone 7 hours in advance from my server time. My server time: > Mon Jul 23 23:00:00 2017 What I want to achieve: > Mon Jul 24 06:00:00 2017 I have tried this one in my bash script: #!/bin/bash let var=$(date +%H...
I am working on Linux Ubuntu, and I want a bash script whose output is to convert the timezone 7 hours in advance from my server time.
My server time:
> Mon Jul 23 23:00:00 2017
What I want to achieve:
> Mon Jul 24 06:00:00 2017
I have tried this one in my bash script:
#!/bin/bash
let var=$(date +%H)*3600+$(date +%M)*60+$(date +%S)
seven=25200
time=$(($var+$seven))
date=$(date --date='TZ="UTC+7"' "+%Y-%m-%d")
hours=$(date -d@$time -u +%H:%M:%S)
echo "$date" "$hours"
the output was:
> 2017-07-23
06:00:00
The hours works, but the date still matches the server date. Is there another way to solve this?
spacetrack
(99 rep)
Jul 24, 2017, 05:55 AM
• Last activity: May 9, 2025, 02:53 PM
0
votes
1
answers
2256
views
Value too great for base
I'm trying to display how long it takes for my script to execute in both seconds and milliseconds. This is my code: ``` #!/bin/bash before=10#`date +'%s%N'` sleep 1 after=10#`date +'%s%N'` echo "$before" let "time_taken=$before-$after" echo "$time_taken" echo "$s" ``` But I get the following error:...
I'm trying to display how long it takes for my script to execute in both seconds and milliseconds.
This is my code:
#!/bin/bash
before=10#date +'%s%N'
sleep 1
after=10#date +'%s%N'
echo "$before"
let "time_taken=$before-$after"
echo "$time_taken"
echo "$s"
But I get the following error:
./tijdsmeting.sh: line 9: let: time_taken=10#1590683503N: value too great for base (error token is "10#15906835
~ |03N")
I researched it and it has something to do with decimal/octal/... But I did specify it needed to be decimal by using #10
. Maybe using ibase
? And my errortoken isn't 08
like in the other cases on the internet..
O'Niel
(169 rep)
May 28, 2020, 04:34 PM
• Last activity: May 1, 2025, 11:09 AM
2
votes
2
answers
582
views
I could run command in terminal but not in crontab (date issue)
I checked many questions like my issue but could not find a solution yet Following command works without any problem rm -rf / *$(date +'%Y%m%d' -d "-2 days")*.csv I have edited crontab with like following line 39 9 * * * rm -rf / *$(date +\'\%Y\%m\%d\' -d \"-2 days\")*.csv But I got following error...
I checked many questions like my issue but could not find a solution yet
Following command works without any problem
rm -rf /*$(date +'%Y%m%d' -d "-2 days")*.csv
I have edited crontab with like following line
39 9 * * * rm -rf /*$(date +\'\%Y\%m\%d\' -d \"-2 days\")*.csv
But I got following error when crond runs my command
> date: extra operand `days"'
Try `date --help' for more information.
I could not find any solution yet, do you have any idea ?
I have tons of file to delete, rm works better than find (-exec rm) command.
Murat Suluhan
(97 rep)
Dec 26, 2017, 07:04 AM
• Last activity: Apr 14, 2025, 05:38 PM
3
votes
1
answers
254
views
Help needed for command to avoid leading zero in month part
We are using command ``` find $$dirpath_err -maxdepth 1 -type f -name "*XYZJPQ*_"`date +%m_%d_%Y`"*standard_error.csv" ``` but the file is generated as `s_mtt_XYZJPQ_4_07_2025_11_50_standard_error.csv` the above find command could search file successfully with name s_mtt_XYZJPQ_ 0 4_07_2025_11_50_st...
We are using command
find $$dirpath_err -maxdepth 1 -type f -name "*XYZJPQ*_"date +%m_%d_%Y
"*standard_error.csv"
but the file is generated as s_mtt_XYZJPQ_4_07_2025_11_50_standard_error.csv
the above find command could search file successfully with name s_mtt_XYZJPQ_04_07_2025_11_50_standard_error.csv
Could you please assist with option to avoid searching with leading zero in month part? Thank you in advance.
Sanjay Dubey
(75 rep)
Apr 7, 2025, 07:28 AM
• Last activity: Apr 7, 2025, 12:33 PM
0
votes
1
answers
65
views
What output does --iso-8601=ns provide with the date command?
This command will output the following:\ `date --iso-8601=ns` > 2025-04-04T12:10:16,045431370+02:00 According to `man date` the `ns` is documented as follows: ``` -I[FMT], --iso-8601[=FMT] output date/time in ISO 8601 format. FMT='date' for date only (the default), 'hours', 'minutes', 'seconds', or...
This command will output the following:\
date --iso-8601=ns
> 2025-04-04T12:10:16,045431370+02:00
According to man date
the ns
is documented as follows:
-I[FMT], --iso-8601[=FMT]
output date/time in ISO 8601 format. FMT='date' for date only (the default), 'hours', 'minutes', 'seconds',
or 'ns' for date and time to the indicated precision.
Confusing part is 'ns' for date and time to the indicated precision
\
What exactly is "indicated precision"? What is ns
?
Particularly I want to know the meaning of number 045431370
in output of 2025-04-04T12:10:16,045431370+02:00
**How to interpret 045431370
number? and what is ns
option?**
btw. I assume +02:00
means UTC offset? or UTC +2
?
metablaster
(776 rep)
Apr 4, 2025, 10:30 AM
• Last activity: Apr 4, 2025, 02:21 PM
1
votes
3
answers
3260
views
trying to add X hours to an arbitrary date in bash
Given a date string like this: 2022-03-28T23:40:49.721Z I am trying to add X hours. the function would look similar to ``` addHours() { dateString=$1 hours=$2 return date -d 'dateString + $hours hours' +'%Y-%m-%dT%H:%M:%S.%NZ' } ``` My issue is the 'T' is causing issues and I keep running into inval...
Given a date string like this:
2022-03-28T23:40:49.721Z
I am trying to add X hours.
the function would look similar to
addHours()
{
dateString=$1
hours=$2
return date -d 'dateString + $hours hours' +'%Y-%m-%dT%H:%M:%S.%NZ'
}
My issue is the 'T' is causing issues and I keep running into invalid date structure
Tracy Lauren
(39 rep)
Apr 22, 2022, 05:48 PM
• Last activity: Mar 31, 2025, 04:11 PM
11
votes
3
answers
1591
views
What is a distro-agnostic way determine the OS install date?
I am on a CrunchBang machine and trying to write a script that needs to have the OS install date as a reference. I searched and found this command: ls -lct /etc | tail -1 | awk '{print $6, $7, $8}' It prints Mar 31 21:24 I did not understand the `tail -1` part, but was able figure out that $6 $7 $8...
I am on a CrunchBang machine and trying to write a script that needs to have the OS install date as a reference.
I searched and found this command:
ls -lct /etc | tail -1 | awk '{print $6, $7, $8}'
It prints
Mar 31 21:24
I did not understand the
tail -1
part, but was able figure out that $6 $7 $8 are the 6th 7th 8th occurrences of the last line that the command is referencing.
However, I realized that the year cannot be included as the year was not displayed in the ls -ltc
command.
Some people suggested finding the date /etc
was created and some checking the /var/log/syslog
etc. I thought these might be a little specific to the distro.
What is your recommendation for a truly distro-agnostic way to find the OS install date?
Animesh D
(2017 rep)
Apr 2, 2012, 06:47 PM
• Last activity: Mar 20, 2025, 06:59 AM
0
votes
2
answers
82
views
time in bash prompt does not change over time
I changed the prompt in my .bashrc to show the current time. This was the original prompt (from a fresh MX Linux install) ``` PS1="$PURPLE\u$nc@$CYAN\H$nc:$GREEN\w$nc\\n$GREEN\$$nc " ``` and I changed it to this ``` PS1="$PURPLE\u$nc@$CYAN\H$nc $YELLOW$(date '+%Y-%m-%d %H:%M:%S')$nc $REEN\w$nc\\n$GR...
I changed the prompt in my .bashrc to show the current time. This was the original prompt (from a fresh MX Linux install)
PS1="$PURPLE\u$nc@$CYAN\H$nc:$GREEN\w$nc\\n$GREEN\$$nc "
and I changed it to this
PS1="$PURPLE\u$nc@$CYAN\H$nc $YELLOW$(date '+%Y-%m-%d %H:%M:%S')$nc $REEN\w$nc\\n$GREEN\$$nc "
When I open a terminal, I see the current date and time in the prompt. New prompts are not displayed with the time at which they are generated. They always show the same time as the first prompt. What am I doing wrong?

crantok
(124 rep)
Mar 6, 2025, 12:32 PM
• Last activity: Mar 6, 2025, 06:18 PM
1
votes
2
answers
11728
views
How to check the number of day of month?
I want a bash script to check if today is 15 th of the current month. I need something like this: if [[ $dayOfMonth == 15 ]]; then echo "15th day of month" fi
I want a bash script to check if today is 15th of the current month.
I need something like this:
if [[ $dayOfMonth == 15 ]]; then
echo "15th day of month"
fi
nicholas
(171 rep)
Apr 14, 2021, 12:49 PM
• Last activity: Feb 25, 2025, 11:13 AM
4
votes
3
answers
1506
views
Porting Linux date parsing to FreeBSD
I have date in this format: `date -d $datum +"%Y-%m-%d"` and on Linux it worked OK but in FreeBSD says this: ERROR wrong format usage: date [-jnRu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ... [-f fmt date | [[[[[cc]yy]mm]dd]HH]MM[.ss]] [+format] what is response to this: date -d $datum...
I have date in this format:
date -d $datum +"%Y-%m-%d"
and on Linux it worked OK but in FreeBSD says this:
ERROR wrong format
usage: date [-jnRu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ...
[-f fmt date | [[[[[cc]yy]mm]dd]HH]MM[.ss]] [+format]
what is response to this:
date -d $datum +"%Y-%m-%d" >/dev/null 2>&1 || echo "ERROR wrong format"
But it prints out an error and then continues with the code and it seems that correctly. What am I supposed to do, so it wouldn't print out error and if there is error then the program exits?
applenic
(611 rep)
Mar 28, 2015, 01:54 PM
• Last activity: Feb 18, 2025, 12:07 PM
3
votes
2
answers
389
views
How to compare two dates in formats %Y-%m-%dT%H:%M:%S.%3NZ and %-m/%-d/%Y %-I:%M %p
This is a bash date conversion/comparison question. How do I compare dates `$d1` and `$d2` below where: `$d1` has format `%-m/%-d/%Y %-I:%M %p` (US-style `%p` with AM/PM) and `$d2` has format `%Y-%m-%dT%H:%M:%S.%3NZ` ``` #!/usr/bin/bash export d1='5/30/2024 7:52 PM' export d2='2025-01-08T18:07:23.00...
This is a bash date conversion/comparison question.
How do I compare dates
$d1
and $d2
below where:
$d1
has format %-m/%-d/%Y %-I:%M %p
(US-style %p
with AM/PM)
and
$d2
has format %Y-%m-%dT%H:%M:%S.%3NZ
#!/usr/bin/bash
export d1='5/30/2024 7:52 PM'
export d2='2025-01-08T18:07:23.000Z'
Emmett
(102 rep)
Feb 18, 2025, 02:03 AM
• Last activity: Feb 18, 2025, 08:05 AM
133
votes
7
answers
708498
views
Linux: set date through command line
How to change the system date in Linux ? I want to change: * Only Year * Only Month * Only Date * Any combination of above three
How to change the system date in Linux ?
I want to change:
* Only Year
* Only Month
* Only Date
* Any combination of above three
SHW
(15376 rep)
Aug 22, 2014, 09:40 AM
• Last activity: Feb 12, 2025, 01:09 PM
Showing page 1 of 20 total questions