Linux Format



The command line provides an efficient way to get things done, especially for repeated tasks, but it can demand a lot of typing, especially if you are a fellow alumnus of the two-fingered hunt-and-peck school of typing.

You have almost certainly discovered that you can use the cursor up key to revisit previous commands you’ve entered, which is fine for repeating what you did a few minutes ago, but the shell offers so much more. Bash, along with other shells, maintains a history file of the last 500 or so commands you typed, the exact number is determined by the HISTFILESI­ZE and HISTSIZE environmen­t variables. We generally set these to 1,000, but you don’t want to be hitting the up key hundreds of times to find the exact invocation of a command you used last week, so press Ctrl+R instead.

This starts the history search. Start typing part of a command and it shows the most recent match; as you type more, the match improves. If you want an earlier match, press Ctrl+R again. Once you have found the command you want, you can either press Enter to run it again, or the left or right cursor key to edit it first.

Some shell shortcuts use the history file, too, usually starting with ! . !-n runs the nth from last command again, !! is a shortcut for !-1 and runs the last command. !xyz runs the most recent command matching xyz, so is the same as Ctrl+R xyz Enter but suitable for scripting, too. There are lots more options to make your shell life easier, so check the Bash man page for full details.

Newspapers in English

Newspapers from Australia