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?

  • I assume that src/.* also copies src/.. (the parent directory), right? – Ken Sharp Dec 18 '15 at 13:34

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.

  • Nice trick I did not realized this yet. – cstamas Jun 7 '09 at 19:06
  • 20
    rsync -avz -e ssh --progress src/ user@server:dest/ – MikeyB Jun 7 '09 at 23:23
  • 2
    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
  • 1
    Note that adding a . at the end no longer works (2019) due to security issues. This is explained here: superuser.com/questions/1403473/scp-error-unexpected-filename – Stéphane Feb 12 at 21:44

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

rsync -av src/ user@server:dest/

(And its manual page is worth reading.)

  • 2
    I always use the --progress option for rsync, I can't live without it =D – Hofa Jun 7 '09 at 21:21
  • 1
    @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.


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

  • After updating scp recently, this now results in scp: error: unexpected filename: . . Make sure to test whether it works with your distribution, fellow Googler :) – Mo Friedrich Feb 11 at 11:39

To copy only hidden files, Use this command

scp -rp /path_to_copy_hidden/.[!.]* user@host:/path_to_paste/

Actual game is the /.[!.]* tag that is referring to files starting with .(hidden)


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.


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 user1@remote.host:/remote/source/directory/ /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.


As scp supports regular expressions, this will nicely do the trick for you:

scp -rp src/(*|.*) user@server:dest/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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