I frequently run sequences of administrative commands interactively in Bash. I read the responses before continuing but these chains can take several goes before I'm satisfied. These sorts of chains often involve a single system with multiple sub-commands, or "actions":
sudo apt depends package
sudo apt rdepends package
sudo apt purge package
sudo apt install package
systemctl --user status whatever.service
systemctl --user restart whatever.service
The "action", the thing you're actually doing is buried in the middle of the command. After almost two decades of this, it still takes me four steps to go from one command to the next:
- ↑ to show the previous command
- Ctrl+← until the carat is in the right place
- Alt+Backspace to remove a word
- Type the new "action", and Return.
What I'm asking for might seem lazy, but I've actually run into this a few times this morning on much longer commands, where it's taken a good few seconds to hunt through the line to replace the action. What I want to know is: is this really as good as it gets?
I'm regularly astounded by how much I don't know, so I'd not be too shocked to learn there's a quick-inline-word-replace shortcut that I've never heard of before.
In bash, you can use quick substitution with
^...^...
:The trailing
^
can be omitted. Example:So: