Questions tagged [date]

the "date" tag is used to classify questions about date/calendar/time manipulation, visualisation, conversion... on Unix-like systems.

Filter by
Sorted by
Tagged with
9 votes
4 answers
994 views

What's the POSIX-compliant way to get the epoch timestamp in a shell?

I just noticed, that POSIX date doesn't seem to have the %s or %N format items. So I can't use those. What's an alternative, yet POSIX-compliant way to get the epoch timestamp in my shell script?
user avatar
  • 1,924
2 votes
2 answers
40 views

Setting time zone in a kindle bash file

I've recently jailbreaked my kindle to make it a clock that shows a certain image for each minute of the day. I used the instructions mentioned in this article https://www.instructables.com/Literary-...
user avatar
0 votes
0 answers
12 views

Format the file date according to ISO-8601 in tree -D and accumulate the sizes of files in a directory

It is well known that tree -hD can show the file size with each file or directory and the file change date of each file or directory. However, for a directory, it always shows 4.0K which of course is ...
user avatar
1 vote
0 answers
22 views

Counter-intuitive date command [duplicate]

I've been using date in a script in order to add one year to a specific date the following way: date '+%Y-%m-%d %H:%M:%S' -d "$DATE + 1 year" In this example, DATE looks like 2022-05-11 14:...
user avatar
3 votes
1 answer
215 views

Is my zoneinfo backwards or am I confused

As far as I know, United States Eastern Time is GMT-5 for Eastern Standard Time, and GMT-4 for Eastern Daylight Time. So why do these two commands give different hours in the answers? laptop % TZ=...
user avatar
  • 1,652
0 votes
1 answer
23 views

FreeBSD - get timezone in Continent/Region format

I have a Linux (bash) script to generate a login message (motd). One of the things it displays is the timezone, using the command timedatectl | grep Time | awk {'print $3'}. The command returns ...
user avatar
  • 77
0 votes
1 answer
23 views

How do I set the date to the epoch of a linux (raspbian flavor) system, i.e., 1 January 1970 00:00:00? [duplicate]

I am trying to set up a Raspberry Pi with the date and time to the beginning of time from the linux point of view. In my understanding, the epoch is 1 January 1970 00:00:00. The first step was to set ...
user avatar
0 votes
1 answer
35 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 + $...
user avatar
1 vote
1 answer
24 views

zdump and date do not show the same daylight saving information

I am using my localtime set to be Israel. I updated the system clock and hardware clock, and using zdump I get: ~# zdump /usr/share/zoneinfo/Israel /usr/share/zoneinfo/Israel Wed Apr 20 16:11:36 2022 ...
user avatar
0 votes
2 answers
63 views

trying to get number of seconds from the epoch to the day, using %s, getting invalid date

When I'm trying to run the below command, I'm getting correct output date --date="04/1/2022 7:1:00" +'%s' output: 1648776660 But when trying to run the same command with a different date, ...
user avatar
  • 282
0 votes
1 answer
58 views

PERMANENTLY change the output format of the 'date' command in my Kali Linux

So I have 2 different Linux installations. One of them is Ubuntu and the second one is Kali. When I run date command with no options/arguments on my Ubuntu install I get: michal@ubuntu:~$ date Thu 24 ...
user avatar
0 votes
2 answers
47 views

How to get date in format 2022-03-17T08:06:20.411493824Z

I can't seem to find any simple answers as to how to get the date 2022-03-17T08:06:20.411493824Z with a simple bash command. The current date and time that is. I tried the following, but I'm not ...
user avatar
0 votes
1 answer
127 views

Format datetime as UTC with strftime (for use in git)

I can format dates and time pretty flexibly with strftime, but from what I can see, this only will give times in my local timezone; I can add the timezone offset (e.g. '%Y %m %d-%H:%M:%S%z' for a ...
user avatar
0 votes
1 answer
32 views

Subset of File between two dates, when some dates are invalid

I have come across several similar questions, but the solutions seem to be failing me, and I believe it is because I have some junk data in my file that is breaking my attempt to filter by time stamp. ...
user avatar
  • 107
0 votes
1 answer
70 views

How to convert Linux date to another date format

I am getting date in one of file in the format "Fri Feb 25 16:07:17 UTC 2022" Which I want to convert it to "2022-02-25 16:07:17". However I am able to do it using Python but its ...
user avatar
-1 votes
1 answer
88 views

Find "latest" path, filename, date, and time at every level of a folder subtree with Bash [closed]

Using Bash, I want to find for any specified directory and its subtree the filename, creation_date and creation_time for the file last created in that directory. For example, the output would be: /...
user avatar
  • 9
2 votes
4 answers
361 views

Convert mm to hh:mm

I am using awk to get all of the 4th comma-delimited fields, which is a duration in minutes. The required output is in the format of hh:mm, so I need to convert that from minutes. "jone",&...
user avatar
  • 35
0 votes
1 answer
35 views

date string column to timestamp column in a log file

I have log.txt with sample output like these: ... 10-Feb-2022 15:15:14.099 lorem 10-Feb-2022 15:15:15.133 ipsum 10-Feb-2022 15:15:16.233 dolor ... I expect the output of filtered log.txt will be ... ...
user avatar
1 vote
1 answer
57 views

Convert string time to seconds

I'm receiving an uptime in this format: 167h58m10.586582048s I want to transform it to seconds and discard the fraction part. I know awk could do that if only the received string had the same ...
user avatar
0 votes
3 answers
91 views

date: starting with year and week number, how to have the date Monday

How can I get the ISO date for a specific week's Monday? For example, the Monday of the 32nd week of 2021? I know that if I run date -dmonday +%Y%m%d I will get the the Monday date of the current week....
user avatar
  • 2,039
0 votes
4 answers
45 views

How to get date string from stat command?

I have this to get the timestamp of a directory: stat -c %Y directory_name What can I pipe this to, to get the date formatted like this? 20220201
user avatar
  • 769
1 vote
2 answers
44 views

How to give file name as current date in expect

I have wrote a script in expect as follows. I want to give date as variable to cd command but when I am giving the date as variable to the command and it add '' commas and therefore it shows a error ...
user avatar
  • 21
0 votes
1 answer
62 views

Origin of date command default US format

date seems to have a very odd default format in the US locale: Thu Jul 9 17:00:00 EDT 2020 using a space-padded day-of-month and putting the (24-hour!) time in the middle, between the month+day and ...
user avatar
  • 151
6 votes
3 answers
640 views

Where can I find a complete list of format specifiers for the date command?

I wanted to get the month name on macOS 11.6, and I tried checking the man page of date checking the man page of strptime But I couldn't figure out what format specifier to use to display the month ...
user avatar
  • 24.1k
0 votes
1 answer
73 views

Show only dates bigger than the search pattern even if the search pattern does not exist in the (log) file

I want to search the syslog for dates bigger than a specific search pattern. For example I want to find every syslog entry where the date is bigger than JAN 6 16:24:00. I know I could use sed (sed -n ...
user avatar
  • 2,281
1 vote
2 answers
111 views

date string is not updating within while true; do loop

I have a simple bash script: #!/bin/bash enp="$(ip route | grep "192.168.1.1" | cut -d' ' -f 3)" while true; do vnstat -l -i "$enp" --style 4 --json | awk '{ print ...
user avatar
0 votes
1 answer
169 views

Convert date format of a stat command output

With the command stat * --format='%A %h %U %G %s %z %n' I get: -rwxrwxrwx 1 myuser mygroup 131072 2021-11-12 14:52:23.495595927 +0100 myfile Is it possible to have a stat output like the following? ...
user avatar
  • 267
0 votes
2 answers
156 views

Wrong Local time Archlinux + Xfce4

My system local clock has been displayed incorrectly for several days. when i run timedatectl status output is something like this : ➜ timedatectl status Local time: Sat 2021-12-25 19:16:57 +0330 ...
user avatar
  • 101
0 votes
1 answer
65 views

How to do math in If-Statement

I have a Bash script which should only execute in a specific time window (from midnight to 00:15 AM). But if I execute the function, I get [: too many arguments as an error message. How do I solve it? ...
user avatar
  • 3
1 vote
1 answer
92 views

cron job running an hour early due to daylight savings [duplicate]

On a CentOS 7.5.1804 host I am experiencing a cronjob that is running an hour early due to rolling the clocks back an hour and the UTC offset changing from UTC-4 to UTC-5. This runs from /etc/cron.d/* ...
user avatar
  • 1,490
1 vote
2 answers
83 views

Nagios Core 3.5 change Date format

How can the Date/Time format that Nagios uses everywhere be changed to YYYY-MM-DD HH:MM:SS?
user avatar
  • 25
0 votes
0 answers
14 views

Change Date & Time format - Solus 4.3 Fortitude

How can I change the date and time format in Solus to display in any format of my choice? Could be HH:MM:SS; Nov 01, 2021 or HH:MM:SS; November 01, 2021 or HH:MM:SS; 01/11/2021 or HH:MM:SS; 01-11-...
user avatar
  • 1
-2 votes
2 answers
104 views

sort and delete older file

How can I sort the below files based on the date and time inside the folder and delete the older ones and keep the most recent ones in Linux? I just want to keep the latest one regardless of the ...
user avatar
  • 25
0 votes
0 answers
35 views

Find out who changed the date on linux?

I'm currently trying to change the date on my Linux machine: date +%s -s @1637142120 Somehow, the date gets resented after some seconds. Is there any way to find out which program / system is ...
user avatar
  • 203
2 votes
2 answers
147 views

Find pattern: sort and delete older files

I want to delete old files and keep only the most recent from each file pattern based on the first five characters (aa_te, bb_co, cc_co, dd_xy) and the date and time in the file name. Note: All files ...
user avatar
  • 25
2 votes
2 answers
285 views

Shift of dates not working as expected

I have a file with records in this format : D20220327,S2927,977,1 D20220328,S2927,977,1 D20220329,S2927,977,1 D20220330,S2927,977,1 D20220331,S2927,977,1 D20220401,S2927,977,1 D20220402,S2927,...
user avatar
2 votes
1 answer
186 views

Wrong Date calculation by date on Ubuntu 16, 20

The weirdest thing happens to date calculation because of what you see below; notice that adding one month to Oct 31st takes it to December! This can't be? I have the same issue on Ubuntu 16 and 20. ...
user avatar
  • 23
0 votes
1 answer
197 views

Who sets date/time automatically from the hardware clock at boot?

When Linux is booting, the current time must be fetched from a RTC chip and then set to Linux system date/time. I can do this manually by running hwclock --hctosys. But where exactly does this happen ...
user avatar
  • 131
1 vote
2 answers
63 views

Substract date in custom format

I need to substract some date from current date to determine the age of some connections. The date is in this format: YYMMDDHHMISS. The output can be pretty much anything that I can use to determine ...
user avatar
0 votes
5 answers
147 views

Shift of dates in a CSV file via bash script

Currently I have a file with records like this : D20211011,S0519,306668,1 D20211004,S1600,306668,1 D20211009,S1604,306668,1 D20211010,S1605,306668,1 D20211006,S1610,306668,1 D20211011,S1611,306668,1 ...
user avatar
2 votes
2 answers
247 views

how to increment date from a to b?

I have 2 dates, start=20190903 & end=20210912 and want to increment till start approaches the end, increment is 13 days. have following code, but it exceeds end. #! /usr/bin/env bash start="...
user avatar
  • 1,613
0 votes
3 answers
37 views

Script that finds and deletes files older than 2014 [duplicate]

I am trying to write a script that finds files that are from before September 24th, 2014, and deletes them. How would I do this?
user avatar
  • 1
0 votes
0 answers
14 views

How to sanitize user input timezone (TZ)?

In my POSIX sh script, I receive a user input timezone (=TZ) with an option. However, I want to throw errors when the tz is not legit (not found in the system). For example, TZ='CETX' date '+%T' ...
user avatar
0 votes
2 answers
85 views

When date and timedatectl?

About reporting and settings for date and time exists available the date and timedatectl commands - it according with the most common results available through the web. Practically both do the same. ...
user avatar
1 vote
1 answer
51 views

Unix script to process data by comparing it to same key records

I have a problem in which Input file has Effective date and End date records. First 6 fields are the keys (12345A). We need to update End date(18 position) based on effective(8 position) date of the ...
user avatar
0 votes
1 answer
102 views

Convert custom date format (GMT-08-2021.08.31-18.29.05) to epoch time

I have a date string that is supplied in the following format: Timezone-Year.Month.Day-Hour.Minute.Second GMT-08-2021.08.31-18.29.05 and I need to figure out how to get the date command to recognize ...
user avatar
  • 2,087
-9 votes
2 answers
355 views

Create a Bash script which will print a message based upon which day of the week it is (eg. 'Happy hump day' for Wedensday, 'TGIF' for Friday etc) [closed]

Create a Bash script which will print a message based upon which day of the week it is (eg. 'Happy hump day' for Wedensday, 'TGIF' for Friday etc). How to print a message of the days of the week on a ...
user avatar
1 vote
1 answer
86 views

hwclock's output is effected by DST when entering it, but not when leaving it

I set system time and RTC to the following values. date -s 2021.08.30-09:59:30 >/dev/null 2>/dev/null //set system time hwclock -w //sync RTC to system time Also, /etc/TZ (which is the same ...
user avatar
  • 121
0 votes
1 answer
104 views

How to automate the writing of a log file using vim?

I am using Vim as my primary text editor on Fedora 34 workstation. I need to create and maintain a log file for one of my courses for the purpose of tracking time and work done. It should look ...
user avatar
  • 113
0 votes
3 answers
95 views

How to find every months secound day

How to get second day(date) of current month (e.g 2 August) in HPUX. date -d doesn't work in HPUX Unix.
user avatar

1
2 3 4 5
23