I'm using scp to copy files from a remote server to a local one. What's really uncomfortable is that I need to type the file path precisely. I'm used to relying on autocompletion, because file names and folder structures can be long. I want to be able to see the names of files in each directory and autocomplete just like when browsing files locally.

Now, I could do SSH separately, find the file names, and use them in the SCP command. But of course, that would be a huge waste of effort. Also, I could use a GUI, but I prefer to avoid that because a command line is more lightweight.

Any way to use SCP without having to remember file names exactly?

  • 1
    For me, auto completion works if I have set key-based password less login. – muru Feb 13 '15 at 11:48
  • There's also the problem with special characters (though they shouldn't be used). With files containing such characters, zsh seems OK, but bash-completion isn't (see my answer). – vinc17 Feb 13 '15 at 17:42

bash-completion (which is available in Cygwin, Debian, Ubuntu and no doubt many other distributions) supports scp auto-completion, as long as the shell can access the required server with no prompting (it uses ssh in batch mode, see the ssh_config(5) manual page for details).

The easiest way to enable this is to use ssh-agent. This is probably enabled by default by your desktop environment; simply try


to add your default key to the currently-running agent (if any). If no agent is running, you can start one by running

eval $(ssh-agent)

Once your key is known to the agent, you'll be able to auto-complete scp commands involving servers you can access with the key.

I'm pretty sure zsh also supports scp auto-completion with the same caveats; the necessary support is in the zsh-common package in Debian. It needs to be enabled in your .zshrc though with something like

autoload -U compinit && compinit

(which loads all the supported completions).


Zsh has remote scp completion, but you need to make sure that you don't use an alias to some wrapper function like the non-official glob_scp, or if you have one, it is possible to add the same completion mechanism like:

compdef glob_scp=scp

You'll note that zsh will correctly quote special characters such as * when needed (though this may look strange). Currently bash-completion doesn't do that, though failures should be uncommon.

Alternatively, in particular with shells that do not have remote scp completion, you could use sftp or sshfs:

  • sftp has its own completion system.
  • sshfs allows you to mount a remote directory via SSH, so that it suffices to use cp with the usual completion system.
  • @muru Thanks, but this wasn't the reason (I use password-less SSH). The reason was that I was using an alias to the non-official glob_scp function (unfortunately the message in the mailing-list didn't mention the effect on the completion). I've corrected my answer. – vinc17 Feb 13 '15 at 17:07
  • Interesting. +1 and deleting my comment. – muru Feb 13 '15 at 17:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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