Linux Basics: Navigate with ls, cd, and pwd

The Linux command line can be a bit intimidating at first, but it gets much easier once you learn a few basic building blocks. The power of the command line lies in combining many basic commands in interesting ways.

Open up a Linux terminal (or, if you want to follow along on Windows, Cygwin). The darkness of the abyss stares at you, but it’s really not as unfriendly as all that.

First things first. Where am I? Type “pwd” without quotes and hit enter:

You should see something like “/home/leonsp”. That’s your home directory, similar to your Documents folder on Windows. “pwd” stands for “print working directory”, and is a handy way to find out your current location.

Let’s try going somewhere else. Enter “cd ..”, followed by “pwd”.

Two dots means one directory up. You just changed the directory to one directory up from /home/leonsp, which is /home.

Let’s get back to your home directory. There’s a few ways to do this. The following commands will all do the same thing:

~ is convenient shorthand that refers to the home directory of the current user — you.

What’s in all these directories? Let’s list the contents using the “ls” command:

Not much will show up, as your home directory starts out with few files in it. It will, however, have a bunch of hidden files. Let’s list all of these:

By convention, Linux treats all filenames starting with a dot as hidden. They will only show in the listing when you ask to see them.

.bash_history, .bash_profile, and .bashrc are configuration files for my shell, Bash. Which shell you have mostly affects scripting (or automation), which is a more advanced topic. Bash, ksh, and sh are similar, while csh and tcsh are a bit different.

. and .. will show up everywhere. Single dot “.” refers to the current directory, and two dots “..” refer to the parent directory.

It’s possible to get a long, more detailed listing:

We’ll get into what these columns mean later.

Published by

Leons Petrazickis

I'm a full-stack developer at IBM Analytics Emerging Technologies. I do Ruby, JS, Python, Hadoop, Spark, as well as web scale devops with Chef and Docker. My opinions are my own.

One thought on “Linux Basics: Navigate with ls, cd, and pwd”

Comments are closed.