Date is a command line utility for printing or setting the date and time.

learn more… | top users | synonyms

44
votes
3answers
4k views

Day of week {0-7} in crontab has 8 options, but we have only 7 days in a week

Day-of-week: Allowed range 0 – 7. Sunday is either 0 or 7. I found this after Googling, my question is why should both values (0,7) correspond to Sunday?
23
votes
10answers
3k views

Year 2038 problem

What is the likelihood of the Year 2038 issue being very problematic?
16
votes
5answers
14k views

How do I convert an epoch timestamp to a human readable format on the cli?

How do I convert an epoch timestamp to a human readable format on the cli? I think there's a way to do it with date but the syntax eludes me (other ways welcome).
16
votes
9answers
8k views

Tool in UNIX to subtract dates

Is there any tool in Solaris UNIX (so no GNU tool available) to subtract dates? I know that in Linux we have gawk that can subtract one date from another. But in Solaris the maximum we have is nawk ...
15
votes
3answers
1k views

How does touch -t work internally?

How does touch -t command works exactly, internally (I tried to find its source code but couldn't)?
15
votes
1answer
256 views

How to trick a particular command into thinking it is a different date?

How can I execute a command making it believe that is on a different date than system one? For instance, if I have this script: #!/usr/bin/env bash date +"%B %d, %Y" It prints the actual date: ...
14
votes
6answers
21k views

Quickly calculate date differences

I often want to make some quick date calculations, such as: What is the difference between these two dates? What is the date n weeks after this other date? I usually open a calendar and count the ...
10
votes
4answers
10k views

How to list files sorted by modification date recursively (no stat command available!)

How can I get the list of all files under current directory along with their modification date and sorted by that date? Now I know how to achieve that with find, stat and sort, but for some weird ...
10
votes
2answers
438 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}' ...
9
votes
4answers
7k views

last time file opened

Is it possible to get the time when file was opened last time and sort all files in a directory by those times?
9
votes
2answers
978 views

How can I delete all files in a folder that haven't been accessed in a certain amount of time?

I'd like to run a nightly cron job that deletes all the files in a folder that haven't been accessed in a week or more. What is the most efficient way to do this in bash?
9
votes
3answers
5k 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 ...
9
votes
3answers
1k views

How to use the date command to find out what date “monday week 40” will be?

How can I use the date command to convert something like "monday week 40" into a ISO date? I am playing with something like this: date --date='monday week 40' +'%Y-%m-%d' And the date I'm ...
9
votes
3answers
431 views

What is the recommended way to synchronize time using NTP?

This question has come up a number of times in a localized way, this question is meant to provide the preferred/best method for synchronizing a system's clock using NTP. The solution should handle ...
8
votes
3answers
4k views

How can I have `date` output the time from a different timezone?

I have a server running with the timezone set to UTC. It seemed like that was generally a good practice (please correct me if I'm wrong). Anyhow, one of the servers I connect to, in order to scp ...
8
votes
2answers
610 views

date - years prior to 1901 are treated as invalid

I have date (GNU coreutils) 7.1 installed on my system. If I try to check dates prior to 14-Dec-1901, I get an "invalid date" error. For example, $ date -d 1901-12-13 date: invalid date ...
8
votes
1answer
3k views

Is there a way to adjust the formatting of the date/time in the GNOME 3 login screen and desktop?

I'm specifically looking to change the formatting in two places: On the desktop, the date/time reads "Sat 21:05". I would like it to read "23-Jul-11 21:05" or "23 Jul 11 21:05". In other words, I ...
7
votes
3answers
306 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 ...
7
votes
6answers
5k 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 ...
7
votes
3answers
458 views

Forcing an 'added' alias to every command

Is it possible to forcibly add a timing alias (for lack of a better way to phrase it) to every command in bash? For example, I would like to have a specific user who whenever a command is run, it is ...
7
votes
2answers
4k views

How to find difference between two timestamps up to milliseconds?

I am new to shell scripting. The heart of my script is to find the difference between two timestamps up to milliseconds. With me I have a file with content of timestamps only as 2012-09-13 ...
6
votes
4answers
3k views

Renaming a bunch of files with date modified timestamp at the end of the filename?

So, say, I have a directory with a bunch of files like g.txt, where g.txt was last modified on, say, June 20, 2012. How would I batch-rename all of the files (like g.txt) with the last modified date ...
6
votes
3answers
527 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 ...
6
votes
4answers
371 views

convert date format in log

I have a log with following date format: 2013-12-14 18:53:33 aaaaaaaaaaaaaaaa 2013-12-14 18:53:33 bbbbbbbbb 2013-12-14 18:53:33 ccccccccccccccccccccc What would be the simplest solution to convert ...
6
votes
3answers
810 views

Equivalent of date --reference in Solaris

The GNU implementation of the date command has a nice feature to show the date of the last modification of a reference file, and using the +FORMAT parameter it is easy to get the date in any format, ...
6
votes
1answer
147 views

locale definition with French republican calendar

I wonder if it is possible to create a locale definition that would make the C library format the dates according to the French republican calendar. I expect then, for example, run `date' and get ...
6
votes
4answers
590 views

Date computations without GNU tools

I have to perform some date calculations and conversion in a shell script. For example computing the difference in day between a date formatted as Nov 28 20:27:19 2012 GMT and today. There are ...
6
votes
1answer
388 views

In KDE, how can I create a custom keyboard shortcut that prints the current date?

I often need to print the current date in lots of different programs. Right now, I always type it per hand which is error prone. I'm using KDE 4.8, and it has customisable keyboard shortcuts. For ...
5
votes
5answers
599 views

How to parse ISO8601 dates with linux date command

I'm trying to use the date command to generate a file timestamp that the date command itself can interpret. However, the date command does not seem to like its own output, and I am not sure how to ...
5
votes
3answers
1k views

Fast way to build a test file with every second listed in YYYY-mm-dd HH:MM:SS format

I want to create a large test file with lines containg dates listed by the second, but my method is taking inordinately long... (or at least, that's how it feels :) ... 43 minutes to create only ...
5
votes
3answers
10k views

Getting all files that have been modified on a specific date

Is it possible to find all php files within a certain directory that have been modified on a certain date I'm using find /var/www/html/dir/ -mtime -28 | grep '\.php' to get files modified within ...
5
votes
3answers
4k views

Appending timestamp stamp along with log file lines

I have a log file and I need to append timestamps to each line as they get added. So I'm looking for script that appends timestamps to each entry in log lines and which could run as a cron job. Could ...
5
votes
3answers
7k views

Find files which are created a certain time after or before a particular file was created

I need a shell script which finds files which are created 1 hour before or 1 hour after a particular file (test.txt) was created. If I go with find -newer, that means I'd have to create a temporary ...
5
votes
2answers
3k views

Good method to compare time?

I need to check for the current time and abort the script if it is not proper time of day I am supposed to run it. Also, if anyone else runs it, it should abort. For example: I need my script to only ...
5
votes
3answers
1k views

Installation date of Ubuntu

How can I determine when Ubuntu was installed in my computer? There was a different question posted here, but none of them is helpful.
5
votes
1answer
891 views

Get “date” to understand a timestamp phrase of a different language

My web-scraping scripts have long enjoyed using date -d to read in human-formatted time and date stamps like "March 11, 1999" and convert to any other format I need via the -s parameter. How might I ...
5
votes
1answer
2k views

Calculate the date from 1125 days ago on non-GNU systems?

On the Unix Bash commandline, I want to calculate the date from 1125 days ago using the base operating system (e.g. No Perl or Python). On systems running GNU Date, I can do something like this: ...
5
votes
1answer
224 views

Remind syntax combining a weekly event with a time range

How should I write "Every Tuesday, Thursday, Friday after 2011 Sep 13, but before Sep 28, with reminder 1 day before event". Now I got REM Tue Thu Fri 13 Sep 2011 +1 UNTIL 28 Sep 2011 MSG Esem, but ...
4
votes
5answers
2k views

Convert formatted dates to seconds since the epoch

I have a file: pablo tty8 Thu Nov 1 12:51:21 2012 still logged in (unknown tty8 Thu Nov 1 12:50:57 2012 - Thu Nov 1 12:51:21 2012 (00:00) pablo tty2 Thu Nov 1 12:50:39 2012 still logged in pablo ...
4
votes
2answers
2k views

/etc/shadow date of last password change—UTC or local time?

man 5 shadow gives the following description of the third field in each line: The date of the last password change, expressed as the number of days since Jan 1, 1970. The value 0 has a ...
4
votes
2answers
4k views

How to get elapsed time from two “text based” dates

I would like to know if there is a way to calculate the difference between two times in bash. I have two fields that are extracted from a log file: Start time: Feb 12 10:02:10 End time: Feb 12 ...
4
votes
1answer
83 views

How does coreutil's date manage to get such weird results?

I was playing around with date to try to convert expressions such as "2 hours" to a number of seconds like 7200. I thought I could perform this with invocations such as: date -d "1970-01-01 00:00:00 ...
4
votes
2answers
58 views

Off by 1 year error in GNU date?

Right now, 2014-01-06, GNU date 8.4 on CentOS release 6.4, does this: $ date --date "last week" +"%Y-%V" 2013-01 On the other hand, $ date --date "last week" +"%Y-%U" 2013-52 which is just ...
4
votes
3answers
915 views

how to suppress bash octal number interpretation? (to be interpreted as decimal)

I have this: date +"%H hours and %M minutes" I use festival to say it up.. but it says like: "zero nine hours".. I want it to say "nine hours"! but date always give me 09... so I wonder if bash ...
4
votes
3answers
270 views

Setting linux time

$ date 042612492005 $ hwclock -w The code above shows how to set the system time, but how's the timestamp string generated in the first place?
4
votes
1answer
134 views

How to show full day name with command of e.g. Jul 16 1991

I found out that date --date 'Jul 16 1991' has an complete output, but I only want the terminal to show the name of the day e.g. Monday. How do I do that?
4
votes
2answers
91 views

Create sub-directories and organize files by date from file name

I have been using the following script to organize my photos into "Date' Directories: for x in *.JPG; do d=$(date -r "$x" +%Y-%m-%d) mkdir -p "$d" mv -- "$x" "$d/" done This script works ...
4
votes
1answer
737 views

Removing leading zeros from DATE

I made an alias of the date command to display date in the following format: 2013.06.14.12.10.02 using this command: alias date = date +"%Y.%m.%d.%H.%M.%S" Everything works great, except i ...
4
votes
5answers
11k views

Display time stamp in dd/mm/yyyy_hh:mm:ss:ms in Unix or Linux

I need help to display date and time in desired format in Unix/ Linux. My desired format is: dd/mm/yyyy hh:mm:ss:ms in Unix or Linux. I got close using the following command: echo $(date +%x_%r) ...
4
votes
1answer
51 views

Midnight Commander, using date in User menu

I would like to use MC (midnight commander) to compress the selected dir with date in its name, e.g: dirname_20131231.tar.gz The command in the User menu is : tar -czf dirname_`date ...