scp -r ... but leave out (exclude) a specified subdirectory

Here's the directory structure:

/a/
/a/b/
/a/c/

I want to copy everything, EXCEPT for the /a/c/ subdirectory.

scp -rp myserver:/a .      # this will copy everything

Q: How would I specify a directory to leave out in the scp command ?

Answers


I don't think you can, but you could use rsync? Something like this:

rsync -a --exclude=a/c myserver:/a .

I think this might be the correct way of doing it so you are still using SSH, I haven't found a way to do it with scp - but using rsync over ssh might resolve it.

rsync -e 'ssh -ax' -av --exclude /a/c myserver:/a .

If you use the -n switch then it will create a dry run of the process:

 rsync -e 'ssh -ax' -av --exclude /a/c -n myserver:/a .

You can use extended globbing as in the example below:

#Enable extglob
shopt -s extglob

cp -rv !(./excludeme/*.jpg) /var/destination

Not the perfect way to do it, but set the sub-directory you want to exclude as read-only. chmod -R 444 /a/c should do the trick. You'll get a "permission denied" error when it tries to write over that directory.


Need Your Help

Setting id and className dynamically in Backbone.js views

javascript backbone.js

I am in process of learning and using Backbone.js.

How do I get the row count in JDBC?

java jdbc resultset

I've executed a JDBC query to obtain a resultset. Before iterating over it, I'd like to quickly find out how many rows were returned. How can I do this with high performance?