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
>

-- 
fedora-list mailing list
fedora-list@xxxxxxxxxx
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
[Index of Archives]     [Older Fedora Users]     [Fedora Announce]     [Fedora Package Announce]     [EPEL Announce]     [Fedora Magazine]     [Fedora News]     [Fedora Summer Coding]     [Fedora Laptop]     [Fedora Cloud]     [Fedora Advisory Board]     [Fedora Education]     [Fedora Security]     [Fedora Scitech]     [Fedora Robotics]     [Fedora Maintainers]     [Fedora Infrastructure]     [Fedora Websites]     [Anaconda Devel]     [Fedora Devel Java]     [Fedora Legacy]     [Fedora Desktop]     [Fedora Fonts]     [ATA RAID]     [Fedora Marketing]     [Fedora Management Tools]     [Fedora Mentors]     [SSH]     [Fedora Package Review]     [Fedora R Devel]     [Fedora PHP Devel]     [Kickstart]     [Fedora Music]     [Fedora Packaging]     [Centos]     [Fedora SELinux]     [Fedora Legal]     [Fedora Kernel]     [Fedora OCaml]     [Coolkey]     [Virtualization Tools]     [ET Management Tools]     [Yum Users]     [Tux]     [Yosemite News]     [Gnome Users]     [KDE Users]     [Fedora Art]     [Fedora Docs]     [Asterisk PBX]     [Fedora Sparc]     [Fedora Universal Network Connector]     [Libvirt Users]     [Fedora ARM]

  Powered by Linux