-1

I have a directory (let's call it master) on a server.

Under the directory master, there're many .txt files; some .txt files are under sub-directories in master, say

    /master/text1.txt
    /master/sub-dir1/text2.txt
    /master/sub-dir2/sub-dir3/text3.txt

There are also a big number of other types of files in the master.

What I want to do is to scp all the .txt files under master to my local, and retain the sub-directory structure, i.e. the result looks like

    /local-dir/text1.txt
    /local-dir/sub-dir1/text2.txt
    /local-dir/sub-dir2/sub-dir3/text3.txt

How can I get this done?

1 Answers1

-1

If you need to keep the folder structure, you can try with rsync. Here is an answer you might want to look at: Using Rsync include and exclude options to include directory and file by pattern

I copied the answer below for your reference:

I think the closest thing to what you want is this:

rsync -nrv --include="/" --include="file_11.jpg" --exclude="*" /Storage/uploads/ /website/uploads/

(which will include all directories, and all files matching file_11*.jpg, but no other files), or maybe this:

rsync -nrv --include="/[0-9][0-9][0-9]0000000/" --include="file_11*.jpg" --exclude="*" /Storage/uploads/ /website/uploads/

(same concept, but much pickier about the directories it will include).

You can easily update the command to only include the .txt files.

Mingliang
  • 69
  • 1
  • 6