2022 Developer Survey is open! Take survey.

New answers tagged

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-(...
user avatar
-3 votes

What's the POSIX-compliant way to get the epoch timestamp in a shell?

time=$(perl -e 'print time, "\n"')
user avatar
  • 795
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 ...
user avatar
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 &...
user avatar
  • 115k
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)...
user avatar
-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....
user avatar
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) /, {&...
user avatar
  • 1,098
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:
user avatar
  • 1
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 ...
user avatar
  • 25.2k
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 '...
user avatar
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-)"
user avatar
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....
user avatar
  • 133
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 ...
user avatar
  • 66.9k
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 ...
user avatar
  • 9,483
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.
user avatar
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.

Top 50 recent answers are included