Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I ran an scp command to download some files from an SSH server. Instead of using the . to put it in the current folder, I accidentally typed *. It looks like scp copied the files and put them somewhere. My command was similar to this:

$moshe> scp username@server.com:~/SomeDirectory/SubDir/* *

I meant to type something more like this:

$moshe> scp username@server.com:~/SomeDirectory/SubDir/* .

Where would they be?

share|improve this question
up vote 4 down vote accepted

Your shell would've expanded the * to all files in the current directory. scp takes multiple source files and a single destination path (the same as cp), so it will have copied username@server.com:~/SomeDirectory/Subdir/* and all the files in the current directory except the last one, to the last one. So, assuming the file list in the current directory hasn't changed, check which directory is listed last:

$ ls | tail -1
share|improve this answer
It's weird because I ran ls immediately after and saw no new files in the directory. – Moshe Feb 28 '12 at 17:16
@Moshe There wouldn't have been, but there should be new files in the directory listed last in the current directory. If the last entry isn't a directory you should've gotten an error – Michael Mrozek Feb 28 '12 at 17:22
It looks like the command did absolutely nothing, and repeating it, with the asterisk corrected downloaded my files. – Moshe Feb 28 '12 at 17:39
@Moshe Why don't execute a simple find command to see of some of those files you copied ended up somewhere? – Bernhard Feb 28 '12 at 18:42

It put them in one subdirectory of your current directory.

For example, if your current directory is something like:

[andcoz@...] ~/test> ls -F
e  f  r  s  v  w  Z/

Note that Z is a directory. When you write:

scp username@server.com:~/SomeDirectory/SubDir/* *

The shell expansion will transform your command in something like:

scp username@server.com:~/SomeDirectory/SubDir/* e  f  r  s  v  w  Z 

So all your files from remote machine and all local directory files will be copied in Z directory.

share|improve this answer
But there were no subdirectories. – Moshe Feb 28 '12 at 17:15

If there were no files¹ in the current directory, then scp successively copied all the remote files to a file called *. In other words, the file ./* now contains the last remote file in alphabetical order. If any of the remote files were directories, scp displayed an error message but went on copying.

If there was a single regular file in the current directory, then scp successively copied all the remote files to that one file.

If there were at least two entries in the current directory, what happened depends on the file type of the last entry in alphabetical order (the last element in the list if you run ls).

  • If it was a regular file, scp aborted with the error “Not a directory”.
  • If it was a directory, scp copied all the remote files and all the files in the current directory except for that last entry into said directory.

I recommend mounting remote directories with sshfs or using rsync -av or rsync -auv (without wildcards) to copy files. scp can be error-prone at times.

¹ Except for files whose name begin with a ..

share|improve this answer

Your Answer


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.