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:

$ pwd


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”.

$ cd ..
$ 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:

$ cd /home/leonsp
$ cd ~
$ cd

~ 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:

$ ls

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:

$ ls -a

.  ..  .bash_history  .bash_profile  .bashrc  .inputrc  .lesshst  .ssh  .subversion

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:

$ ls -la

drwxr-xr-x+ 1 leonsp None     0 Feb 22 15:30 .
drwxrwxrwt+ 1 leonsp root     0 Jan 28  2010 ..
-rw-------  1 leonsp None 17431 Apr  5 00:16 .bash_history
-rwxr-xr-x  1 leonsp None  1150 Jan 28  2010 .bash_profile
-rwxr-xr-x  1 leonsp None  3754 Jan 28  2010 .bashrc
-rwxr-xr-x  1 leonsp None  1461 Jan 28  2010 .inputrc
-rw-------  1 leonsp None    35 Jan 10 16:48 .lesshst
drwx------+ 1 leonsp None     0 Mar 30 13:05 .ssh
drwxr-xr-x+ 1 leonsp None     0 Feb 22 15:30 .subversion
-rw-r--r--  1 leonsp None     0 Aug 26  2010 blah

We’ll get into what these columns mean later.

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

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.