Thursday, May 2, 2024
9
rated 0 times [  9] [ 0]  / answers: 1 / hits: 1323  / 3 Years ago, tue, november 2, 2021, 8:21:15

I have a directory containing many similar subdirectories
Each of these subdirectories have some files I am interested in and some that I am not.


I want to copy:


FROM:
two particular files: file1.txt file2.json from every subdirectory


TO: a different location


But making the subdirectories in that location


For example
If I have


base
|_folder_00000001
| |_-file1.txt
| |_ file2.json
| |_some_other_things_I_dont_need
| |_some_other_folder_I_dont_need
|
|_folder_00000002
| |_-file1.txt
| |_ file2.json
| |_some_other_things_I_dont_need
| |_some_other_folder_I_dont_need
|
|_folder_00000003
| |_-file1.txt
| |_ file2.json
| |_some_other_things_I_dont_need
| |_some_other_folder_I_dont_need
|
|_folder_00000004
| |_-file1.txt
| |_ file2.json
| |_some_other_things_I_dont_need
| |_some_other_folder_I_dont_need
|

I want to copy this to another location but excluding the "some other things and folders I dont need"


target
|_folder_00000001
| |_-file1.txt
| |_ file2.json
|
|
|_folder_00000002
| |_-file1.txt
| |_ file2.json
| |
|_folder_00000003
| |_-file1.txt
| |_ file2.json
| |
|_folder_00000004
| |_-file1.txt
| |_ file2.json
|

How can I do this from the bash terminal?


More From » command-line

 Answers
0

You can use cp with --parents:


cd base
cp -v --parents */file1.txt */file2.json ../target/

[#178] Wednesday, November 3, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
antebrow

Total Points: 291
Total Questions: 135
Total Answers: 117

Location: New Caledonia
Member since Thu, Mar 23, 2023
1 Year ago
antebrow questions
Fri, May 14, 21, 04:02, 3 Years ago
Sat, May 14, 22, 14:51, 2 Years ago
Tue, May 3, 22, 21:43, 2 Years ago
Tue, Jan 18, 22, 03:43, 2 Years ago
;