Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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
add comment

4 Answers 4

up vote 23 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.

share|improve this answer
    
Nice trick I did not realized this yet. –  cstamas Jun 7 '09 at 19:06
6  
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
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
add comment

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
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 '12 at 10:27
add comment

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
add comment

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
add comment

Your Answer

 
discard

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.