Increment time stamps.

Hi Gents.

Please can you help me to solve a problem.

I have a long list of files, which I need to change the time stamp.

-r--r--r--  1 geo2 geovect 47096216 Feb  8 10:40 00000009.segd
-r--r--r--  1 geo2 geovect 47096216 Feb  8 10:40 00000010.segd
-r--r--r--  1 geo2 geovect 47096216 Feb  8 10:40 00000011.segd
-r--r--r--  1 geo2 geovect 47096216 Feb  8 10:40 00000012.segd
-r--r--r--  1 geo2 geovect 47096216 Feb  8 10:40 00000013.segd
-r--r--r--  1 geo2 geovect 47096216 Feb  8 10:40 00000014.segd
-r--r--r--  1 geo2 geovect 47096216 Feb  8 10:50 00000015.segd
-r--r--r--  1 geo2 geovect 47096216 Feb  8 10:50 00000016.segd
-r--r--r--  1 geo2 geovect 47096216 Feb  8 10:50 00000017.segd
-r--r--r--  1 geo2 geovect 47096216 Feb  8 10:50 00000018.segd

I would like to increment the time stamp for each file one minute,,
I am using the comand:

touch -t 1302081040.00 00000009.segd
touch -t 1302081042.00 00000010.segd
touch -t 1302081043.00 00000011.segd

But I can't do it one by one :frowning:

I would like to have something like this:

-r--r--r--  1 geo2 geovect 47096216 Feb  8 10:40 00000009.segd
-r--r--r--  1 geo2 geovect 47096216 Feb  8 10:41 00000010.segd
-r--r--r--  1 geo2 geovect 47096216 Feb  8 10:42 00000011.segd
-r--r--r--  1 geo2 geovect 47096216 Feb  8 10:43 00000012.segd
-r--r--r--  1 geo2 geovect 47096216 Feb  8 10:45 00000013.segd
-r--r--r--  1 geo2 geovect 47096216 Feb  8 10:46 00000014.segd
-r--r--r--  1 geo2 geovect 47096216 Feb  8 10:47 00000015.segd
-r--r--r--  1 geo2 geovect 47096216 Feb  8 10:48 00000016.segd
-r--r--r--  1 geo2 geovect 47096216 Feb  8 10:49 00000017.segd
-r--r--r--  1 geo2 geovect 47096216 Feb  8 10:50 00000018.segd

Thanks in advance

If you know perl it should be a simple script.

Please there is something in AWK... I don't Perl:(

try:

ls -1 *.segd | awk '{printf "touch -t %d.00 %s\n", tt++, $0}' tt=1302081040 | sh

or

tt=1302081040
for fl in *.segd
do
   touch -t $tt.00 $fl
   (( tt = tt + 1 ))
done
1 Like

Do you have a GNU date on your system?

i.e. a date command that supports something like this:

$ date -d 'Feb  8 10:47 + 1 min'
Fri, Feb 08, 2013  7:48:00 PM
1 Like

Hi rdrtx1

ls -1 *.segd | awk '{printf "touch -t %d.00 %s\n", tt++, $0}' tt=1302081040 | sh

This command works perfect.. But I would like to increment the hour also, when the last minute reach 59..
Example 081059
next file will be 081100
Thanks for your cooperation

---------- Post updated at 04:03 AM ---------- Previous update was at 02:18 AM ----------

Rdrtx1

This script works fine also,

tt=1302081040 for fl in *.segd do    touch -t $tt.00 $fl    (( tt = tt + 1 )) done

But I notice that it runs the increse the seconds from 0 until 100 interval 1sec,, There is opcion to midify it in order to make the touch -t from 0 to 59, then increase the minute
Example
previous file time 081059
next file time shuold be 081100

Thanks in advance

This is why I asked if you have GNU date as it does a lot of this time/date processing for us and makes the increment code much simpler (thinking about times close to midnight on the last day of the month).

1 Like

Chubler XL

I have more than 1000 files to change the time stamp in order increment,,, Please can you help me.. to solve the problem.
Thanks in advance.

Try this:

OLDEST=$(ls -rt1 *.segd | head -1)
SECS=$(date -r $OLDEST +%s)

ls -rt1 *.segd | while read file
do
    let SECS=SECS+60
    touch -t $(date -d @$SECS +%Y%m%d%H%M) "$file"
done
1 Like

Chubler_XL

It is working fine,, Thanks a lot..

I notice that your scrip take the date and time for the fist file.

How I can assign a specific date entered manually... for the first file ,, can be a variable.. For example ..

And then your scrip will take this date and make the process...For example .. I will like to start on Feb 08 06:00 and then next file shoulbe Feb 08 06:01.... ...

The main point in this case is that I need to change the time and date stamp, using a old date an time.

Your help is really appreciated.

---------- Post updated at 06:17 AM ---------- Previous update was at 06:00 AM ----------

Chubler_XL

I got it like this:

#!/bin/bash

touch -t 1302080500.00 *.*
                      
OLDEST=$(ls -t1 *.segd | head -1)
SECS=$(date -r $OLDEST +%s)

ls -t1 *.segd | while read file
do
    let SECS=SECS+60
    touch -t $(date -d @$SECS +%Y%m%d%H%M) "$file"
done

Thanks for your help

---------- Post updated at 06:48 AM ---------- Previous update was at 06:17 AM ----------

Chubler_XL

I fix it as following

#!/bin/bash

tape=$1
p1=$2 # Motnh
p2=$3 # Day
p3=$4 # Hour
p4=$5 # Min

cd /mnt/data1/SEGD/tape"$tape"

touch -t 13"$p1""$p2""$p3""$p4".00 *.*
                      
OLDEST=$(ls -t1 *.segd | head -1)
SECS=$(date -r $OLDEST +%s)

ls -t1 *.segd | while read file
do
    let SECS=SECS+60
    touch -t $(date -d @$SECS +%Y%m%d%H%M) "$file"
done

usage: fix_timestamps 2984 02 08 00 00

Thanks

Yes your solution looks fine, you can improve performance by just using the passed param to set the SECS var like this:

tape=$1

if [ $# -eg 2 ]
then
    SECS=$(date -d "$2" +%s)
else
    SECS=$(date -d "$2/$3 ${4:-00}:${5:-00}" +%s)
fi

cd /mnt/data1/SEGD/tape"$tape"

for file in *.segd
do
    let SECS=SECS+60
    touch -t $(date -d @$SECS +%Y%m%d%H%M) "$file"
done

Usage:

fix_timestamps tape datestr
fix_timestamps tape month day [hour [min]]>

eg:

fix_timestamps 7593 02 08
fix_timestamps 7590 02 08 14 51
fix_timestamps 7592 "last tuesday"
fix_timestamps 7592 "today -3 days"
fix_timestamps 7592 "Feb 16 2008"
1 Like

Appreciate your support.. Thanks