Too late: The machine, OS and configuration in question is no longer in use, so I can't verify any more suggestions. I have not encountered this problem in Fedora or Arch Linux. If you are having this problem, please post another question with the details of your configuration.

Whenever I want to copy a file from my home directory, I run into this issue: scp won't autocomplete paths preceded by ~ (tilde). This is very simple to verify by typing scp ~/ and pressing Tab twice - No file completions are shown. Even if I specify a unique path prefix such as scp ~/.bash_hist it won't complete. Is this by design, configurable, or a bug?

To clarify, all other parts of the completion work: host names and paths on remote hosts both complete just fine. Completions of paths with tilde also work with other commands, such as ls.

Could there be some restriction on completing a non-standard ~? Mine points to /home/users/username and is an NFS 3 mount to another host (/home/username is used for speed-critical things like the browser profile). I have not changed $HOME (/home/users/username) or some other craziness.

On Fedora 19 it works - Tab completing scp ~/foo results in it replacing the ~ with /home/username and subsequently completing normally.

Please note: This question is neither about autocompleting as root nor autocompleting remotely. Bash completion is installed an working fine.

Running openssh-client 1:5.9p1-5ubuntu1 and GNU bash version 4.2.24(1)-release (x86_64-pc-linux-gnu)

  • 3
    on my system scp ~/ followed by two tabs expands ~/ by $HOME and show me all valid candidates for autocompletion. I use bash version 4.1.5. Probably you have a custom completion enabled for scp so ~ isn't examined by your shell anylonger. Commented Sep 6, 2012 at 12:16
  • Question would be nice for autocompleting on the host :)
    – Bernhard
    Commented Sep 6, 2012 at 12:20
  • @user1146332 Tested on two Ubuntu 12.04 hosts without any custom completion that I know of, and it gets the same result. Which platform/version are you using?
    – l0b0
    Commented Sep 6, 2012 at 16:54
  • i'm working with debian lenny. Commented Sep 6, 2012 at 16:59
  • 1
    @l0b0 oh, I thought he wants to complete the files on remote machine.
    – daisy
    Commented Sep 6, 2012 at 23:58

3 Answers 3


When working under Debian Lenny, do this:

apt-get install bash-completion

Then go for ~/.bash_profile to enable it locally or /etc/profile to add it system-wide. Paste the following in:

if [ -f /etc/bash_completion ]; then
 . /etc/bash_completion
  • I'm not sure about this. Any reference to why it would have to be enabled for all users to work for a single command for a normal user?
    – l0b0
    Commented Nov 13, 2013 at 9:14
  • If it's one user, just go for the .bash_profile. Leave /etc/profile out. More on the profile files here: http://www.linuxfromscratch.org/blfs/view/6.3/postlfs/profile.html
    – mariusz
    Commented Nov 15, 2013 at 7:22

bash auto-completion seems to be the way to go. install the bash-completion package.

And then in /etc/bash_completion.d/ssh there are references to scp command.

  • Bash completion is already installed.
    – l0b0
    Commented Nov 14, 2013 at 16:13

Had the same problem (for what it's worth, on OS X 10.11, stock bash 3.2.57, bash-completion 1.3 via brew). Following this tip I expanded the tilde in the ssh completion file (/usr/local/etc/bash_completion.d/ssh in my case, or /etc/bash_completion.d/ssh otherwise) as follows:

    local IFS=$'\n'

    local dirsonly=false
    if [ "$1" = -d ]; then

    cur="${cur/#\~/$HOME}" # <<< Expand tilde

    if $dirsonly ; then
        COMPREPLY=( "${COMPREPLY[@]}" $( command ls -aF1d $cur* 2>/dev/null | \
            sed -e "s/$_scp_path_esc/\\\\&/g" -e '/[^\/]$/d' -e "s/^/$1/") )
        COMPREPLY=( "${COMPREPLY[@]}" $( command ls -aF1d $cur* 2>/dev/null | \
            sed -e "s/$_scp_path_esc/\\\\&/g" -e 's/[*@|=]$//g' \
            -e 's/[^\/]$/& /g' -e "s/^/$1/") )

    COMPREPLY="${COMPREPLY/#$HOME/~}" # <<< Contract tilde

I also found it nice to contract back the tilde at the end, keeps paths nice and short (as originally typed anyway).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .