More on this book
Kindle Notes & Highlights
To enable programmable completion on an Ubuntu system, source /etc/bash_completion. You can add this command to your personal initialization files or you can enable it globally by uncommenting the the appropriate lines in /etc/bash.bashrc.
V&C Brothers and 1 other person liked this
Your previous working directory is stored in an environment variable named $OLDPWD.
Time and time again I find myself needing to run another command against the last item on the previous command line. To access that item in your current command, use "!$".
For example, to run the last command that started with a "d", type "!d<ENTER>." Specify as much of the string to make it unique. If you have several commands in your recent history that begin with "d", you can add additional characters like "!du" or "!df".
When I need to perform the same action for multiple items, I use a for loop right from the command line.
Luckily it's really easy to repeat the previous command with superuser privileges. If sudo is configured on your system, run sudo !!, otherwise run su - c "!!".
To repeat the previous command while substituting a string run "^string1^string2^". This will repeat the previous command using string2 in place of string1.
By default, only the first occurrence of "string1" is replaced. To replace every occurrence, append ":&".
You can omit the trailing caret symbol, except when using ":&".
The "!#" string represents the current command line. To reuse an item on the same command line follow "!#" with ":N" where N is a number representing a word. Word references are zero based, so the first word, which is almost always a command, is :0, the second word, or first argument to the command, is :1, etc.
Note that if you were to log out and log back in, your aliases would be lost. To make them persist between sessions add them to one of your personal initialization files, sometimes called "dot files," like .bash_profile.