Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 ?

share|improve this question

migrated from stackoverflow.com Jun 2 '11 at 0:36

This question came from our site for professional and enthusiast programmers.

2  
The original motivation is that the subdirectory "/a/c/" is very large (gigabytes), so leaving it out will cut down the copy from minutes to seconds. – russian_spy Sep 28 '11 at 2:51

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

rsync -a --exclude=a/c myserver:/a .
share|improve this answer

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 .
share|improve this answer
    
Also try -rz : -e "ssh -i private.pem" -rz 'users@server:/full/path/'. – mbrownnyc Dec 3 '13 at 14:12

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.

share|improve this answer

You can use extended globbing as in the example below:

#Enable extglob
shopt -s extglob

cp -rv !(./excludeme/*.jpg) /var/destination
share|improve this answer

You must log in to answer this question.

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