New answers tagged

2 votes

How to change the modification date (The Metadata) of multiple files?

Update: If I am wrong with this answer please let me now. I'm not sure if file system's modification date metadata is equivalent to exitf modification date metadata. I tested with exiftool and the ...
1 vote

Why does `date` ignore TZ environment variable?

The correct, standard and portable way to define via $TZ a time zone that is called UTC and is on (with 0 offset to) Universal Time all year round is with: TZ=UTC0 That is self-contained and give the ...
0 votes

Copy a file and append a timestamp

If the original file name were test1.txt, this copy statement copies it and concatenates a date-time stamp onto the original file-name in the current directory: cp test1.txt{,.$(date +%Y%m%d%H%m%s)} ...
0 votes

Get date of next Saturday from a given date

Maybe this is more straight forward than some of the other answers: startdate=30-AUG-2015 weekday=saturday date -d "$startdate + $(( (`date +%u -d $weekday` - `date +%u -d $startdate` + 7 ) % 7 ))...
  • 383
1 vote
Accepted

Script - Compare filename date with current date

The script I'm looking for has to print only the newest of all older than today files. I would suggest that you simply build a list of the filenames that exist, remove names matching the current date,...
  • 5,943
2 votes

Script - Compare filename date with current date

That is what loops are for: #!/bin/bash for FILE in /some/directory/File156tr.*.*.txt do FROM_FILE=$(echo $FILE | grep -Eo '[[:digit:]]{8}') NOW=$(date +"%Y%m%d") DIFFERENCE=$(($NOW -...
  • 2,285
11 votes

Precision of the date command and arithmetic

As others have said, most decimal representations of floating point numbers cannot be represented exactly in binary formats which are the ones computers use for computations. All you see with printf %....
5 votes
Accepted

Precision of the date command and arithmetic

Yes, some imprecision is to be expected using floats, that is an unavoidable result of using a limited set of bits, or bytes to express a real number. Or also called a number with several fractional ...
2 votes

Precision of the date command and arithmetic

There is an additional source of error. date returns %s and %N from different hardware clocks, and both are integers. The nanosecond value depends on whether high-resolution timers are available: even ...
  • 6,763
5 votes

Precision of the date command and arithmetic

Binary floating point math is like this. In most programming languages, it is based on the IEEE 754 standard. The crux of the problem is that numbers are represented in this format as a whole number ...
  • 14.7k
1 vote

Read and convert date from file

$ let diff=($(date +%s -d 'today')-$(date +%s -f VM1_EOMAP_TIME.log))/60 $ echo "$diff"
  • 2,139
1 vote

Read and convert date from file

Your problem is quoting. And that you should use date -u to compensate for timezone. $ echo "07 Sep 2022 16:30" > infile $ var="$(<infile)" $ cat infile; echo "$var"...
1 vote

Read and convert date from file

If your bash is recent, the current time in epoch seconds is builtin: $EPOCHSECONDS Otherwise, bash's printf can get it with the %(fmt)T directive and magic value "-1": printf -v ...
0 votes

Installation date of Ubuntu

When dumpe2fs and findmnt are not installed (on Synology DSM v6 for example) type : $ sudo tune2fs -l $(LANG=C df / --output=source | grep -v Filesystem) | grep created: Filesystem created: Sat ...
  • 1,539
0 votes

Get date of Monday two weeks ago from particular date using GNU date

I tried to take a "reusable tool" approach. My monday script: #!/bin/bash date=${1:-now} shift dow=`date +%u -d "$date"` dow0=$[ $dow - 1 ] date -d "$date -$dow0 days" &...

Top 50 recent answers are included