Results 1 to 4 of 4

Thread: copy file from sub folders to folder?

  1. #1
    Join Date
    Oct 2008
    Location
    /usr/bin/
    Beans
    493
    Distro
    Ubuntu

    copy file from sub folders to folder?

    How can I copy all files from a folder and all sub folders in to another folder?

    example

    copy all images from the following folders
    folder1 (has 100 images)
    folder2 (has 100 images)
    folder3 (has 100 images)
    folder4 (has 100 images)

    copy them to a new folder "folder5 (which will then have 400 images inside "not the folders, only the images)

    but if the images have the same name then auto rename them?

    thanks

  2. #2
    Join Date
    Oct 2008
    Location
    /usr/bin/
    Beans
    493
    Distro
    Ubuntu

    Re: copy file from sub folders to folder?

    I figured out the copy part but I dont know how to do the rename if the same file name exists?

    find -iname "*jpg" -exec cp "{}" /new_folder/. \;
    Last edited by sohlinux; September 13th, 2012 at 03:22 PM.

  3. #3
    Join Date
    Feb 2007
    Location
    Romania
    Beans
    Hidden!

    Re: copy file from sub folders to folder?

    You need a glob which matches all the files. Then you can use the cp command with its --backup option to copy them to the new directory. Something like:

    Code:
    cp --backup=numbered -- */*.jpg directory5

  4. #4
    Join Date
    Oct 2008
    Location
    /usr/bin/
    Beans
    493
    Distro
    Ubuntu

    Re: copy file from sub folders to folder?

    Quote Originally Posted by sisco311 View Post
    You need a glob which matches all the files. Then you can use the cp command with its --backup option to copy them to the new directory. Something like:

    Code:
    cp --backup=numbered -- */*.jpg directory5
    thanks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •