Macos – Mac OS X bash does not always add trailing slash for root directories

bashmacos

I'm using Terminal Version 2.2.3 (303.2).

The problem is when I try to change directory starting from root, I have to double tab for some directories to get trailing slash.

For example, I start to type

cd /etTab

it gives me:

/etc

Then I have to hit tab once more to get needed trailing slash

/etc/

And then, finally, I can Tab all further directories using single tab hit.

How can I fix this? I miss Ubuntu's bash so much.

Best Answer

This is because, on OS X, /etc is a symbolic link:

$ l /etc
lrwxr-xr-x 1 root 11 2012-09-22 09:02 /etc -> private/etc/

that is, /etc is a file, not a directory.

If you try a real directory, like /usr, you'll see the expected behavior:

cd /us TAB

cd /usr/

You can force Bash to treat symlinked directories as directories with this command:

bind 'set mark-symlinked-directories on'

Add it to your .bashrc and source it (that is, read and execute commands from it) like this:

. ~/.bashrc

or reopen Terminal.

Related Question