Tab filename completion

From LQWiki
Jump to navigation Jump to search

When you use the bash shell on Linux it will complete commands and file names for you if you type the 'TAB' key. The default behaviour is:

  1. You type in the start of the command or filename.
  2. You hit TAB.
  3. The shell will fill in as much as it can and beep.
  4. Hit TAB again and it shows you all possible matches.

Example:

  • You want to start firefox and type only firef and then the 'TAB' key.
  • You want to know which commands starting with 'f' exist, so you type 'f' and then the 'TAB' key twice.

Configuration

The default behavior be changed to:

  1. You type in the start of the command or filename.
  2. You hit TAB.
  3. The shell will fill in as much as it can and shows you all possible matches.

All that needs to be done is:

  1. Edit /etc/inputrc
  2. Add the line:
set show-all-if-ambiguous on

Problems

Tab filename completion does not work in some scenarios.

Example
You are an ordinary user. You oPen a console and type
sudo cp /root/

and then the 'TAB' key. bash will try to complete the filename, but you as a user are not allowed to see the files in the /root folder. Bash filename completion will not work for this reason.

Example
You want to copy from the network
scp root@192.168.0.1:/tmp/

then the 'TAB' key does not work.