Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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/tempabc.txt
def.txt
ghi.txtFolder needed to replace.
/opt/app/test/abc.txt
def.txt
ghi.txt

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

![]() |
![]() |
![]() |
| Login or Register to Reply | |
| Login | Register |
| Ads by Google |