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?

link|improve this question

feedback

5 Answers

up vote 18 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: http://www.cyberciti.biz/tips/moving-home-data-from-old-system-to-new-linux-system.html

The real answer is to use rsync.

link|improve this answer
Nice trick I did not realized this yet. – cstamas Jun 7 '09 at 19:06
3  
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
1  
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
feedback

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

rsync -av src/ user@server:dest/

(And its manual page is worth reading.)

link|improve this answer
1  
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 at 10:27
feedback

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.

link|improve this answer
feedback

Try this:
cd mydir
scp -pr ./ name@host:/path/mydir/

link|improve this answer
feedback

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.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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