I love working in the shell. Mastery of shell lets you get things done in seconds, rather than minutes or hours, if you chose to write a program instead.
But before I do that, I want to take the opportunity and link to a few of my articles that I wrote some time ago on working efficiently in the command line:
- Working efficiently in bash with vi keyboard shortcuts.
- Working efficiently in bash with emacs keyboard shortcuts.
- The definitive guide to bash command line history.
- Fun article on set operations in the shell.
And now the explanation of top one-liners from commandlinefu.
#1. Run the last command as root
$ sudo !!
We all know what the
sudo command does — it runs the command as another user, in this case, it runs the command as superuser because no other user was specified. But what’s really interesting is the bang-bang
!! part of the command. It’s called the event designator. An event designator references a command in shell’s history. In this case the event designator references the previous command. Writing
!! is the same as writing
-1 refers to the last command. You can generalize it, and write
!-n to refer to the n-th previous command. To view all your previous commands, type
I wrote about event designators in much more detail in my article “The Definitive Guide to Bash Command Line History.” The article also comes with a printable cheat sheet for working with the history.