The bash history can do many helpful things, and the search with Show
You can re-do the previous command with
you don't have to retype all of that again. Instead just call
If you want to re-execute
the command at a specific position from your history, you can also use
to re-execute the command at position 3. Be aware that this counts from the top. So if you're storing 500 commands in your history,
would re-execute the second last command. You can also re-execute the last command that started with a string like
which would re-do the last line that started with "apt-". If you want the last command where the string appeared anywhere in the line, you can use something like
There are more interesting things the bash history can do. Just to give an impression of the wide range of possibilities, you can specifically access a parameter of a command from history. So
would print the third parameter to the fifth from last command. EDIT: Regarding Rudie's comment below, with the standard settings this bash
history expansions are indeed executed directly. It's probably best described like this: A call like If you don't want that, you can set the shell option Bash is the default command-line shell on most Linux distributions, from Ubuntu and Debian to Red Hat and Fedora. Bash is also the default shell included with macOS, and you can install a Linux-based bash environment on Windows 10. The bash shell features a wide variety of keyboard shortcuts you can use. These will work in bash on any operating system. Some of them may not work if you’re accessing bash remotely through an SSH or telnet session, depending on how you have your keys mapped. RELATED: 10 Basic Linux Commands for Beginners Working With ProcessesUse the following shortcuts to manage running processes.
RELATED: How Linux Signals Work: SIGINT, SIGTERM, and SIGKILL Controlling the ScreenThe following shortcuts allow you to control what appears on the screen.
Moving the CursorUse the following shortcuts to quickly move the cursor around the current line while typing a command.
Deleting TextUse the following shortcuts to quickly delete characters:
Fixing TyposThese shortcuts allow you to fix typos and undo your key presses.
Cutting and PastingBash includes some basic cut-and-paste features.
Capitalizing CharactersThe bash shell can quickly convert characters to upper or lower case:
Tab CompletionRELATED: Use Tab Completion to Type Commands Faster on Any Operating System Tab completion is a very useful bash feature. While typing a file, directory, or command name, press Tab and bash will automatically complete what you’re typing, if possible. If not, bash will show you various possible matches and you can continue typing and pressing Tab to finish typing.
For example, if you have a file named really_long_file_name in /home/chris/ and it’s the only file name starting with “r” in that directory, you can type /home/chris/r, press Tab, and bash will automatically fill in /home/chris/really_long_file_name for you. If you have multiple files or directories starting with “r”, bash will inform you of your possibilities. You can start typing one of them and press “Tab” to continue. Working With Your Command HistoryRELATED: How to Use Your Bash History in the Linux or macOS Terminal You can quickly scroll through your recent commands, which are stored in your user account’s bash history file:
Bash also has a special “recall” mode you can use to search for commands you’ve previously run:
emacs vs. vi Keyboard ShortcutsThe above instructions assume you’re using the default
keyboard shortcut configuration in bash. By default, bash uses The following command will put bash into set -o vi The following command will put bash back into the default set -o emacs With a few of these in your toolbelt, you’ll be a Terminal master in no time. READ NEXT
How-To Geek is where you turn when you want experts to explain technology. Since we launched in 2006, our articles have been read more than 1 billion times. Want to know more? Which bash shortcut or command is used rePressing Esc+. Which Bash shortcut or command is used to re-execute a recent command by matching the command name? e. Pressing Esc+.
Which bash shortcut or command is used to re1) Ctrl + P
This is the most dependable shortcut in Linux to execute the last run command in the terminal.
Which command is used to execute the previous command in Linux?Using CTRL + P and CTRL + R
You can use a combination of 'CTRL + P' and 'CTRL + R' to output the last command that you used on the terminal. And then, if you press the <Enter> button after this combination, you will also be able to run that command as well.
How to list history of commands in Linux?Using a Reverse Search of Linux Command History
To enter this mode you simply press ctrl and r. You can then enter a search term and use repeat presses of ctrl and r to step back through the list of previous commands containing that term.
|