Command Completion and History Editing


Now that you have seen some of the basic commands available at the command line, let's examine a few of the advanced features of the more modern shells.

If you're not sure whether bash (or any program) is installed on the system, you can easily figure it out by taking advantage of the built-in command-completion features of tcsh, bash, and other feature-rich shells. Type enough of the command name for it to be uniquethe first two or three letters, just to see how this worksand then press Tab. If you've entered enough of the program name for it to be uniquely determinable, the rest of the command will complete itself.

If you haven't specified enough of the program name for the shell to figure out what you want, you will get a "bell" signal (which will beep at you or give you another kind of alert, depending on your terminal program). You can then get a listing of all possible completions to the command, either by pressing Tab again (in bash) or by using Ctrl+D (in tcsh):

# bas [Tab] basename   bash     bashbug


Caution

Ctrl+D is also the keystroke for deleting the character to the right of the cursor as well as for logging out of a tcsh session (if entered on a blank line). So be careful!


Tab-completion also works on filenames:

# ls show [Tab] showchars.cgi*    showfavepics.cgi* showprofile.cgi*  showuploads.cgi* showcomments.cgi* showpopular.cgi*  showrequests.cgi*


History editing is also a fundamental feature of the advanced shells. As you enter commands, each one is held in a buffer for the duration of your current login session, up to a limit set in your shell configuration file (100 by default in tcsh). You can scroll up and down through the commands you've entered with the up and down arrow keys; then you can either press Enter to re-execute whatever command you've selected or edit the command with the other arrow keys to correct mistakes or alter the desired result.

Each command is also entered into a history file in your home directory: .history for tcsh and .bash_history for bash. This allows your command history to span even beyond your current login session, back into previous ones; however, although the history file is readable only by its owner, you might consider it a security risk. After all, do you really want to have a file sitting around with a record of all the commands you've entered? If that's the case, the history file can safely be deleted without any detrimental effects other than commands from previous login sessions not being available in scrollback. You can delete your history file by entering rm ~/.history or rm ~/.bash_history, depending on the shell you're using. You can even have this occur automatically by adding the appropriate rm command to your .logout or .bash_logout file, as described in Chapter 9.




FreeBSD 6 Unleashed
FreeBSD 6 Unleashed
ISBN: 0672328755
EAN: 2147483647
Year: 2006
Pages: 355
Authors: Brian Tiemann

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net