Score:-2

how to copy files with some pattern from multiple directories to a single directory?

cn flag

I have a directory structure

base
|_folder_34231
|         |_23491_this_I_want.csv
|         |_23491_this_I_dont_want.csv
|         |_some_other_things_I_dont_need
|         |_some_other_folder_I_dont_need
|
|_folder_30941
|         |_30912_this_I_want.csv
|         |_30912_this_I_dont_want.csv
|         |_some_other_things_I_dont_need
|         |_some_other_folder_I_dont_need
|
|_folder_55587
|         |_17777_this_I_want.csv
|         |_17777_this_I_dont_want.csv
|         |_some_other_things_I_dont_need
|         |_some_other_folder_I_dont_need
|
|_folder_60920
|         |_83821_this_I_want.csv
|         |_83821_this_I_dont_want.csv
|         |_some_other_things_I_dont_need
|         |_some_other_folder_I_dont_need

I want to copy all of the csv files that finish with "this_I_want" into a single folder(named for example "target") The other files (including the very similar named "this_I_dont_want" file ) should be ignored

How can I do this from the terminal?

muru avatar
us flag
This should be a trivial variation of https://askubuntu.com/questions/1437037/how-can-i-copy-files-from-many-subdirectories-to-another-directory-while-preserv - just omit the `--parents` from `cp`. You know `cp` exists, you know wildcards exist, so what have you tried?
eg flag
Does this answer your question? [How can I copy files from many subdirectories to another directory while preserving directory structure?](https://askubuntu.com/questions/1437037/how-can-i-copy-files-from-many-subdirectories-to-another-directory-while-preserv)
cn flag
@KevinBowen No, that is a different question.
Score:0
cn flag
mkdir mycsv 
find . -name "*this_I_want.csv" -exec cp -p -u {} mycsv \;
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.