How to make scp copy hidden files?
Solution 1
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.
Solution 2
You can try rsync. It's better suited for this job:
rsync -av src/ user@server:dest/
(And its manual page is worth reading.)
Solution 3
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.
Solution 4
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)
Solution 5
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/. [email protected]:/usr/dest/code/
Hope it helps
Related videos on Youtube
rascher
Updated on September 17, 2022Comments
-
rascher almost 2 years
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?
-
Ken Sharp over 8 yearsI assume that
src/.*
also copiessrc/..
(the parent directory), right?
-
-
user649102 about 15 yearsNice trick I did not realized this yet.
-
bakwarte about 15 yearsI always use the --progress option for rsync, I can't live without it =D
-
Steve Townsend about 15 yearsrsync -avz -e ssh --progress src/ user@server:dest/
-
Mikel over 13 yearsI can't reproduce that behavior.
scp -r source/ host:source2
copies dot files. Works in OpenSSH 5.1 from 2007. -
user649102 about 12 years@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 ;-)
-
Moritz Friedrich over 5 yearsAfter updating scp recently, this now results in
scp: error: unexpected filename: .
. Make sure to test whether it works with your distribution, fellow Googler :) -
Stéphane over 5 yearsNote 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 -
Brain90 over 4 yearsUse this if you need different port : rsync -av -e "ssh -p 2222" src/ user@server:dest/