I have a server with Ubuntu 18.04

I want to transfer my website to a new server.

Here are my questions :

How to copy files with png extension ? I tried the following command line but it doesn't work :

$ sudo scp -r -p [email protected]:/var/www/www-example-com/web/*.png/ /home/ubuntu/www-example-com/web/

How to copy the following folder excluding a folder inside ?

$ sudo scp -r -p [email protected]:/var/www/www-example-com/web/themes/custom/ /home/ubuntu/www-example-com/web/themes/custom/

I want to exclude the below folder from the above folder :


2 Answers 2


You say your scp command "does not work"; can you give more information on that? I'm sure the command outputs something. Could you share that?

Anyway, your top command has a superfluous / in it. / is the character in Linux that is used as directory separator. So /home/mathieu/ would be "directory mathieu inside directory home". Files do not end with a /.

Instead of sudo scp -r -p [email protected]:/var/www/www-example-com/web/*.png/ /home/ubuntu/www-example-com/web/...

...try to write sudo scp -r -p [email protected]:/var/www/www-example-com/web/*.png /home/ubuntu/www-example-com/web/ (Notice the lack of / after *.png.)

On a sidenote: only prefix commands with sudo if you really need to run that command as super user. In this case, if your current user is owner of /home/ubuntu/www-example-com/web/, sudo is not needed. If you make a mistake in a command and used sudo, this might go horribly wrong. Ranging from "Oh well, I can live withouth that file anyway" to "Oh shoot - this is going to take a reinstall" or worse.

About the second question (on excluding a subdirectory), I have no fitting answer.

  • OK, thanks. SUDO is in danger of breaking the source or the destination ?
    – Mathieu
    Aug 14, 2020 at 21:34

The simple way to exclude a directory from a copy is to move the directory somewhere else first. You can move it back after the copy - it's just two move commands.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .