I have a folder which contains some folders:
main
\_ Dir 1
\_ Dir 2
\_ ...
\_ Dir 40
I need to open each sub-folder, copy all the files and paste them in another folder, the same folder for all this sub-folder.
How can I do that in a smart way?
The only thing that comes to my mind was create a list with the name of all folders and then use a simple script to open, copy and paste but I'm sure that there is a faster way than write all the names.
Copy a File ( cp ) You can also copy a specific file to a new directory using the command cp followed by the name of the file you want to copy and the name of the directory to where you want to copy the file (e.g. cp filename directory-name ). For example, you can copy grades. txt from the home directory to documents .
The Linux cp command is used for copying files and directories to another location. To copy a file, specify “cp” followed by the name of a file to copy. Then, state the location at which the new file should appear. The new file does not need to have the same name as the one you are copying.
Try:
cp main/*/* /path/to/otherfolder/
If you want to be warned before overwriting a file, use the -i
option:
cp -i main/*/* /path/to/otherfolder/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With