how to copy all files to different folder with different names

Posted on 2011-04-28
Last Modified: 2012-05-11
I have many data files under /data/file/
I want to use 1 unix command to backup all files to another folder /backup/file/

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

it does not work

Question by:SayYou_SayMe
    LVL 18

    Assisted Solution

    by:Jerry Miller
    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.
    LVL 23

    Accepted Solution

    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

    LVL 23

    Assisted Solution

    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


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Installing FreeBSD… FreeBSD is a darling of an operating system. The stability and usability make it a clear choice for servers and desktops (for the cunning). Savvy?  The Ports collection makes available every popular FOSS application and packag…
    Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
    Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
    Video by: Phil
    This video goes over how to configure and start a jail in FreeBSD.  This video is meant to supplement the article included with this course.

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now