Navigating the Linux File System

This entry is part 2 of 6 in the series Beginner Linux Administrator

Now that we know how the Linux File system is structured, we need to be able to move around or navigate.

Before we can begin navigating we need to be able to list the contents of directories so that we can see where we can go.

The command to list a directories contents.

NAME
ls – list directory contents

SYNOPSIS
ls [OPTION]… [FILE]…

Lets list the contents of the root / (the main linux system folder)

$ ls /
bin   dev  home  lost+found  mnt  proc  sbin     srv  tmp  var
boot  etc  lib   media       opt  root  selinux  sys  usr

Now lets list the contents of the home directory: (your listing will be different)

$ ls /home
admin lost+found

The command for changing directories:

NAME
cd- change working directory

SYNOPSIS
cd [OPTION]… [Directory]…

Lets change our working directory to the root directory “/”:

$ cd /

Our working directory is now the root directory. Did you notice that the command prompt has changed to reflect that our new working directory is root, by placing a “/” at the end of the prompt.

[admin@localhost /]$

Lets try again and this time change our working directory to the log directory or /var/log:

[admin@localhost /]$ cd /var/log
[admin@localhost log]$

Notice how the command prompt has changed to reflect the new working directory by placing “log” at the end of the prompt.

To change to the /var/log directory we gave an absolute path. An absolute path is when you start at the beginning of the file structure and work your way up. We started each directory that we wanted to search with a “/” . By doing this we signified that we wanted to work our way through the file structure starting with the root directory or beginning of the file structure.

You do not have to begin from the root directory when navigating. If we want to change to a directory that is in our current working directory we omit the beginning “/”. This is called a relative path. The “.” signifies the working directory:

[admin@localhost log]$ cd ./mail
[admin@localhost mail]$

Which is the same as if we did an absolute path:

[admin@localhost log]$ cd /var/log/mail
[admin@localhost mail]$

A shortcut to list relative paths is to ommit both the “.” and “/” and just list the directory name:

[admin@localhost log]$ cd mail
[admin@localhost mail]$

How do move back to the parent directory without typing an absolute path ?

We use a shortcut “../” which states to move to the parent directory of the current working directory:

[admin@localhost mail]$ cd ../
[admin@localhost log]$

We can add more then one “../” to move to the parent directory of the parent directory etc…

[admin@localhost log]$ cd ../../
[admin@localhost /]$

Now lets go back to the /var/log/ directory using a relative path:

[admin@localhost /]$ cd var/log

Note that absolute and relative paths also work for the ls command and almost all commands that involve files and directories.
Lets list the var directory contents from the working directory of root or “/”

[admin@localhost /]$ ls var
account  cvs  empty  gdm  local  log   named  opt       racoon  spool  www
cache    db   games  lib  lock   mail  nis    preserve  run     tmp    yp

The command to show current working directory

What if we want to know where we are in the file system structure. There is a command to do that too.

NAME
pwd – print name of current/working directory

SYNOPSIS
pwd [OPTION]

The pwd command will tell us the absolute path to our current working directory:

[admin@localhost log]$ pwd
/var/log

Now that you know how to navigate the Linux File System Structure have some fun and explore. Go back to the article on Linux File System Structure and visit each directory and take a look at whats inside them.

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Blogplay
Fabio Milano has written 79 articles for us. Fabio Milano is a certified RHCE, MCP, and CFOI. He runs an IT consulting and services company called RDS Support inc. Website:http://www.rdssupport.com
The information provided is for educational purposes only. All content including links and comments is provided "as is" with no warranty, expressed or implied. Use is at your own risk and you are solely responsible for what you do with it.

No Comments

Leave a reply