Skip to main content

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
0 votes
1 answer
34 views

Format date output with spaces into awk

I want to make the date command with nice formatting like this: awk -F, '{system("date -d " $1 " +%d/%m/%Y %H:%M")}' file.log However it does not work Try 'date --help' for more ...
0 votes
1 answer
33 views

Script to find multiple files and update their timestamps by a second

I'm trying to create an interactive script that lets me choose a start date and time, then recurse into the present directory/subdirectories, find all flac audio files, sorted by directory/...
2 votes
3 answers
2k views

Error in deleting files or directories older than 1 day

I am able to delete files or directories older than 1 day using below command find /u01/Release/* -mtime +1 -exec rm -r {} \; but why I am getting error in the output of this command: ls -lrt ...
-2 votes
1 answer
75 views

How do I get lastlog timestamps in a generic format?

I have multiple Ubuntu machines in different locations. I want to collect the last login information from these machines. However, when I use the lastlog command, it returns dates in different formats....
13 votes
11 answers
21k views

How do I parse out just the date from 2017-03-08T19:41:26Z?

I am trying to parse out just the date from 2017-03-08T19:41:26Z. The desired output is 2017-03-08.
2 votes
2 answers
3k views

How to read dd/mm/yyyy date string in date -d UNIX command?

I am trying to dynamically convert one column in text file containing date in dd/mm/yyyy hh:mm:ss format to yy-mm-dd hh:mm:ss. Following command is working but giving output in yy-dd-mm and NOT yy-mm-...
4 votes
2 answers
2k 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 ...
18 votes
4 answers
14k views

How can I avoid "Run fsck manually" messages while allowing experimenting with system time changes?

I'm working with a system where we want to allow users to play around with the date and time if they want, and where reboots may happen arbitrarily. This is fine, except for one thing: if there's a ...
8 votes
5 answers
4k views

creating the directory with the month name only

Posting question by curiosity, I wanted to create directory like January, February...to December so I created them by individually giving the name. ( mkdir January February ....etc) Is it possible to ...
3 votes
1 answer
3k 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 ...
1 vote
1 answer
2k views

Print a date with leading zeros

My intention is to print date like this, 04.10.2015 I have tried, d=`date '+%d%m%y'` But the problem what was happening, it was printing those dates which are two digits (10 to 31). But 1 to 9 date ...
0 votes
1 answer
55 views

Where does `date` get the system timezone from?

I always thought Linux systems used /etc/timezone for the timezone, but: $ cat /etc/timezone Etc/UTC $ date Tue May 28 12:34:01 PM PDT 2024 Here, the /etc/timezone is UTC but date is reporting in ...
0 votes
1 answer
60 views

What's the origin of the date format specifier "%b" for abbreviated months?

I'm working with the date command in Linux and I'm curious about the format specifier "%b". It outputs the abbreviated month name, which is great. However, I couldn't find a clear ...
6 votes
4 answers
1k views

Getting file modification time in POSIX shell

Is it possible to get file modification time from shell using only POSIX features? Ideally in unix timestamp (seconds). Everything I was able to find was using stat(1) but that does not seem to be ...
0 votes
1 answer
31 views

Date is incorrect in wifi : system clock synchronization is not active

I have compiled a read-only rootfs image with yocto for my raspberrypi4. I have noticed that my date is incorrect uniquely in wifi. Indeed when I type the command timedatectl status I have the ...
2 votes
2 answers
2k views

How to list attributes (esp. date) of a symbolic link's target file?

When typing ls -la we get the list of files in the current directory, with symlinks having also their target files printed. When displaying a symlink, the shell prints the attributes (and particularly,...
114 votes
7 answers
197k views

Show the year while listing files in the current directory

I am working on a Red Hat server. The commands ls -l or ll giving me the date and time in format +"%b %-d %H:%M". I want to list the files in a way where the year when each was file created would ...
0 votes
1 answer
5k views

shell script to monitor current errors in logfile

This script monitors logfile for pattern "ora",pull error details and send email.In this case i want to pull only the last error which come in logfile. I set crontab for every 5 minutes,so grep pull ...
21 votes
1 answer
3k views

How could March 30th 2024 be followed by the 1st?

I am in the EU zone +1 or when DST is on, +2. Now is Sunday 31.3.2024. This Sunday morning, we changed into DST, at 2→3 (CET → CEST). I have Linux servers in separate networks reporting monthly energy ...
1 vote
4 answers
1k views

Pick off 'first' dates using cal function in bash

I'm trying to pick off the first Monday, second Tuesday, second Saturday, etc. out of the cal function and piping awk commands. For this month, I can get the first Tuesday correctly with the command ...
2 votes
3 answers
1k views

Can the date command take as argument another date command in a file?

I am reading through the GNU coreutils manual, and I am experimenting with the date command.  Here is what I found in the text: The date command has a -f datefile option: Parse each line in datefile ...
240 votes
5 answers
233k views

date command --iso-8601 option

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 ...
74 votes
1 answer
114k views

How do you time how long a command took to run? [duplicate]

How would you find out how long a running process took to complete? Example: date; dd bs=1m if=/foo of=bar; date ^This example only has 1 second of resolution. Any shell is acceptable.
2 votes
3 answers
2k views

Log search within date range

My log file looks like the following sample: 10.434.22.334 - unauthenticated 10/Aug/2020:23:45:45 +0800 "GET /eai/random.jsp HTTP/1.1" 200 74 10.434.22.334 - unauthenticated 10/Aug/2020:23:...
2 votes
6 answers
567 views

Convert EPOCH string in filename to readable format

My knowledge of Unix is not very good. I'm trying to write a shell script to rename a set of files in a directory, like 1709532255.mp4 to 20240304_070415.mp4, where 1709532255 is always an epoch time. ...
0 votes
1 answer
78 views

How to generate a date in ISO 8601 format (UTC time) with an offset X days into the future? [duplicate]

When calling an API, I need to provide a start time and an end time in ISO 8601 format (UTC time). I want to call the API in a CRON job, so I can't manually create the date-time(s). How can I use the ...
8 votes
4 answers
36k views

Get previous month regardless of days

In Linux, I can get last month by using date -d "last month" '+%Y%m' or date -d "1 month ago" '+%Y%m' But say, today is 31st of March, if I run the command at top, it shows 201603, but I want to ...
0 votes
1 answer
31 views

Updating date for all files in scratch directory periodically

I am using a shared linux server that deletes files after 2 weeks. I would like to write a script that updates the date for all of my directories and files (basically, everything in my scratch ...
15 votes
8 answers
29k views

date: get current 15 minute interval

Is there any way I can get the current 15 minute interval using the date command or similar ? e.g. something like date %Y.%m.%d %H:%M will give me 2011.02.22 10:19 , I need something that yields ...
0 votes
4 answers
125 views

how to subtract a date in format: 'xyz/[int][int]/[int][int][int][int]' from the current date?

Scenario I have containers which have last deploy dates in the format: month/date/year or feb/11/2024. I cant change the way they output the last deploy date. I'd like to subtract the last deploy date,...
1 vote
4 answers
786 views

Given a weekday name, week of a month, and a year, how to find the date

I can find the last Monday using date -d 'last-monday' +%F but given a weekday name, week of a month, and a year, how to find the date? e.g. given: Monday, Week 4, June, 2022 output: 2022-06-20 given: ...
9 votes
3 answers
17k views

`timedatectl set-timezone` doesn't update `/etc/timezone`

I expected that timedatectl would update /etc/timezone when changing timezones, but no: % sudo timedatectl set-timezone 'Asia/Kuala_Lumpur' % cat /etc/timezone Asia/Bangkok Is there a reason that it ...
2 votes
2 answers
117 views

What's the KISS-way of turning format '1000 days' into format 2 years, 9 months, 0 days' within bash & shell scripting?

What's the "Keep It Simple" way of turning a format such as '1000 days' into format '2 years, 9 months, 0 days' within shell scripting? I've thought of applying modulor or floor rounding. I'...
3 votes
3 answers
975 views

Date sorting format: Day-Month-Year

I have a text file with date value. Data: 01-Sep-21 02-Jan-22 12-Aug-21 24-Dec-21 11-Jul-22 How to sort these data from old to new date value?
0 votes
2 answers
109 views

Removing Minutes from Date as a Variable

I am writing a script in KSH and need your help to find the logic to remove minutes and seconds from the date. If users pass 2024-12-22-16-43-40 to a variable, it should be converted to 2024-12-22-16-...
1 vote
1 answer
4k views

view IPs from apache access.log for date period

I have seen someone use this command -- and it works where it pulls back all the IPS in a list/group: cat access.* | awk '{ print $1 }' | sort | uniq -c | sort -n However, I want to choose the past ...
13 votes
2 answers
36k views

Get last time timedatectl synchronized its time/force synchronization now

I have an Ubuntu server that is a little over a minute out of sync with the actual time. When I run timedatectl I get: Local time: Tue 2018-04-24 14:47:57 MDT Universal time: Tue 2018-04-24 20:47:57 ...
10 votes
4 answers
26k views

Local Account Creation Date

For compliance purposes there is the need to fetch information regarding local (user and non-user) accounts creation date on UNIX machines. Is there any way (even if it's not the most reliable or ...
0 votes
0 answers
28 views

highlight several dates in a year with gcal

cal or gcal are linux terminal programs which display a calendar gcal 2023 displays the entire year 2023 This question explains how to make it highlight todays date in the current year - Highlight the ...
0 votes
1 answer
141 views

How to make crontab interact with session of currently logged-in user?

THE PROBLEM Crontab does work - but just aside, not in interaction with users. How to make crontab talk to currently logged-in user by automatically perceivable prompt output? For example, a wake-up ...
0 votes
4 answers
2k views

Script to find the date of all the sundays in a year

I wanted to print the dates of the 54 sundays in a year. i have written the below script , but in the output im getting an error Script: req_date=`date +%m%d%Y` for i in {1..54} do NEXT_DATE=$(...
0 votes
2 answers
71 views

How can I generate a cumulative plot where I can view the number of files by the last modified date?

I have a large (millions) number of files in a folder, its subfolders and its subsubfolders that were modified over the past 15 years. I'd like to generate a cumulative plot where I can view the ...
16 votes
4 answers
3k views

date - Can't Go Back More Than 115 Years or Can't Go 5879565 Years Into the Future

TimeZone = CEST date (GNU coreutils) 8.32 date -d "115 years ago" Di 11. Aug 13:37:54 CET 1908 date -d "116 years ago" date: invalid date ‘116 years ago’ Questions Is it ...
1 vote
1 answer
520 views

Compare file dates from two directories

I have two directories with files with the same name. Basically I want to replace dir1/file.txt with dir2/file.txt if the creation date of dir1/file.txt is more recent. But i think I'm missing ...
0 votes
2 answers
3k views

busybox format date

I got a command which works perfectly on linux date -d @$(git log -1 --format=%at) '+%Y-%m-%d_%H-%M-%S' and now I'm trying to do the same formatting with busybox (v1.31.1), but it always fails with ...
23 votes
4 answers
13k views

Change time (date) in or from exif data

In the question Change file created date from JPEG EXIF metadata there are great scripts to update the file system date and to match date stored in the file. But what if the “Date and Time (original)” ...
18 votes
3 answers
69k views

How to convert date to timestamp

I saw this date command: date -d @1332468005 '+%Y-%m-%d %H:%M:%S' Resulting in : 2012-03-22 22:00:05 How can I convert it back from 2012-03-22 22:00:05 to 1332468005 with bash shell?
12 votes
4 answers
3k views

sort at jobs chronologically

Possibly a simple solution I misplaced. How can I get the output of atq sorted chronologically, so I can easily see who's due to run next? The man page for sort doesn't have anything built-in to ...
32 votes
4 answers
24k views

Why does TZ=UTC-8 produce dates that are UTC+8?

The current time in Los Angeles is 18:05. But when I run TZ=UTC-8 date --iso=ns, I get: 2013-12-07T10:05:37,788173835+0800 The date utility tells me that the time is 10:05, and even says that it's ...
1 vote
1 answer
186 views

Add hours to the date and time

I have a requirement to add offset hours to the datetime value. Get the previous date (e.g. 2023-10-19 00:00:00.000000) previous_date=`TZ=TZ+24 date '+%Y-%m-%d 00:00:00.000000'` Calculate the ...

1
2 3 4 5
24