Computing.Net > Forums > Unix > How to copy files and replace it.

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

How to copy files and replace it.

Reply to Message Icon

Name: ntc2000
Date: August 17, 2009 at 08:24:37 Pacific
OS: Windows Vista
Subcategory: Configurations
Comment:

I m new to unix command, can everyone guide me for below scenario. I need to copy the files in temp folder and replace it in test folder. Before overwrite it, I need to backup the existing file in test folder and move it to /opt/app/test/backup folder.

Folder that contain several files to copy:
/opt/app/temp

abc.txt
def.txt
ghi.txt

Folder needed to replace.
/opt/app/test/

abc.txt
def.txt
ghi.txt



Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: August 17, 2009 at 12:27:06 Pacific
Reply:

a way .... this korn shell should do what you want. When you are sure it works, change the cp, copy, to mv, move. No error checking; script assumes directories exist:

#!/bin/ksh

tempdir="/opt/app/temp"
testdir="/opt/app/test"
backupdir="/opt/app/test/backup"

# change directory where the files are
cd $tempdir

# grab each file with a txt extension
for file in *.txt
do
   fileloc=${testdir}/${file}
   if [[ -f $fileloc ]]
   then
      cp $fileloc ${backupdir}
   fi
   cp ${file}  ${testdir}
done


0

Response Number 2
Name: ntc2000
Date: August 17, 2009 at 20:09:32 Pacific
Reply:

thank you nails ...really appreciate ur help.

its work great for me.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More






Use following form to reply to current message:

Login or Register to Reply
LoginRegister


Sponsored links

Ads by Google


Results for: How to copy files and replace it.

how to replace a file and save it i www.computing.net/answers/unix/how-to-replace-a-file-and-save-it-i/7216.html

how to extract files and redirect r www.computing.net/answers/unix/how-to-extract-files-and-redirect-r/4152.html

how to find files and move to direc www.computing.net/answers/unix/how-to-find-files-and-move-to-direc/4822.html