Recently Windows 10 added a bash shell as part of their Linux Subsystems for Windows initiative. This is generally fantastic, but I've run into an interesting problem: Windows filesystems do not allow colons/other special characters in their file names. Therefore, when I try to scp something like this:

scp user@remote:/path/to/file-2016-09-07_08:45:45.txt .

scp throws an invalid argument error. One way around this is to specify a new file name without special characters, but this is cumbersome when trying to do something like

scp user@remote:/path/to/file-2016-09-07* .

because all of the files throw the invalid argument error. Is there some code I could place in my .bashrc file that would take any scp argument and replace each offending character with _, for example? The equivalent to

 scp user@remote:/path/to/file-2016-09-07_08:45:45 file-2016-09-07_08_45_45.txt

but portable for use with *?

2 Answers 2


You could do a parameter substitution on the name — if you had it in a variable. But the shell does not "see" the wildcard expansion on the remote filesystem which scp may "see", so a shell alias would not work.

From the description, you could write a script which does what you are asking for, e.g.,

  • use ssh to obtain a list of the remote filenames, and
  • in a loop...
  • form a local filename, and
  • use scp to copy the actual remote/local files.

You might also consider using alternative Unicode characters in your original file names, allowing copies without any naming problems.

  • Can you explain how the OP could use this information to rewrite the target filenames? Jan 31, 2022 at 1:01
  • 1
    @roaima, what I'm suggesting means never having to rewrite the target filenames. In the original source, use the Unicode visually equivalent character right from the very beginning. Then the filenames will always automatically work everywhere without one's having to worry about what the rules are. Jan 31, 2022 at 1:33

You must log in to answer this question.