New answers tagged

2

Your format string to date is wrong. %I gives the hour in 12 hour format (01..12), you probably want %M, and then your command seems to work (on this linux box - I don't have a synology to try on).


1

The problem is here: '-15 minutes "$n"' Single quotes stop variable substitution, so you're literally passing "$n" in rather than the contents of the variable. Write: /opt/bin/date --date "-15 minutes $n" '+%Y-%m-%dT%H:%I:%S' instead.


1

The first point of call would be man date There you may find the details on setting time with a relative offset, as in date --date '-15 minutes 2016-04-27T14:14:47.836Z' It also offers details about how to format the output.


1

25 seconds was the difference between the POSIX-compliant tz zones and the "right" tz zones during the interval 2012-07-01 until 2015-07-01. If the tzdata is that old and if default time zone for the shell running this command is a POSIX CET and the "-u" time zone is a "right" version of UTC then the "right" code will assume that the system clock violated ...


2

By following the strace of the first command (date): open("/etc/localtime", O_RDONLY) It access the timezone file pointed by /etc/localtime which is /usr/share/zoneinfo/europe/Zurich in my case. So everything fine so far. The strace of the second command (date -u) gave me hints why it wasn't working properly: open("/usr/share/zoneinfo/UTC0", ...


1

Here's a fairly simple solution, based on this answer to the related question discovered by @don_crissti. But I was hoping for something that doesn't use an extra file-- can anyone do better? touch -r some-file.txt .timestamp emacs some-file.txt # Or whatever touch -r .timestamp some-file.txt rm .timestamp


6

Example using bash string manipulation only to extract the date: #!/bin/bash for name in IMG-[0-9]*.jpg; do touch -amt ${name:4:8}0900 "$name" done


1

From your example, assuming that all of the files have a valid yyyymmdd date, you can extract the date from the filename and apply that in the command cited: #!/bin/bash for name in IMG-*-W*.jpg do date="$(echo "$name" | sed -e 's/^IMG-//' -e 's/-W.*//')" touch -a -m -t ${date}0900 "$name" done If some file hasn't a valid date, that is more work. ...


0

There is probably only one thing missing from your example, the option -f to flush the write each time. script -f >(while read;do date;echo "$REPLY";done >>session.log)


0

Sounds like ts, from moreutils. Lots of distros have it packaged. It just prepends timestamps to lines of input. Example use: $ while true; do sleep 1; echo hi; done | ts %s 1461198715 hi 1461198716 hi 1461198717 hi 1461198718 hi [ ... ]


0

this might be a partial solution, depending on your needs: if you include \d \D{} in your PS1 string, each command prompt will include the date and time. that will give you the time at which the previous command finished. in the simplest case, do PS1='\d \D{} $ ' do that after invoking script (or in your .bashrc or whatever) and you will get a ...


3

The command you are looking for is touch with the option -d (or --date) touch - change file timestamp (...) -d, --date=STRING parse STRING and use it instead of current time For example: touch -d '2016-01-15 22:41:18' file or even touch -d '3 months ago' file As always man touch is your friend.


0

Maybe you need a script that you can input the two specific dates and times. Code: #!/bin/bash if [ $# -ne 4 ];then exit 0 fi AAA=$1" "$2 BBB=$3" "$4 awk -v begintime="${AAA}" -v endtime="${BBB}" '$2" "$3>=begintime && $2" "$3<=endtime' exa > newfile.txt


2

The only real problem is that you assign to $AAA and $BBB instead of AAA and BBB. So if you do (nearly the same as your code): AAA="2015-12-11 20:00:00" BBB="2015-12-12 01:00:00" awk '$2" "$3>="'"$AAA"'" && $2" "$3<="'"$BBB"'"' file.txt > newfile.txt it should already work. But I recommend the following further changes in order to reduce ...


-1

awk is not the best tool. sed -e "/^$AAA/,/^$BBB/,p" file.txt and man sed.



Top 50 recent answers are included