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
508 views

How to get +HHMM offset of TZ="Asia/Tokyo" compared to current time-zone using bash?

I am taking input for TZ and I want to convert it into a (+/-)HHMM format. but not compared with UTC, I want it to be compared with the local time. How can I do it?
0 votes
3 answers
349 views

How to get particular date

There is a need to get first Saturday date of current month in my script. I am able to get last Saturday date from below command date -d 'last Saturday' +%y%m%d But unable to get First Saturday date. ...
  • 60
2 votes
3 answers
204 views

How do I set a value when running find command?

I'm running a long string of -exec commands, and I want to pull a timestamp from the beginning of the run to use as a value for subsequent commands. Is this possible? Something like: find . -exec NOW=$...
0 votes
1 answer
791 views

Taking an integer and creating a date format

I can take a date and convert is to an integer. date_as_integer = $("2020-06-13" | sed "s/-//g") However is there a way to convert it back to date?
1 vote
2 answers
239 views

GNU date: truncate provided date-time and set provided hours

I have a timestamp value in a variable and I need to truncate the hours from it and set different hours. Can GNU date do this in one go? It definitely does this for special dates like "today"...
  • 1,821
2 votes
1 answer
365 views

Print datetime each time I hit the return key

I am searching for a way of prefixing the date command every time I run a command on the terminal (I am currently using zsh). The reason for this is that I usually run scripts that take a long time to ...
-1 votes
2 answers
112 views

How to delete deployments of a greater than date from awk list [closed]

I need to delete deployments that are older than 14 days on clusters. if I run: oc get deploy --sort-by=.metadata.creationTimestamp | grep wml-os-rt-hybrid | awk '{ print $1 "\t\t" $6;}' ...
1 vote
1 answer
94 views

Long listing showing hours since modification

Is there an option (preferably a GNU and/or FreeBSD option) that instructs ls to display modification time, not in absolute date time, but instead showing a number indicating hours (or days) since ...
  • 487
0 votes
2 answers
225 views

Fetch the series of logs in between date range when the range contains specific string(s)

I am searching for multiple range of lines from a file with in a given date range when the search string(s) exists. I am not an Unix expert, don't know how to achieve this. After googling I was able ...
  • 13
0 votes
1 answer
127 views

Comparing dates of different formats and matching it from another file

I have two data files with date stamps in different formats (as text in the file contents).  I wish to compare the two dates and print the variable from one file to another according to date in a ...
0 votes
1 answer
55 views

find a file based on date passed in parameter

I have a requirement to find a next day file based on date provided in the parameter. For example, I have these files: XYZ.ABC.M.20200615180200.batch XYZ.ABC.M.20200616180200.batch XYZ.ABC.M....
0 votes
1 answer
70 views

Purge lines in a file based on age in shell script

I wanted to record the slave delay in mysql server every minute,so prepared a simple script. #!/bin/bash echo "`date` : `mysql -uroot -pXXXXXX -e"show slave status\G" | grep -i ...
0 votes
1 answer
194 views

Archive files not modified for more than 6 months

I have a python method to archive files not modified in 6 months to another drive by iterating through the directories. But what is the fastest way to find all non-modified files from the whole ...
  • 135
0 votes
3 answers
87 views

I am working in Sun OS, I want my script to read date from a file(in format %Y%m%d) and add 1 day to that date

I am working in Sun OS environment, I want to add a functionality to my existing unix ksh script where it allows to read a date(in %Y%m%d format) from a file and add 1 day and rewrite the same into ...
  • 11
0 votes
1 answer
195 views

Is there a way to substring or cut a part of value of a unix variable without using echo?

Is there a way to substring or cut a part of value of a unix variable without using echo? For example i have a variable containing a date. pDate=2020-06-22 I need to pass the year and month into ...
  • 1
-1 votes
1 answer
35 views

How to search in Ubuntu/Linux using two different date?

Please assist. I am trying to search few events in Ubuntu from auth.log and syslog in /var/log/ folder using two different date range, how can I do it? My Code is like below with only one date range ...
1 vote
0 answers
44 views

Call script in locale definition

I am following the answer in https://askubuntu.com/a/162714/146591 to generate a custom locale on my system. Many of the fields that can be configured in a locale are input for the date utility (https:...
  • 111
0 votes
1 answer
191 views

Using a bash script to write current date to a .cfg/text file

I'm trying to get the current date as month/day (i.e., 6/18), printed into a .cfg file (using sed because I need a specific line changed). However, when running the bash, the date is correct in the ...
1 vote
1 answer
138 views

How date command keep tracking time

I got a weird scenario in which the date of my computer is getting the wrong time (and he keeps fixing the time but still keep repeating this issue) let me share with you an example who make this much ...
0 votes
1 answer
1k 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 same formatting with busybox, but i always fail
  • 1
-2 votes
2 answers
236 views

convert milliseconds column to seconds in a csv file [closed]

I have a large tab separated file without headers like this: Tue Jun 09 18:06:53 GMT 2020 1591726013187 Tue Jun 09 18:20:31 GMT 2020 1591726831779 Tue Jun 09 18:09:01 GMT 2020 1591726141456 ...
  • 109
0 votes
1 answer
371 views

Expanding Date Command inside single quotes in linux

I am new to linux. I am wondering why date command is not expanding inside single quotes. so if i give command like below d=$(date +%m%d) echo 'A1D$d' Output is A1D$d But If i give without quotes ...
  • 85
0 votes
1 answer
21 views

How to list and put log's name to a file according to date

I have bunch of log files. And some of them are rotated. Say I want to put their name in a txt file. -rw-r----- 1 admin staff 5120126 Apr 20 14:29 access.log00071 -rw-r----- 1 admin ...
1 vote
0 answers
82 views

Sheduling a shell script using crontabs for a rolling 5 hour interval across days [duplicate]

I need to schedule a shell script execution with crontabs to execute it every 5 hours starting from 01:00 and daily. sample execution times: 2020-05-29 01:00 2020-05-29 06:00 2020-05-29 11:00 ...
  • 111
0 votes
0 answers
939 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 "$...
  • 137
0 votes
3 answers
2k views

Time elapsed of a bash script (days/minutes/seconds)

Infact when i want to have an estimated time it took when a script is finished. startdate=$date stuffs enddate=$date I wished to get the difference between these two dates and normally the script ...
1 vote
2 answers
214 views

Is it planned to incorporate the Olson database for TZ in POSIX for `date`?

There is a simpler way to define the value of the timezone, the Olson database. It has been supported for 19 years (Paul Eggert) by Solaris, HP-UX and Tru64. It is certainly supported by AIX as the ...
's user avatar
3 votes
2 answers
500 views

Invalid date when converting timestamp with awk

I'm trying to find a way to convert timestamps in log files to a Unix timestamp. The command I have come up with so far is the following: awk -F'[' '{ print $2}' | awk -F']' '{cmd ="date \"+%s\" -d \"...
  • 593
0 votes
2 answers
267 views

"date" command doesn't show many timezones on Centos 8

On a fresh Centos 8 system, the date command does not show many timezones even though the timezone is properly set by timedatectl and /etc/localtime points to the correct TZ data file. For example: #...
  • 407
0 votes
2 answers
126 views

Sort a column with two different datetime format

I have a tab separated file and the date columns contains date with two different formats. I am using this sort command to sort by one format type ("%a %b %d %H:%M:%S %Z %Y"), but is there any way to ...
  • 109
0 votes
3 answers
375 views

Displaying time and date next to part of the ping output

#!/bin/bash ping -c 1 8.8.8.8 | awk '{print $7}' date So for the code above, I want it to display the date and time in this format below Tue May 5 11:11:11 UTC 2020 time=0.838 ms So far it prints ...
0 votes
3 answers
130 views

Get the epoch time and add it as a new column

I have the following tab separated input file, with timestamps in UTC. How can I calculate the epoch time an add it as a new column? It is a large file with over 60MM rows. a b 0 2020-03-03 15:46:...
  • 109
0 votes
1 answer
613 views

Adjusting the 'date' command to subtract three hours

In a bash script, I have the following 3 lines: D=`date -u +%Y%m%d` H=`date -u +%H` RUNTIME="${D}_${H}00" I need to have the RUNTIME adjusted to 3 hours earlier than the current time. So this would ...
  • 3
1 vote
2 answers
232 views

Find the age of the oldest file in one line

I tried stat -c %Y ./* 2>/dev/null | awk -v d="$(date +%s)" 'BEGIN {m=d} $0 < m {m = $0} END {print d - m}' to find the age of the oldest file in the current directory, and I get a number in ...
  • 11
0 votes
1 answer
98 views

Display time logged in by hour(s) and minute(s)

I am writing a script to display how long a user has been logged in. who | grep "$userid" | awk '{print $1,$3,$4}' | while read user time; do \echo $(($(($(date +%s) - $(date -d "$time" +%s)))/60)) ...
  • 1
5 votes
1 answer
1k views

Generate a random time between 00:00:20 and 10:10:00

I want to generate a somewhat random time signature in a bash script using a variable. I've got a video file that's 11 hours long and I'll be muxing a 50-minute mp3 podcast that I download most ...
  • 361
1 vote
1 answer
369 views

sort datetimestamp column in a csv file from the command line

I have a csv file contains a datetime column format as 1 Mon Mar 02 07:42:29 UT 2020 2 Tue Mar 03 09:02:09 UT 2020 3 Mon Mar 02 01:21:29 UT 2020 I am trying to use the sort, but I dont think ...
  • 109
3 votes
3 answers
908 views

How to sort a zsh array by modification date?

How to sort a zsh array by modification date? files=( ~/a ~/b ~/c ) # how to sort files by date? PS: Here is my exact usecase, (fz is almost fzf) v () { local files files=() command rg '^>' ~...
  • 1,325
0 votes
2 answers
808 views

Copy a file containing date in the file name to a folder for that date

I looked for similar questions, but it was hard to get a clear answer in my case. I use my synology DS1515+ and DSM 6.2.2. First of all, I have been made daily folder containing a date using script ...
  • 33
0 votes
2 answers
870 views

Convert days to date

I want to ask how to convert the number of days from 0000-00-00 to date in Linux? (Note: I saw from epochconverter that it can be converted. For example, 737887 is converted to April 7, 2020, that is ...
  • 3
5 votes
2 answers
747 views

Search for last modified files in the last 2 minutes in your home directory which contain a certain string

I am searching for files in my home directory that were modified in the last two minutes that also contain a certain string. I tried with this command: find -type d -mmin -2 -ls | grep -Ril "...
  • 95
2 votes
3 answers
127 views

Copy a file containing a date in the file name to a folder for that date

I'm newbie in stack overflow. I need your help. Thank you for your reply in advance. I looked for similar questions, but it was hard to get a clear answer in my case. I use my synology DS1515+ and ...
  • 33
1 vote
1 answer
678 views

Bash: sort CSV on date by month,day

I've searched unsuccessfully for a solution to this problem. I have a CSV file with a date field I'm trying to sort by both month and day. CSV format : name,email,phone,date The date field format ...
0 votes
1 answer
611 views

What is the meaning of T Z format in whois output?

I've just notice this format when doing whois just now. What is the meaning of T and Z format in whois output? E.g. user@linux:~$ whois example.com Domain Name: EXAMPLE.COM Registry Domain ID:...
's user avatar
0 votes
1 answer
114 views

Find files from the ISO week number

I would like to find files created in the ISO week number of the year. Those two values will be provided by the user as an arguments. For example user provides the two values: Please specify the ...
0 votes
1 answer
372 views

Replace timestamp format in a file

I have a file which contains the timestamp format like below. '2020-03-07T14:42:36Z UTC [ db=dev user=rdsdb pid=16913 userid=1 xid=5326 ]' LOG: SET statement_timeout TO 120000 I want to change this ...
0 votes
1 answer
50 views

Conditionally bypass records in the .txt file in Linux by comparing fields values within the same file

I need to compare two dates for each line of a .txt file. If value in position 11 is equal to "02407IC" and "21100220" minus "19860220" equal to 124 years, I want to bypass this record, otherwise I ...
2 votes
2 answers
124 views

How to merge common data sets between two files

I am attempting to merge two sets of data file1 is a numerical julian date text file up to 366 to account for leap and nonleap years together. 1 2 3 4 5 6 7 8 9 10 File 2 is a data set which ...
0 votes
2 answers
151 views

Date output in expected format between two dates

I want date output in format like... 01/01/2020 02/01/2020 03/01/2020 04/01/2020 05/01/2020 06/01/2020 07/01/2020 08/01/2020 09/01/2020 10/01/2020 11/01/2020 12/01/2020 13/01/2020 14/01/2020 15/01/...
1 vote
1 answer
6k views

How to set the timezone of a Linux host to BRT (Brasilia Time)?

I've a scenario that needs the timezone on the host to be BRT which is currently PST. I'm expecting the result of date to appear like Wed Jan 30 19:30:36 BRT 2020 I've checked the /etc/localtime ...
  • 111

1 2 3
4
5
23