Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [date]

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

79
votes
13answers
178k 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 ...
18
votes
4answers
43k 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 ...
22
votes
11answers
19k 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 (...
105
votes
6answers
152k 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 ...
15
votes
2answers
8k 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 ...
4
votes
2answers
1k views

how to sort by the day of the week?

I have two files. file1: Dave 734.838.9800 Bob 313.123.4567 Carol 248.344.5576 Mary 313.449.1390 Ted 248.496.2204 Alice 616.556.4458 file2: Bob Tuesday Carol Monday Ted Sunday ...
14
votes
5answers
22k 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 ...
11
votes
4answers
2k 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 ...
74
votes
6answers
354k 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
37
votes
4answers
20k views

How do I remove leading zeroes from output of 'date' or avoid octal interpretation of such decimal numbers?

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 can ...
22
votes
1answer
4k 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: ...
3
votes
2answers
266 views

How do I find a locale which formats date and time the way I want?

My question seems like it should be simple but I'm amazed that I can't find the answer. I live in Canada so en_CA.UTF8 or en_US.UTF8 are the locales that are most appropriate, however I really ...
5
votes
7answers
872 views

Change date and time format from csv file without using date -d

I have a .csv file contains Data1|Data2|10/24/2017 8:10:00 AM I want to change date and time format of column 3 as following: From 10/24/2017 8:10:00 AM (12-Hour) to 20171024 08:10:00(24-hour). ...
1
vote
3answers
211 views

Display lines in last 10 minutes with specific pattern in logs

I need to display lines with Error occurred in last 10 minutes of a log file. Aug 26 10:50:42 Normal line. Aug 26 10:51:23 Normal line. Aug 26 10:55:33 Error line. Aug 26 10:56:45 Normal line. Aug ...
102
votes
3answers
254k views

linux + add X days to date and get new virtual date

I have Linux ( RH 5.3) machine I need to add/calculate 10 days plus date so then I will get new date (expiration date)) for example # date Sun Sep 11 07:59:16 IST 2012 So I need to get ...
82
votes
11answers
227k views

How to compare two dates in a shell?

How can two dates be compared in a shell? Here is an example of how I would like to use this, though it does not work as-is: todate=2013-07-18 cond=2013-07-15 if [ $todate -ge $cond ]; then ...
28
votes
3answers
79k views

List of Recently Modified Files

How can I Get a list of all files modified , say 3 months ago. I checked this question but I was not able to apply it to my scenario. I am trying this now , it seems to be working , but I know there ...
6
votes
3answers
2k 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 ...
14
votes
3answers
7k views

Date validation in shell

I want to validate the below date format in shell script 2015-Jul-13 I'm using date -d "2015-Jul-13" +"%Y-%b-%d" but its giving error as date: invalid date '2015-Jul-13'
6
votes
5answers
2k views

Is it possible to reference the most recently modified file in a command line argument?

I frequently download PDF files with heinous numeric file names from my browser. These automatically go into ~/Downloads. Ideally I would like to just be able to open these files with: evince "the ...
1
vote
2answers
3k 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 ...
9
votes
1answer
621 views

Bash - date, working around the 2038 bug on 32bit LINUX system

I wrote a little bash script that made me stumble across the "Year 2038 Bug". I did not know about this problem before and I just dare on posting the --debug output I got from date when my script ...
5
votes
3answers
21k 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 ...
1599
votes
3answers
307k views

Why does man print “gimme gimme gimme” at 00:30?

We've noticed that some of our automatic tests fail when they run at 00:30 but work fine the rest of the day. They fail with the message "gimme gimme gimme" in stderr, which wasn't expected. Why are ...
169
votes
12answers
245k 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).
87
votes
4answers
141k 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?
21
votes
1answer
40k 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.
19
votes
3answers
31k views

How does the “1 month ago” option in date command work?

I'm not sure if this gets the past date within the current day or if it only takes 30 or 31 days to it. e.g. If the current date is March 28th, 1 month ago must be February 28th, but what happen ...
7
votes
2answers
7k views

Create sub-directories and organize files by date

I have some directories of files copied from my security camera that I would like to organize into sub-directories by file date. So for example; -rwxrwxrwx 0 root root 4935241 Jul 19 2012 DSCN1406....
7
votes
1answer
34k views

Read log file between two dates

I have to read log file between and my question is how to get only the text in the file wich is between two dates using unix commands? Every line contain date and I want to get the text in the file ...
3
votes
1answer
5k views

How do I set up busybox to allow a non-root user to set the date?

I have an embedded system built with busy box. I allow a user named "app" to download a program/script to a directory and it will be run on boot. The program should be allowed to set the date. It ...
16
votes
1answer
1k views

Best practice to customize date/time format system-wide?

I'd like to customize exclusively the date and time format for my system, while sticking to the rest of the locale as is. I know that environment variable LC_TIME will make it possible to customize ...
15
votes
5answers
22k 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
2answers
6k views

Select greatest numbered filename

I have a list of dated files as below... filename_20120101.dat filename_20120102.dat filename_20120103.dat I need a script which selects the most recent file based on the date in the ...
10
votes
3answers
12k views

How do I find seconds since midnight?

Using the date program, how can I calculate the number of seconds since midnight?
9
votes
4answers
16k 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 ...
6
votes
2answers
2k views

List files created on Sundays

How do I list/find all the files created on Sundays or Mondays? How do I use the date parameter to display them? Something like : ls -f date + %a or find -type f | date +%A or find -type f -...
3
votes
3answers
770 views

how to create a data file with a column of date from day1 to dayN?

I was wondering if I could generate a hourly or daily time step date in a column starting from some year in the past to some day in the near past or today. to be more clear, I want to create one ...
3
votes
3answers
2k views

How do I find a file with a name which depends on the current date (and a random component)?

I have to check a particular path every day and find the file with a name of the form: StaticData_Sets_yyyymmdd-232550.txt The date in the name after the string StaticData_Sets_ is updated every day ...
2
votes
1answer
1k views

Change System Time/Date

I'm running Linux Mint 15 with KDE 4.10.4+ Here's what I get when I run date: user:~ > date Die Okt 29 15:47:54 UTC 2013 Where "Die Okt" indicates a German-language setting, which I don't mind. ...
6
votes
6answers
79k views

Extract date from a variable in a different format

Let me explain you the problem $ date +%c -d "$d" Tue 31 Dec 2013 01:13:06 PM CET $ date +'Today is %F' -d "$d" Today is 2013-12-31 This solution corresponds to current date. But I have one ...
5
votes
5answers
22k views

Next day of the user entered date - date +1 day

I am new to scripting. I need a script in the AIX environment to get the next days date based on the date entered by the user. After hard time browsing for this, I got a piece of code which does the ...
4
votes
3answers
5k views

Get file modification time in a specific format (yyyymmddhh24miss)

I want to get the modification time of a file in a specific format. How can I do that ? I know about stat -c %x find.txt but I need this format: yyyymmddhh24miss I'm using ksh on Linux 2.6.18-406....
4
votes
3answers
479 views

Get time difference of two dates using awk

I have a file of size 7GB. Now have two date time in that I want to use awk to get this difference of time between that two DateTime. Below is how my files look like: A B C D ...
3
votes
1answer
693 views

linux: touch date precision

On my linux system if I display the current date "t1", touch a file "f" then display the modification time "t2" of that "f" I would expect t1 < t2. But that's not what I always get when I execute ...
2
votes
1answer
3k views

Append same timestamp to multiple filenames

I have several files that I ftp each hour. The receiving system needs to have some sort of identifier that they came from the same batch, so I would like to append a timestamp to the filename. That ...
1
vote
2answers
3k views

How to grep a date lesser than a particular date in a file [closed]

I have a log file like Blah blah blah 2018-12-13. Now I want to grep the log files with a date before 2018-05-01. My intention is to filter the Log files lesser than 2018-05-01
1
vote
1answer
94 views

Calculate Difference In Time Over Several Days

I've seen many questions and examples showing how to calculate the difference in two times by converting the times to epoch, and then converting the difference in seconds... However, what is the best ...
1
vote
1answer
1k views

how to subtract a constant value from a data file?

I want to subtract a constant number from my data to get new data file. For example, I want to subtract 10 from my data. data.txt Id a b c d e 1 1 2 3 4 5 2 2 3 4 5 6 ...
0
votes
3answers
68 views

Cascading Date Manipulation and Precedence [duplicate]

echo 20171231 | xargs -i date -d "{} +1 day" | xargs -i date -d "{} -1 month" **Fri Dec 1 00:00:00 PST 2017** In this case, when date formatting commands are pipelined I am get Dec 1. echo 20171231 ...