• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 354
  • Last Modified:

how to copy all files to different folder with different names

I have many data files under /data/file/
IBM.txt
DELL.txt
GOOGLE.txt
..
..
I want to use 1 unix command to backup all files to another folder /backup/file/
IBM.bkp
DELL.bkp
GOOGLE.bkp
..
..

cp /data/file/*.txt /backup/file/*.kbp

it does not work


0
SayYou_SayMe
Asked:
SayYou_SayMe
  • 2
3 Solutions
 
Jerry MillerCommented:
I probably wouldn't rename the files since they are going into a backup directory anyway so cp /data/file/*.txt /backup/file/ should work fine.


But you could combine two commands, something like

cp /data/file/*.txt /backup/file/ && mv /backup/file/*.txt /backup/file/*.kbp

With the && control, the second command only runs if the first one runs successfully.


http://www.ibm.com/developerworks/aix/library/au-badunixhabits.html#three
0
 
Kamaraj SubramanianApplication Support AnalystCommented:
check whether this works or not
for i in `ls /data/file/`; do fname=${i%\.???}; cp /data/file/$i /data/file/$fname.bak; done

Open in new window

0
 
Kamaraj SubramanianApplication Support AnalystCommented:
change in destination and this will copy all the files ( not only the txt files )
for i in `ls /data/file/`; do fname=${i%\.???}; cp /data/file/$i /backup/file/$fname.bak; done

Open in new window

0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now