Results 1 to 5 of 5

Thread: copy random files overwrite or rename

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

    copy random files overwrite or rename

    I want to copy 1000 random files from a folder and sub folders with many 1000s of files but some of the files have the same name and it prompts me to overwrite but how can I let it over write automatically or rename the file if the file has the same name?

    I am using the following
    Code:
    cp $(find . -iname "test*.ext" -print | shuf -n 100) /home/user/rand
    thanks

  2. #2
    Join Date
    Oct 2013
    Location
    Colorado
    Beans
    560
    Distro
    Xubuntu 20.04 Focal Fossa

    Re: copy random files overwrite or rename

    To overwrite a duplicate filename
    Code:
    cp -f $(find . -iname "test*.ext" -print | shuf -n 100) /home/user/rand
    To rename a duplicate filename
    Code:
    cp --backup=numbered $(find . -iname "test*.ext" -print | shuf -n 100) /home/user/rand

  3. #3
    Join Date
    Apr 2012
    Beans
    7,256

    Re: copy random files overwrite or rename

    For whitespace safety, I can't help feeling you should be using something more like

    Code:
    find . -iname "test*.ext" -print0 | shuf -zn 100 | xargs -0 cp -t /home/user/rand
    (adding either the `-f` or `--backup=numbered` option as described by Keith_Helms)

  4. #4
    Join Date
    Sep 2016
    Location
    Australia
    Beans
    69

    Re: copy random files overwrite or rename

    Some graphic file managers will ask if you want to over-write all or one instance
    Cheers

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

    Re: copy random files overwrite or rename

    thanks for the answers. they work fine

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
  •