Search code examples
linuxshellunix

Copy files form multiple subdirectories to a different directory


I have multiple sub directories in which i have multiple csv file. I wanted to copy all the files alone into a different directory.

I am able to find or list the files using wildcards

find -name '*.csv' ls /**/'*.csv'

The challenge is all the directory names and file names are having spaces and so am unable to achieve the expected result.


Solution

  • find . -type f -name "*.csv" -exec cp {} Folder \;
    

    In that command, Folder is your different directory. And You have to create that directory before you run this command

    Before you run this command

    • cd to your main directory or Home directory.
    • Create the directory that you want to copy all csv files (mkdir Folder)