Hot answers tagged

6

In a POSIX shell: case $yy in ([[:digit:]][[:digit:]][[:digit:]][[:digit:]]) echo OK;; (*) echo >&2 not OK;; esac Which you could also put in a function like: valid_year() case $1 in ([[:digit:]][[:digit:]][[:digit:]][[:digit:]]) true;; (*) false;; esac And then use in an if construct like: if valid_year "$yy"; then echo ...


6

On Linux, or any system that uses GNU date: $ thedate=2019-08-15 $ date -d "$thedate" +'%B %e, %Y' August 15, 2019 On macOS, OpenBSD and FreeBSD, where GNU date is not available by default: $ thedate=2019-08-15 $ date -j -f '%Y-%m-%d' "$thedate" +'%B %e, %Y' August 15, 2019 The -j option disables setting the system clock, and the format string used with -...


4

POSIXly: for file in ??-??-????' '*.xml; do date=${file%% *} year=${date##*-} day=${date%%-*} month=${date%-*} month=${month#*-} touch -d "$year-$month-$day 00:00:00" -- "$file" done With zsh, you can shorten it to: for f (??-??-????' '*.xml(N)) touch -d "$f[7,10]-$f[4,5]-$f[1,2] 00:00:00" -- $f


4

Assuming that you have access to GNU date, something along $ date --date="2019-08-15" "+%B %d, %Y" August 15, 2019 Check the manpage of date (man date).


4

I can't reproduce “Invalid argument” for exactly the epoch on an older system, but: # strace date -s '@-1' … clock_settime(CLOCK_REALTIME, {4294967295, 0}) = -1 EINVAL (Invalid argument) settimeofday({4294967295, 0}, NULL) = -1 EINVAL (Invalid argument) write(2, "date: ", 6date: ) = 6 write(2, "cannot set date", 15cannot set date) ...


2

It turns out that this is not in the Linux kernel, but in systemd. The systemd clock utility has a minimum clock value defined at build time, and if the time read from the RTC is prior to that clock time, it will force the system clock to that minimum time. This "minimum time" may be specified by the Meson build system, or it is read from the creation time ...


2

Try sort -t. -k 3,3 -k 2,2 -k 1,1 <filename Sets the delimiter to be "." and then sorts by key 3 (yyyy), 2 (mm), 1 (dd)


2

With relatively recent versions of procps, you can use etimes as the elapsed time as a number of seconds: ps -Ao etimes= -o pid= | awk -v n=30 '$1 >= n*86400 {print $2}' | xargs -r kill (here assuming GNU xargs for its -r option) Or: ps -Ao etimes= -o pid= | awk -v n=30 '$1 >= n*86400 {print "kill", $2}' | sh With older versions, you can ...


1

The problem here seems to be with the single-quotes in $DATEJ. Your variable imposes them. Change that to DATEJ=`echo -n "2012-03-02 22:00"` and in the final command: date -d "$DATEJ EDT" +%s This will work: $ date -d '2012-03-02 22:00 EDT' +%s 1330740000 $ DATEJ=`echo -n "2012-03-02 22:00"` $ echo $DATEJ 2012-03-02 22:00 $ date -d "$DATEJ EDT" +%s ...


1

You can set TZ to your local time zone on the remote system when you log in, e.g. in your shell’s startup script if you have your own account and you always log in from the same timezone. That will result in timestamps which are recalculated when output to be displayed in your chosen time zone: for example, timestamps shown in the output of ls. However you ...


1

This can happen if the current timezone's idea of epoch is before the (UTC) Unix epoch. Such times just can't be represented.


1

Based on your comment regarding the current time being Thu Aug 1 15:13:26 CEST 2019, my theory is that the xdebug log is running (or logging) in UTC, which is two hours earlier than CEST. It's unfortunate that the timezone doesn't appear to be part of the output; that leaves the actual time ambiguous for any cross-referencing, as you've seen. I found a ...


Only top voted, non community-wiki answers of a minimum length are eligible