0

i have many files inside a directory1(libX11.so.6, tm.txt, ff.txt..and so on), i need to copy these files of directory1 to many other directories named as directory2,3.......100000. I tried find command but its not working.My sample online code is given below.can anybody suggest some better solutions using shell or python...Thanks in advance.

find . -type f -name "libX11.so.6, tm.txt, ff.txt" -exec cp -rv {} /home/geo/data/directory{2...100000} \;

while doing this it shows errors

2 Answers2

0

You could use the python library shutil to achieve this, code to make this work is below:

import shutil

shutil.copy(src, dst)
Algebra8
  • 1,115
  • 1
  • 10
  • 23
AyanSh
  • 324
  • 1
  • 10
  • Thanks for ur reply...however how to set my above problem inside this shutil..can u please suggest –  Sep 05 '20 at 06:38
  • How you use it is where it says src you type the location of the folder so C:/user and if you do this it will copy everything in the user folder and copy it to your destination so that could be C:/file a file folder – AyanSh Sep 05 '20 at 06:40
  • Anyway i use ubuntu –  Sep 05 '20 at 06:49
  • Look at this post to find out how to use it on ubuntu, https://stackoverflow.com/questions/20020177/python-shutil-copy-fails-on-fat-file-systems-ubuntu – AyanSh Sep 05 '20 at 06:51
0

The following code will copy all your original_dir files to the destination_dir.
I believe you can do some customized changes to get what you want.

import os
from shutil import copyfile

original_dir = "/path/to/the/original/dir"
original_files = os.listdir(original_dir)

destination_dir = "/path/to/your/destination/dir"

for each in original_files:
    current_file = os.path.join(original_dir, each)
    # check if it is a file
    if not os.path.isdir(current_file):
        # print(each + " is being processing")
        copyfile(current_file, destination_folder + each)

s3cret
  • 354
  • 2
  • 10