Operating System - HP-UX
1819824 Members
2931 Online
109607 Solutions
New Discussion юеВ

renaming a directory to the current date

 
Diebold_Unix_Support
Occasional Advisor

renaming a directory to the current date

I was trying to rename a directory using the below command, but it is not working, please help.

j1=`date | cut -c 5-7,9-10,25-28`

mv /mnt/temp /mnt/temp$j1

Thanks
SP
4 REPLIES 4
Yogeeraj_1
Honored Contributor

Re: renaming a directory to the current date

hi SP,

the first line is not returning the expected string:
$ j1=`date | cut -c 5-7,9-10,25-28`
$ echo $j1
Apr 82008
$

the Space in "Apr 82008" is the cause of the error.

Try somthing simpler:
j1=$(date +'%b%d%Y')


e.g.
$ j1=$(date +'%b%d%Y')
$ echo $j1
Apr082008


hope this helps!

kind regards
yogeeraj
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)
Diebold_Unix_Support
Occasional Advisor

Re: renaming a directory to the current date

Thank you very much, it helps.

SP
Davis Paul
Valued Contributor

Re: renaming a directory to the current date

Hi,
Check with the following:
j1=`date | cut -c 5-7,9-10,25-28`
j1=`echo $j1 | sed -e "s/ //g"`
mv /mnt/temp /mnt/'temp'$j1

Davis Paul

Diebold_Unix_Support
Occasional Advisor

Re: renaming a directory to the current date

Thanks for providing the solution.

SP