Practice using `.` and `..` in paths.

QuestionsQuestions8 SkillsProDec, 17 2025
0108

Excellent! Practicing with . and .. is a fundamental skill for navigating Linux efficiently.

Let's do some exercises to get a good feel for them. Your current step is perfect for this as it talks about these very concepts.

First, let's make sure you're in the right starting place:

  1. Check your current location.
    pwd
    You should see /home/labex/project. If not, run cd /home/labex/project to get there.

Now, let's practice:

Exercise 1: Moving up and down

  1. Move up one level using ..

    cd ..

    (This should take you to /home/labex)

  2. Verify your location

    pwd

    (Confirm you are in /home/labex)

  3. Now, move back into the project directory from where you are now, using a relative path.

    cd project

    (This should take you back to /home/labex/project)

  4. Verify your location again

    pwd

    (Confirm you are in /home/labex/project)

Exercise 2: Referencing parent directory content

Let's create a file in your home directory, and then try to view it from your project directory.

  1. Go to your home directory.

    cd ~
  2. Create a file called my_note.txt in your home directory.

    echo "This is a note from my home directory." > my_note.txt
  3. Go back to your project directory.

    cd project
  4. Now, from inside the project directory, try to list the contents of your home directory using .. to refer to it.

    ls ..

    You should see my_note.txt listed there.

  5. Still from the project directory, try to view the content of my_note.txt using .. in the path.

    cat ../my_note.txt

    You should see the text "This is a note from my home directory."

Exercise 3: Referencing the current directory with .

While cd . doesn't do anything (it just moves you to the directory you're already in), . is often used when executing files or as part of a path.

  1. Make sure you are in ~/project.

    pwd

    (Should be /home/labex/project)

  2. Create a simple shell script in your current directory (.):

    echo '#!/bin/bash' > hello.sh
    echo 'echo "Hello from the script!"' >> hello.sh
    chmod +x hello.sh
    • The first two lines create a simple script.
    • chmod +x hello.sh makes the script executable.
  3. Now, run the script using . to indicate the current directory.

    ./hello.sh

    (You should see "Hello from the script!")

This demonstrates that . is useful for indicating "this directory" when the command needs a path.

How did these exercises go for you? Let me know if you encountered any issues or have more questions!

0 Comments

no data
Be the first to share your comment!