next up previous contents index
Next: The Standard Input and Up: Time Saving with bash Previous: Command-Line Editing

Command and File Completion


Another feature of bash  is automatic completion of your command lines. For instance, let's look at the following example of a typical cp command:


It's a big pain to have to type every letter of this-is-a-long-file whenever you try to access it. So, create this-is-a-long-file by copying /etc/rc to itgif. Now, we're going to do the above cp command very quickly and with a smaller chance of mistyping.

Instead of typing the whole filename, type cp th and press and release the tex2html_wrap8288 . Like magic, the rest of the filename shows up on the command line, and you can type in shorter. Unfortunately, bash  cannot read your thoughts, and you'll have to type all of shorter.

When you type tex2html_wrap8288 , bash looks at what you've typed and looks for a file that starts like that. For instance, if I type /usr/bin/ema and then hit tex2html_wrap8288 , bash will find /usr/bin/emacs since that's the only file that begins /usr/bin/ema on my system. However, if I type /usr/bin/ld and hit tex2html_wrap8288 , bash beeps at me. That's because three files, /usr/bin/ld, /usr/bin/ldd, and /usr/bin/ld86 start /usr/bin/ld on my system.

If you try a completion and bash beeps, you can immediately hit tex2html_wrap8288 again to get a list of all the files your start matches so far. That way, if you aren't sure of the exact spelling of your file, you can start it and scan a much smaller list of files.


Converted on:
Mon Apr 1 08:59:56 EST 1996