Tag Archives: Linux

Visualizing Directory Structures with the Tree Command

Sometimes good old ls just doesn’t cut it when you’re browsing directories from the command line. Sometimes you just need a more visual overview of the nested files and directories. Well, it turns out there’s a useful command for those cases, and it’s available for Linux, OS X, FreeBSD and just about any OS you can think of. (Except Windows, of course.) It’s called tree.

To install it on OS X, with Homebrew:

brew install tree

On Ubuntu/Debian, or other Linux distros that use Debian packages:

apt-get install tree

To use it, just navigate to a directory and type tree. It has various options (visible with tree --help), so you can limit how many levels down it will go, exclude items that match a pattern, adjust sorting, etc.. You get a spiffy diagram that looks something like this:

├── application.rb
├── boot.rb
├── database.yml
├── environment.rb
├── environments
│   ├── development.rb
│   ├── production.rb
│   └── test.rb
├── initializers
│   ├── backtrace_silencers.rb
│   ├── filter_parameter_logging.rb
│   ├── inflections.rb
│   ├── mime_types.rb
│   ├── secret_token.rb
│   ├── session_store.rb
│   └── wrap_parameters.rb
├── locales
│   └── en.yml
└── routes.rb

Is that cool or what? This should be quite useful for writing tutorials, since a plain-text directory tree is more accessible than a screenshot of a file manager window.

Installing Multiple Ghost Blogs Behind NGINX on Ubuntu 12.04

Ghost LogoLooking to set up a blog with Ghost? While it still has a few rough edges and missing features at the time of this writing, as it’s essentially in beta at this point (hence the “0.3” versioning), it definitely shows promise as a blogging platform.

If you’re reading this, you’re probably aware that you can’t just FTP Ghost to a dinky shared host and expect it to run like your average PHP script. Ghost is a Node.js application, which works differently, and has yet to be adopted by services that generally cater to newbies. You’re going to need a VPS and command line access. I’m also going to assume a rudimentary knowledge of Linux commands. (You can pick up the basics pretty easily at linuxcommand.org if need be.)

This tutorial aims to walk you through the process of installing one ore more instances of Ghost behind the NGINX server. NGINX is a fast and lightweight web server that, when configured in this manner, acts as a proxy, forwarding requests to the correct Ghost blog.


I’m a big fan of DigitalOcean. I’ve been hosting my various web sites with them since this June, and their service has been of excellent quality. In addition to their rock-bottom price, their virtual machines have performed well and their staff has been competent and helpful. (You can find my review of DigitalOcean here.)

$5/month will get you a “Droplet” with 512MB of RAM, 20GB of storage on a solid state drive and plenty of data transfer. (It’s a soft cap with reasonable overages. You’re very, very unlikely to ever reach it, though. Unless you’re a popular podcaster or something, in which case you should be looking into a CDN…)

The figure that’s the most important is the RAM. Just like with the computer you’re using to read this, active applications reside in the system’s memory, and the amount they use varies depending on what the app is doing. Ghost, in my informal tests, doesn’t seem to be too memory-intense. So a 512MB Droplet could probably host a few Ghost blogs at once, depending on their popularity and how the system is configured.

There are plenty of options for a VPS, though. If you’re not too keen on DigitalOcean, Linode, Rackspace, Amazon EC2 and RamNode are popular. If you want to give DigitalOcean a try, you can sign up with the promo code DIVEIN5 to get a $5 credit. You can also pay by the hour if you just want to fire up a VM for a few hours to experiment before making a decision.

Initial Setup

Once you’ve got your VPS, it’s time to start setting things up. For simplicity, I will assume you are running Ubuntu 12.04. You can follow along with any Linux distribution on any hosting provider, but some commands may be a little different.

First, if you haven’t already, use SSH to log in to your VM as root, using the password your host gave you. Take this opportunity to change your password to something different, and reasonably strong, for security. Just run the passwd command and follow the on-screen instructions.

Now let the system update its package index by running the following command:

apt-get update

While you’re at it, install the unzip tool so you can unpack the Ghost archive later on.

apt-get install unzip

Continue reading →

4 Useful cURL Tricks

cURL is pretty much the universal go-to tool for testing HTTP responses from the command line. If you’re not already familiar with it, here are a few handy things you can use it for.

Checking Headers

You can use cURL to see the headers sent in a request. I use this all the time to see if the headers I’m trying to send in a script are working right.

$ curl -I http://www.google.com
HTTP/1.1 200 OK
Date: Thu, 06 Dec 2012 02:45:58 GMT
Expires: -1
Cache-Control: private, max-age=0
Content-Type: text/html; charset=ISO-8859-1

Sending POST Requests

I was working on a project recently that involved receiving POST requests from a client script running on another server. Since there was no convenient HTML form to use to repeatedly test changes made to the API, I ended up using cURL. Sending POST data is a simple matter of passing an argument that looks something like a query string.

curl http://example.org/url-to-recieve-post-request -d "name=Gandalf&type=wizard";

Continue reading →

What are Some Good Places to Find Linux Server Tutorials?

Are you planning on moving from shared hosting to a more robust hosting platform, such as a VPS? It’s easy enough to find a provider, such as VPS.net, Linode or Slicehost. But that’s just the beginning. You have to learn how to set up and maintain your new server.

Here are a few resources to help you figure things out:

  • HowtoForge — All sorts of Linux tutorials. They have guides to setting up server configurations on the various Linux flavors, as well as basic  introductions to Linux.
  • Slicehost Article Repository — Even if you aren’t a Slicehost customer, you will find some invaluable guides and tutorials here.
  • Linode Library — Much like Slicehost, Linode maintains a collection of useful tutorials.
  • Official Ubuntu Documentation — Select your version of Ubuntu and look for the “Server Guide” link.
  • Google! — Search engines are your friend. If you don’t know what something means or you want to learn how to do something, search for a tutorial. The chances are good that someone else has already written something on the subject.

If you really get stuck, try leaving your question on your host’s forum or on Server Fault.

No Support Linux Hosting

We ignore the support questions and pass the savings on to you. Not lazy. Efficient.

That’s the slogan for No Support Linux Hosting, a company providing ridiculously cheap web hosting. You pay $1 per month for shared hosting with 1GB of disk space, a 10GB transfer caps, 3 MySQL databases, cPanel and 25 email accounts. Just one dollar.

It seems like a great deal for small websites or, as they suggest, someone looking to resell to clients. You pay $1 monthly to host a client’s website, charge them a few dollars, and handle the support yourself.

The billing system is interesting as well. You pre-pay a certain number of credits through PayPal, and No Support Linux Hosting dips into your pool of credits as necessary. The initial registration is free, as you don’t need to pay for anything until you actually start using the service.

$12/year for hosting is a pretty good deal. Couple it with $8.99 or so for a domain from your registrar of choice, and you can launch a website on a very tight budget.

Automatic Amazon S3 Backups on Ubuntu/Debian

If you manage your own web server, as you do with a VPS, one thing you need to look into is a backup strategy. It wouldn’t be pleasant for your files to vanish into the ether in the event of some sort of catastrophic server meltdown, would it? Optimally you want to, on a daily basis, offload a copy of everything important to a separate geographical location. One excellent way to do that is to follow Pro Blog Design’s new tutorial on how to automatically back up your files and databases to Amazon S3.

S3, or Simple Storage Service, is Amazon’s cheap cloud data storage system. Michael Martin, the author of the tutorial, says that his bill from last month was $2.60. ($0.15 per month per GB for stored, $0.15 per GB transferred.) Using a backup script on your server, you can automatically archive and encrypt your files and MySQL dumps, then send them off to Amazon’s servers for safekeeping.

I should start by saying that while s3 is not a free service, it’s incredibly inexpensive! My bill for the last month was $2.60, and that was with backing up a lot more than just this site! It’s the cheapest peace-of-mind ever.

Automatic Amazon S3 Backups on Ubuntu/Debian [Pro Blog Design]

Get Live Access Logs With a Simple Linux Command

Here’s a neat little trick for those of you with SSH access to your Linux server. You can use a simple command to get a live-updated stream of your access log, so you can see hits as they come in. It’s sort of like the “spy” tool in Woopra or pMetrics, but geekier and with less visual polish. :)

Linux "tail -f" on an Apache Access Log

First you need to connect to the server with SSH. Once you’re in, change your working directory to wherever Apache stashes its log files on your system. On my Ubuntu install it’s /var/log/apache2. So I would type cd /var/log/apache2 to switch to that directory. Next, run the tail command like so:

tail -f access.log

Tail normally outputs the last several lines of a file and then returns to a prompt, but with the -f argument it continues to monitor the file for changes, and outputs them. So as the Apache server writes to the log file, tail spits the new lines out on your screen.

When you’re done, press Ctrl+C to terminate the tail process and go back to the shell prompt.

How to Set Up a Linux Server

Since I’ve been planning on moving to a VPS server sometime in the coming months, I’ve been reading up on server administration. How to set up Linux to serve web pages and parse PHP, how to not leave the door wide open to attackers, how to manage Apache, all that jazz. It’s all rather complicated at a glance, though luckily not too much so once you get into it. I’m doing my best to prepare myself so I’m not overwhelmed when the time comes to switch servers.

The folks over at NETTUTS must be psychic or something. They seemed to know that I was semi-actively looknig for information on this topic, since they recently published a tutorial on setting up an Ubuntu webserver. I had a “well that’s cool” moment when I saw it in my feed reader.

Continue reading →