Server Fault is a question and answer site for system and network administrators. 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

I often use SCP to copy files around - particularly web-related files. The problem is that whenever I do this, I can't get my command to copy hidden files (eg, .htaccess).

I typically invoke this:

scp -rp src/ user@server:dest/

This doesn't copy hidden files. I don't want to have to invoke this again (by doing something like scp -rp src/.* ... - and that has strange . and .. implications anyway.

I didn't see anything in the scp man page about an "include hidden files".

How can I accomplish this?

share|improve this question
I assume that src/.* also copies src/.. (the parent directory), right? – Ken Sharp Dec 18 '15 at 13:34
up vote 35 down vote accepted

That should absolutely match hidden files. The / at the end of the source says "every file under this directory". Nevertheless, testing and research bear you out. This is stupid behavior.

The "answer" is to append a dot to the end of the source:

scp -rp src/. user@server:dest/

The real answer is to use rsync.

share|improve this answer
Nice trick I did not realized this yet. – cstamas Jun 7 '09 at 19:06
rsync -avz -e ssh --progress src/ user@server:dest/ – MikeyB Jun 7 '09 at 23:23
silly linux. thank you for the link! – rascher Jun 9 '09 at 1:45
I can't reproduce that behavior. scp -r source/ host:source2 copies dot files. Works in OpenSSH 5.1 from 2007. – Mikel Mar 8 '11 at 20:33

You can try rsync. It's better suited for this job:

rsync -av src/ user@server:dest/

(And its manual page is worth reading.)

share|improve this answer
I always use the --progress option for rsync, I can't live without it =D – Hofa Jun 7 '09 at 21:21
@Hofa I usually use -P because it is shorter, already includes --progress and also includes --partial which can make sense if I am already interested in its progress ;-) – cstamas Mar 31 '12 at 10:27

Don't put a slash after the source directory. Your code would look like this:

scp -rp src user@server:dest/

This will create a directory 'src' under 'dest' on the remote machine, with all the hidden files included. It's probably not exactly what you want, but it will copy hidden files in src.

share|improve this answer

The following will solve the problem, this has been fully tested on our continuous integration environment

scp -rp src/. user@server:dest/
example scp -rp /usr/src/code/. content001@

Hope it helps

share|improve this answer

None of the above scp solutions worked for me. However, I did find that the following worked on cygwin: scp -r directory/* host:directory The '*' matched all visible files and skipped the invisible.

share|improve this answer

If password login is disabled on the remote machine, and the only way to login is via public key, then you can use this:

$ rsync -av -s 'ssh -i /path/to/your/private/SSH/key' --progress /local/destination/directory/

It copies hidden files too.

Also please note that "user1" must have the permissions to read those files, for example you can't copy other user's ssh folders with this method.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.