Languages and Scripting
Showing results for 
Search instead for 
Do you mean 

Script to add date×tamp on the filename.

SOLVED
Go to Solution
Highlighted
Regular Advisor

Script to add date×tamp on the filename.

Hi,
I want to know whether it is possible to have date&timestamp on the filename. The question over here is i can put the date&timestamp on the filename. But i want the date&timestamp on the filename as of India time. As we have servers in US in pacific timezone i.e. PDT. The script will run on this US server but when it will put the date&timestamp on the filename it should be of India time. Please can someone help me how to write the date conversion i.e. PDT to IST conversion logic in the script as below,
#!/bin/ksh
cd /SID/TEST/IN/Out
Datestamp=$(date +%Y%m%d%H%M)
file=$(ls *)
for x in $file
do
mv $x /backup/$x.$Datestamp
done

Thanks,
Narendra
2 REPLIES
Acclaimed Contributor Acclaimed Contributor

Re: Script to add date×tamp on the filename.

>help me how to write the date conversion i.e. PDT to IST conversion

You let the computer do it:
Datestamp=$(TZ=IST-5:30 date +%Y%m%d%H%M)

You can also combine these lines to:
for x in *; do
mv $x /backup/$x.$Datestamp
done
Regular Advisor

Re: Script to add date×tamp on the filename.

Thanks Dennis it works great...