AnswerBun.com

How to use scp with recursion and file mask for multiple extensions?

I’m trying to recursively download a directory, but only files with certain extensions from it, while also maintaining the directory structure.

The command I’m using now is
scp -rp [email protected]:"/path/to/directory/foo/*.{jpg,mp4}" ~/local/directory/foo/. Which a) requires me to create directory foo locally, and b) it only downloads files in the root directory (recursion doesn’t work).

The command I used before this was scp -rp [email protected]:"/path/to/directory/foo" ~/local/directory/, which didn’t have either of those problems, but downloads all the files I don’t need as well.

Unix & Linux Asked by Renox92 on December 27, 2020

1 Answers

One Answer

I don't think this is possible with scp. You can either copy all files recursively or selected file types non-recursively. Note that you don't need to escape the ..

But you could use rsync:

rsync -avm --include='*/' --include='*.jpg' --include='*.mp4' --exclude='*'
  [email protected]:/path/to/directory/foo ~/local/directory/

Options used:

  • -a archive mode
  • -v increase verbosity
  • -m prune empty directories
  • --include='*/' include subdirectories
  • --include='*.jpg' include *.jpg files
  • --include='*.mp4' include *.mp4 files
  • --exclude='*' exclude other file types

Answered by Freddy on December 27, 2020

Add your own answers!

Related Questions

Viewing (monitoring) line status of a serial port

1  Asked on February 4, 2021 by anton-samsonov

   

How to list files – sorted by both filename and modified date?

1  Asked on February 3, 2021 by gabor-faludi

     

Specify rootfs mount options

1  Asked on February 3, 2021 by iron-oxidizer

     

PulseAudio module-remap-source blocks shutdown

0  Asked on February 2, 2021 by konrad-hffner

   

Gedit doesn’t work in Kali 2020

0  Asked on February 1, 2021 by mate-mre

       

Trying to Install Linux Alongside Windows 10

2  Asked on January 30, 2021 by jackson-a-cubbage

     

EasyTether Internet Disconnect on OpenWRT Router

0  Asked on January 30, 2021 by jack-nelson

   

Issues installing Nvidia drivers in Debian 9

1  Asked on January 29, 2021 by axiomsword

     

Ask a Question

Get help from others!

© 2022 AnswerBun.com. All rights reserved.