As you saw earlier, previous commands can be reused with the help of the history feature. But the history feature executes commands without any modification. If you want to execute a previous command with some modification, you can use the vi editing features for command editing. If you press the
keystroke combination, the last command appears on your command prompt. If you continue pressing
, you can go back as far as the history supports. To go to the next command, you can press the
key during this process. If you want to edit a particular command, first bring that command on your command prompt using this procedure and then use
to move right and
to move left. As you can see, all of these are vi commands. You can use other vi commands to insert or delete any text on the command line.
Use of vi commands with the command line editing feature is controlled by the EDITOR environment variable. The value of this variable must be set to vi to use vi commands.
Study Break Practicing POSIX Shell Capabilities Login with your name and go to directory /usr/bin . Type the partial command ll la and then press the key twice. You will find that the shell does not complete the command. Now use the keystroke combination and you will see a list similar to that shown here. -
landiag -
last -
lastb -
lastcomm The shell did not complete the command when you pressed the key twice because there are four files that start with the combination la . Now add three more characters to your command, making it ll lastc , and then press twice. This time the shell completes the command. Use the history command to list the last 10 commands in the history. Try to run the fifth-to-last command using the r command. Press the keystroke combination to bring the last executed command to the command prompt and edit it to run the second-to-last command. |