Operating System - HP-UX
1747980 Members
4601 Online
108756 Solutions
New Discussion юеВ

Re: Rename a number of files

 
Fenglin
Regular Advisor

Rename a number of files

Hi,

I would like to rename a number of files located in the same directory from *job to *job.date

Is it possible?

Regards
Feng Lin
7 REPLIES 7
Sajjad Sahir
Honored Contributor

Re: Rename a number of files

Dear Fenglin

Please check the link

http://www.informatik.uni-frankfurt.de/doc/man/hpux/mv.1.html

thanks and regards

Sajjad Sahir
Nido
Trusted Contributor

Re: Rename a number of files

Hello Feng Lin,

This will do: ( Please Check it)
Change the date format if you wish to..

for I in `ls -1 *.job`
do
mv ${I} ${I}.`date "+%Y%m%d"`
done


Thanks,
" Let Villagers Be Happy!! "
Fenglin
Regular Advisor

Re: Rename a number of files

Hi,

I would like to do it in 1 command line. This means I want a number of files with extension .job to change to .job.date

Any such commands?
Basheer_2
Trusted Contributor

Re: Rename a number of files

Nedo's script works.

this is a little difft
for file in *
do
mv ${file} ${file}.`date "+%Y%m%d"`
done

are you trying to move entire dirs or is this in one dir.
Fenglin
Regular Advisor

Re: Rename a number of files

Thanks, it works.

was wondering whether it can be done in 1 command line.

Cheers
Feng Lin
Sagar Sirdesai
Trusted Contributor

Re: Rename a number of files

Hi
Please try the below 2 commands
find /dir -type f -name "*job" -print |xargs -t -I {} mv {} {}.date

cd /dir
ls |xargs -t -I {} mv {} {}.date

Sagar
Dennis Handly
Acclaimed Contributor

Re: Rename a number of files

>was wondering whether it can be done in 1 command line.

Only if you write your own script/command.
Why do you care? You want something you can understand/maintain.

>Nido: mv ${I} ${I}.`date "+%Y%m%d"`

It might be a good idea to get the date once before the loop.
t_stamp=$(date "+%Y%m%d")
for I in *.job; do
mv ${I} ${I}.$t_stamp
done