Baby Steps in Data Journalism

Starting from zero, this Tumblr provides tools, links and how-to information for people just beginning to explore data journalism.
Posts tagged "Unix"

Computer Hope has a nicely formatted reference for Unix/Linux commands, clear and easy to understand, responds well to searches. 

How to edit your .bash_profile file

When I first opened Terminal on my Mac, the prompt was really long. It contained the full name of my Mac, which for some reason I had allowed to be insanely … not great. So I wanted to change the way my prompt looked.

To do this, I edited my user profile on the system.

That profile is controlled by a user’s .bash_profile file. I found a helpful article titled How to Customize your Terminal Prompt and followed the instructions. The article shows you many options.

You start with this (at the command prompt):

nano .bash_profile

You could use nano to open any other text file (just use the filename and path, if necessary, after the word nano).

Anyway, you press Return and thereby go into a simple text editor. If there’s nothing in your .bash_profile file yet, you’ll see your cursor blinking at the top left corner of a blank area. Above that is a bar that says GNU nano and the version number. At the bottom of the screen are some commands, but you might not realize that WriteOut actually means Save (duh).

DO NOT DELETE anything that is already in your .bash_profile file. Move the cursor down below that stuff, on a new line. This is how I changed my command prompt:

export PS1=”\u \W $ “        [NOTE: This is case sensitive.]

So this is my crib sheet for nano on Mac OS:

Save a file: Control-o        [press Return to accept the filename given*]

Exit the file and program: Control-x

That’s all, just two commands.

*After you save, it asks if you want to save that file. I guess it wants you to make sure you’re editing the file that you intended. Press Return at that point, or your file will not be saved.

Baby Steps in Unix/Linux Part 3: Your Home Directory

What if you get lost after you have changed to different directories too many times?

There’s no place like home — here’s how to click your heels and get back.

Type the following and then press Return (or Enter):


That’s it, just cd by itself. That will take you back you your own home directory on the system. However, if you want to go outside that directory, to the root of the system, type the following and then press Return (or Enter):

cd /

That is cd, and one space, and a slash.

A brief introduction to some useful commands in Unix or Linux. Alphabetical listing. More than you will probably need, but not too much, and you don’t have to click out to read what the command does. No ads (hooray!). From Indiana University.

Baby Steps in Unix/Linux Part 2: Change Directories

One of the common tasks you’ll be doing in Terminal is changing directories. What Unix calls “directories” are the same as what most of us call “folders” on our computers.

Experiment with the cd (“change directory”) command to find out how it works.

Use the ls (“list”) command to see the names of directories that are inside the current one. You will probably see one named Desktop, so let’s peek inside that one. Type the following and then press Return (or Enter):

cd Desktop

Remember that Unix is case sensitive, so pay attention to that uppercase letter “D” in Desktop.

To see what’s inside Desktop (“list” the contents), type the following and then press Return (or Enter):


You should see the names of all the stuff that’s on your Mac Desktop.

To go back “up” to the parent directory (the one you started in, in this case, and which contains the folder named Desktop), type the following and then press Return (or Enter):

cd ..


Finally, what if you want to change to a folder that’s easy to locate in the Finder, but you don’t want to type all the many folder names leading down, down, down to where it is buried? Easy peasy: Just find the folder the normal way, using the Mac Finder — then click it once (don’t open it) and then press Command-c to copy the “path.”

Return to your Terminal window. Type cd and one space, and then paste (Command-v). Press Return, and bingo! You’re in that directory, no matter how deep down it is.

Each of these steps is illustrated in one of the images above (CLICK for a slideshow of larger images).

Baby Steps in Unix/Linux Part 1: Listing

When you’re staring at that bare command prompt in Terminal, of course you don’t know what to do. A command-line interface expects you to type something. But not just anything. It’s not a person, after all. It can’t understand natural language.

So first, try out some useful commands that will show you information about directories (folders) and files that are inside the current directory. Each one is illustrated in one of the images above (CLICK for a slideshow of larger images).

  1. Type ls (for “list”) and press Return (Enter).
  2. Result: The contents of the current directory are listed, in columns.
  3. Type ls -a (“list all”) and press Return (Enter). Result: Now the list includes “hidden” system files, which have names that start with a dot.
  4. Type ls -l (“list long”) and press Return (Enter). Result: Now you see a lot of details about the directory contents, including read/write (rw) permissions.

NOTE: Unix is case sensitive, so pay attention to upper- and lowercase letters.