It's well known that !! is a sweet little helper in case where you forgot to sudo a command. However, I find that for those cases I usually use `Up-arrow CTRL-A` to get the previous command and then go to the beginning of the line where I can type `sudo`. Is there any reason to prefer the !! variant?
Bash Shortcuts For Maximum Productivity
31–40 of 58 posts
Re: Bash Shortcuts For Maximum Productivity
#32 # ln -s /usr/local/plan9/bin/rc /bin/bashRe: Bash Shortcuts For Maximum Productivity
#33Bash emacs-like keyboard shortcuts:
http://www.catonmat.net/blog/bash-emacs-editing-mode-cheat-s...
Bash vi-like keyboard shortcuts:
http://www.catonmat.net/blog/bash-vi-editing-mode-cheat-shee...
Definitive bash guide to command line history:
http://www.catonmat.net/blog/the-definitive-guide-to-bash-co...
And they all come with cheat sheets. See downloads box at the bottom of each post for download links.
Re: Bash Shortcuts For Maximum Productivity
#34The things he calls "bang commands" are actually "event designators" (!!, !blah), "word designators" ($) and "word modifiers" (:p). There are links to docs for each at the bottom of this page: http://www.gnu.org/s/bash/manual/html_node/History-Interacti... I use them all the time, and anyone watching over my shoulder always asks what that was. Learn !!, !$, and a few modifiers. You'll be glad you did. Personally, I u…
You post inspired me to quickly create two (hopefully) handy bash functions:
# Create a backup of the given file(s)
# USAGE: bk file1 file2 file3
# -> result: file1.bak file2.bak file3.bak
bk() {
for file in "$@"
do
cp $file{,.bak}
done
}
# Restores the file from backup
# USAGE: rbk file.bak OR rbk file
# -> result: replaces file with file.bak
rbk() {
if [[ $1 == *.bak ]]
then
backup_file=$1
old_file=${backup_file:0:$((${#backup_file}-4))}
else
old_file=$1
backup_file=${old_file}".bak"
fi
read -p "Replace the old backup? (y/N) " -n 2
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
`cp $backup_file $old_file`
fi
}
I've put them in my newly created .functions file (https://github.com/pooriaazimi/dotfiles/blob/master/.functio...).Re: Bash Shortcuts For Maximum Productivity
#35Re: Bash Shortcuts For Maximum Productivity
#36commandline and vim have easily got the most powerful, yet the most rage-inducing key mappings – ever. The worst, and most easily rectifiable aspect is the way command pairs (eg move back/forward a word) require two totally separate commands (esc + b/esc + f) instead of having one command + a generic 'reverse' meta key. In the future I hope someone has the balls to do away with this legacy tripe and popularise some m…
The bash shortcuts are from readline, which (in this case, but by default?) are the same as Emacs. C-f,C-b for moving by character, M-f,M-b for moving by word. C-n,C-p for next and previous line. I think there's a vi switch for readline which would allow you to have vi style shortcuts in bash. This is nice, because it means you have one set of keyboard shortcuts in your editor and shell. Emacs users in OS X get this in any text box (at least any that supports the same defaults as the system, I'm spitting at you MS Outlook/Entourage). I'm sure you could set something up in other windows systems, like GNOME or KDE.
Sure the keyboard shortcuts might be cryptic, but any keyboard shortcuts will be. Don't slag something just because you don't know the history and background behind the choices.
Re: Bash Shortcuts For Maximum Productivity
#37Sometimes I find myself typing out a long command and then deciding that I don't want to run it quite yet. Normally I just hit C-c run some other command first and then copy paste the long command. Surely there is someway to put the long command in history?
Re: Bash Shortcuts For Maximum Productivity
#38Re: Bash Shortcuts For Maximum Productivity
#39Sometimes I find myself typing out a long command and then deciding that I don't want to run it quite yet. Normally I just hit C-c run some other command first and then copy paste the long command. Surely there is someway to put the long command in history?
Comment it out (put a # at the front), unless your shell is set to ignore commented lines.
Re: Bash Shortcuts For Maximum Productivity
#40The things he calls "bang commands" are actually "event designators" (!!, !blah), "word designators" ($) and "word modifiers" (:p). There are links to docs for each at the bottom of this page: http://www.gnu.org/s/bash/manual/html_node/History-Interacti... I use them all the time, and anyone watching over my shoulder always asks what that was. Learn !!, !$, and a few modifiers. You'll be glad you did. Personally, I u…