New answers tagged date
7
votes
What's the POSIX-compliant way to get the epoch timestamp in a shell?
You can do it with a custom date format string that produces a shell arithmetic expression for the POSIX formula for seconds since the epoch:
secs=$((`TZ=GMT0 date \
+"((%Y-1600)*365+(%Y-1600)/4-(...
-3
votes
What's the POSIX-compliant way to get the epoch timestamp in a shell?
time=$(perl -e 'print time, "\n"')
27
votes
What's the POSIX-compliant way to get the epoch timestamp in a shell?
For the epoch time as an integer number of seconds, that would be:
awk 'BEGIN{srand(); print srand()}'
or:
awk 'BEGIN{print srand(srand())}'
As in POSIX awk, srand() without argument uses the ...
12
votes
What's the POSIX-compliant way to get the epoch timestamp in a shell?
Write a C program that calls time() and prints the result. Borrowing from sample program in the specification of the time() function, let's call this e.g. seconds.c:
#include <stdio.h>
#include &...
1
vote
Setting time zone in a kindle bash file
There was something going wrong in the kindle, no matter how much I tried to solve it or change the timezone. but what worked is adding this line
MinuteOTheDay=$(expr \( $MinuteOTheDay + 400 \) % 2400)...
-1
votes
Setting time zone in a kindle bash file
Use GMT0, and consider the difference between that timezone relative to you, which is -4hrs:
MinuteOTheDay="$(env TZ=GMT0-4 date -R +"%H%M")";
Based on this answer:
https://unix....
1
vote
Bash script/awk to input and output a CSV file
Using Raku (formerly known as Perl_6)
perl6 -MText::CSV -e 'my @a = csv( in => $*IN ); my $date = Date.today; \
@a>>.[2] = @a.map: *.[2].subst(/ (\d**2) \/ (\d**2) \/ (\d**4) /, {&...
0
votes
Cron entry for last Saturday of every month
What about this:
45 23 */25,*/26,*/27,*/28,*/29,*/30,*/31 * SAT
I have not tried this, but Crontab Guru says it's possible:
1
vote
Purge lines in a file based on age in shell script
cutoff=$( date -d "30 days ago" "+%s" )
while read -r line ; do
timestamp=$( date -d"$( echo $line | cut -d: -f1,2,3 )" "+%s" )
if [ $timestamp -gt $cutoff ...
0
votes
How to know last Sunday of month
I found this article when trying to get the last thursday, but it would work for any other day too. Here is my solution (compatible with Bash):
thisThursInMonth=`date +%m`
nextThursInMonth=`date -d '...
0
votes
bash: cd to the most recently modified child directory
Without relying on the output of ls, and assuming GNU coreutils:
cd "$(stat --printf='%Y:%n\0' ./*/ | sort -zt: -k1nr | head -zn1 | cut -zd: -f2-)"
0
votes
Use dynamic date in systemd unit
You can write dynamic parts into an environment file and use the variables later. Something like this:
[Unit]
Description=TCS minetest server unit
[Service]
Type=simple
EnvironmentFile=-/dev/shm/tcs....
10
votes
Accepted
Is my zoneinfo backwards or am I confused
There are actually two main ways to use the TZ variable. The older one is specified in the POSIX standards, and it can encode the timezone and the current year's Daylight Saving Time rules in the ...
2
votes
Accepted
FreeBSD - get timezone in Continent/Region format
This command will provide what you are looking for:
cd /usr/share/zoneinfo && find . -type f -exec cmp -s /etc/localtime '{}' \; -print | sed -e 's|^\./||' -e '/posix/d'
Output (I'm in the US ...
0
votes
How do I set the date to the epoch of a linux (raspbian flavor) system, i.e., 1 January 1970 00:00:00?
After I posted my question the StackExchange system suggest this related question sp the mystery is solved.
0
votes
zdump and date do not show the same daylight saving information
(Copied from question into an answer.)
Fixed by updating Busybox to a newer version. Thanks @thanasisp, by looking for more info I fixed the issue.
Community wiki
Top 50 recent answers are included
Related Tags
date × 1100bash × 191
shell-script × 189
linux × 184
shell × 109
files × 86
time × 80
awk × 77
timezone × 70
timestamps × 67
text-processing × 65
command-line × 57
find × 50
scripting × 42
sed × 38
logs × 34
sort × 32
grep × 31
cron × 30
debian × 26
macos × 23
locale × 22
rename × 21
filenames × 20
solaris × 19