How to Navigate the Unix File System with Basic Commands

When you start using Unix, one of the first things you’ll need to learn is how to navigate its file system. Think of it like learning your way around a new neighborhood. In this post, we’ll break it down step by step, using simple language to guide you.


What Is the Unix File System?

The Unix file system is like a tree turned upside down:

  • The very top is called the root directory, represented by a single /.
  • From the root, folders (called directories in Unix) branch out like tree limbs.
  • Each directory can hold files and even more directories.

Here’s a simple example:

/
├── home
│ ├── user1
│ └── user2
├── var
│ └── log
└── etc

Basic Commands to Get Around

Here are the most important commands to navigate the Unix file system. Don’t worry, they’re easy to learn!


1. See Where You Are: pwd

The pwd command stands for Print Working Directory. It tells you the exact location of where you are in the file system.

Example:

$ pwd
/home/user1

Here, you’re in the user1 folder inside the home directory.


2. List What’s Around You: ls

The ls command shows what’s inside your current directory (like opening a folder to see its contents).

Examples:

  • To list files and folders:
$ ls 
Documents Downloads Pictures
  • To see more details (like file size and date):
$ ls -l 
drwxr-xr-x 2 user user 4096 Nov 14 09:00 Documents 
-rw-r--r-- 1 user user 1200 Nov 14 08:30 notes.txt
  • To include hidden files (those starting with a dot .):
$ ls -a. .. .bashrc Documents Downloads

3. Move Between Folders: cd

The cd command stands for Change Directory. Use it to move around the file system.

Examples:

  • Go into a specific directory:
$ cd Documents
  • Move back up one level:
$ cd ..(This moves you to the parent folder.)
  • Go straight to your home directory:
$ cd ~
  • Jump directly to a folder:
$ cd /var/log

4. Optional: See a Directory Tree with tree

If you want a clearer picture of how files are organized, you can use the tree command. It shows a visual map of directories and files. You might need to install it first by running:

$ sudo apt install tree   # For Debian-based systems like Ubuntu

Example:

$ tree
.
├── Documents
│ └── report.txt
├── Downloads
└── Pictures

Tips to Make Life Easier

  1. Tab Auto-Complete
    Start typing a file or folder name, then press Tab to auto-complete it. For example:
$ cd Doc<Tab> 

This will expand to Documents if it exists.

  1. Combine Commands
    You can do multiple things in one line. For example:
$ cd /var/log && ls 

This moves to the /var/log directory and lists its contents in one go.


    Practice Time!

    1. Open your terminal.
    2. Type pwd to check your current location.
    3. Use ls to see what’s inside your directory.
    4. Try moving into a folder using cd, then back out using cd ...

    Leave a Reply

    Your email address will not be published. Required fields are marked *