A collection of various bash
tips and tricks collected from various sources. I'm writing this as I learn new stuff, so this is in no way authoritative or even corrent. In fact, you shouldn't read this.
Check your version:
echo $BASH_VERSION
If you're on Mac OS X, and you're using using homebrew
then:
brew install bash
brew update
brew upgrade bash
bash
stores something called a PATH
variable, telling it where to look for programs and scripts. You can see what your path is by typing:
echo $PATH
You'll get a long list that looks something like this:
/usr/local/bin:/bin:/usr/sbin:/sbin:/usr/bin:/usr/local/go/bin
That's each path, for example /usr/sbin
, separated by a colon (:
)
Add this to your ~/.bash_rc
file
# supports history search using up and down arrows
bind '"\e[A": history-search-backward'
bind '"\e[B": history-search-forward'
bind '"\eOA": history-search-backward'
bind '"\eOB": history-search-forward'
set show-all-if-ambiguous on
set completion-ignore-case on
Add this to your .bashrc
file:
# run previous command with sudo
alias fuck='sudo $(history -p \!\!)'
Bash programming is horribly hard, and it's easy to make mistakes. But don't let that put you off -- it's a lovely feeling to write a code snippet that you can directly run in your terminal.
for i in *
> do
> [ -d "$i" ] && zip -r "$i.zip" "$i"
> done