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
.
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.
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
Get Safari's Reading List programmatically with Ruby
I wanted to export my Safari Reading List on OS X, so I wrote some code to do it. I leveraged Ruby, but this methodology could be easily ported to other languages like Bash, Python, or Objective C.
How to make a ruby file executable
In the ruby file:
#!/usr/bin/env ruby
puts 'Hello world'
At the command line:
chmod +x ruby.rb
Then you can execute it like this:
./ruby.rb
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
In OS X, should I use cron or launchd?
Use launchd
. Do not use cron
on OS X.
Source: the launchd
man page.
What does the at sign (@) mean in OS X permissions?
If you run ls
on a file or folder in OS X…
ls -la /dir/to/some_file_or_folder
You may see a permission entry like this:
-rwxr--r--@ 1 john admins 548 Oct 29 15:58 filename.plist
The at sign (@) means that the file has “extended attributes”. Extended attributes are basically some metadata that OS X and OS X apps can tack on to a file.
To view the extended attributes of a file, type:
xattr -l ./filename.ext
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