Re: How to change file's timestamp?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The problem is when I run it at command line, it works, but not in the script:

# touch --date="Tue Aug 22 08:30:00 CDT 2006" t1
works well. However, the script mystmp:

#!/bin/sh
newstmp=$1
touch --date=$newstmp t1

and run mystmp as:
# ./mystmp "Tue Aug 22 08:30:00 CDT 2006"

didn't do what I want, but created:

# ls -l
total 32
-rw-r--r-- 1 root root   0 Aug 22 00:00 08:30:00
-rw-r--r-- 1 root root   0 Aug 22 00:00 2006
-rw-r--r-- 1 root root   0 Aug 22 00:00 22
-rw-r--r-- 1 root root   0 Aug 22 00:00 Aug
-rw-r--r-- 1 root root   0 Aug 22 00:00 CDT
-rwxr-xr-x 1 root root 420 Aug 22 10:47 mystmp
-rw-r--r-- 1 root root   0 Aug 22 00:00 t1

What's wrong? Thanks!

- H.

> man touch
>  (and for the date, man date)
> -B
>
> Hongwei Li wrote:
>> Hi,
>>
>> I need to write a script to change a file's timestamp. I have this script
>> mytmp:
>>
>> #!/bin/sh
>> cd /tmp/test
>> touch t1
>>
>> Then, if I run mytmp, file t1 is created with the current timestamp.  How to
>> change its timestamp in the script after it is created to a specific date
>> and
>> time? If I want to set the date and time as an argument, e.g. I change the
>> script as:
>>
>> #!/bin/sh
>> newstmp=$1
>> cd /tmp/test
>> touch t1
>>
>> and run it as
>>
>> # mytmp "Tue Aug 22 08:30:00 CDT 2006"
>>
>> What should be added in the script to change t1's timestamp to the argument
>> provided?
>>
>> Thanks!
>>
>> Hongwei Li
>>
>>
>
> --
> fedora-list mailing list
> fedora-list@xxxxxxxxxx
> To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
>


[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux