Posts tagged Linux

echo on Linux does not need quotes

The echo command in Linux does not require quotes:

echo Hi there blog readers

…will output the same as:

echo "Hi there blog readers"

The obvious exception is when the string to be printed contains special characters that would confuse echo itself, in which case quotations may be necessary.

How I use ls on Linux

When I run ls, I run it as ls -lAhog:

  • l says to put each file or folder on its own line
  • A says to list all files – hidden files, backups, etc. – but omit the current directory (.) and the parent directory (..)
  • h says to use human readable file sizes – 1.5G instead of 1628688384
  • g says to omit the user
  • o says to omit the group

Occasionally I use the -R parameter, which lists folders and subfolders recursively.

Vagrant cheat sheet

Developing robust software requires an accurate testing and staging environment. Vagrant provides just that. It lets you mimic your production server map on your computer.


Bash cheat sheet

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


tmux cheat sheet

Since switching to vim, I’ve found myself really enjoying keyboard-based user interfaces. So instead of managing multiple terminal sessions in iTerm, I have started using tmux. I’m writing this cheat sheet as I learn. Check back often.


Moving around in Linux with pushd, popd, and dirs

Often when administering a Linux server, you move around between the same few directories. You cd here, you cd there, and then you cd back here. Instead of cd‘ing so much, Linux has 3 powerful commands that can help you: pushd, popd, and dirs.


My ssh config file template

If you ssh into servers, you must set up a .ssh/config file. It will allow you to type ssh myd instead of ssh -i ~/.ssh/mykey.pem -p 1234.


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.


VIM Cheat Sheet

After 9 years of TextMate, I’m switching to vim. I’m writing this cheat sheet as I learn. Check back often.


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:

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:

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

How to start and stop Apache 2 in Ubuntu Linux

How to start Apache 2:

sudo service apache2 start

How to stop Apache 2:

sudo service apache2 stop

How to restart Apache 2:

sudo service apache2 restart

How to reload Apache 2:

sudo service apache2 reload

Reloading is useful if you change a virtualhost file, since it will not actually stop Apache. Therefore, your websites will not go offline (even for a few seconds).

How to change a line into a shape in Illustrator

In Illustrator, there are line objects and shape objects. Lines are made of points, and shapes are made of boundaries. Since line objects are not easily resized or manipulated, you will want to convert your line into a shape.


How to change ownership recurisively in Linux

Run this command, replacing USER and GROUP with the user and group to which you would like the files changed; substitute DIRECTORY for the folder whose ownership you would like to change:


How to download Wordpress in Linux

Every time you set up a new Wordpress site in Linux, you will need to download a fresh copy of Wordpress. Here’s the fastest way:

tar -xzvf latest.tar.gz

How to dump a MySQL database

There are many cases where you will want to dump a MySQL database. Examples include: backing up a website, migrating a website to a new server, moving from a development machine to a production server, and more.

Simply run this command, substituting the USERNAME, DATABASE_NAME, and FILENAME with your info. When you run this command, it will prompt you for the MySQL password for the USERNAME you provided:


How to open the MySQL console

The MySQL console allows you to directly execute SQL commands, without having to use a programming language adapter such as PHP, Ruby, or Python.

Run this command, replacing USERNAME with your MySQL username; you will be prompted for the password.

mysql -u USERNAME -p -h localhost

How to set up a new virtualhost domain in Apache 2

This guide will show you how to quickly set up a new website in Apache 2 using virtualhosts. Follow these instructions exactly as written, down to the character: trailing slashes, case, line breaks, etc.

Start by firing up a terminal, and creating a folder for the new website:

mkdir /var/www/

How to unzip a file on the Linux commandline

In order for this to work, the unzip command must be installed. If you do not have unzip on your system, install it using the package manager for your distro (apt-get, etc.).

unzip ./

My minimal Apache2 virtualhost file

I have written at length about how administering a Linux server is a nightmare. It does not matter how smart, experienced, or nerdy you are. Everyone who uses Linux bangs their head against a wall from time to time.