Posts tagged Bash

Bash cheat sheet

Technically, this is a bash cheat sheet; however, many of the commands will work with Bourne shell descendants, such as zsh.

more...

reverse-i-search'ing in the Linux shell

When you press ctrl+r in the shell, you activate a feature called “reverse-i-search.” Reverse-i-search’ing lets you search through your shell history commands, from most recent to oldest.

more...

How to check if Bash is vulnerable to Heartbleed

Run this line in your Bash console:

env x='() { :;}; echo vulnerable' bash -c "only this line should appear"

If you see this, your Bash is vulnerable to Heartbleed:

vulnerable
only this line should appear

If you see this, your Bash is secure from Heartbleed:

only this line should appear

How to dump all MySQL databases to a gzip file from inside a bash script

Often as part of an hourly, daily, or weekly server backup bash script, you will wish to dump all MySQL databases to disk as a gzip file. This way, in the case that any of your databases suffer from corruption or user error, you will have a backup.

Simply put this command inside your cron-scheduled backup bash script, substituting the USERNAME, PASSWORD, and the destination path with your info:

#!/bin/bash
mysqldump -u USERNAME -pPASSWORD --all-databases --routines| gzip > /mysqlbackups/MySQLDB_`date '+%m-%d-%Y'`.sql.gz

Where to put custom bash scripts in OS X

If you make a custom bash script in OS X, and you want everyone on the system to be able to access it, this is the directory where you should save it:

/usr/local/bin