Get the current directory information

Check my progress

/ 1

Change directory and list the subdirectories

Check my progress

/ 1

Locate and read the contents of a file

Check my progress

/ 1

Navigate to a directory and locate a file

Check my progress

/ 1

This lab may incorporate AI tools to support your learning.

Activity overview

Previously, you learned about Linux and how to communicate with the OS through the shell. You also learned how to use some of the core commands to navigate the Linux file system and read content from files it contains.

These are essential skills. For example, when investigating unauthorized access, you might navigate to and then read a user access report.

In this lab activity, you’ll navigate a Linux file structure, locate files, and read the contents of files. You’ll also need to answer a few multiple-choice questions based on the information contained in these files.

As a security analyst, it’s key that you know how to navigate, manage, and analyze files remotely via a Linux shell without a graphical user interface.

Scenario

In this scenario, you have to locate and analyze the information of certain files located in the /home/analyst directory.

Here’s how you’ll do this: First, you’ll get the information of the current working directory you’re in and display the contents of the directory. Second, you’ll navigate to the reports directory and list the subdirectories it contains. Third, you’ll navigate to the users subdirectory and display the contents of the Q1_added_users.txt file. Finally, you’ll navigate to the logs directory and display the first 10 lines of a file it contains.

To complete these tasks, you'll need to use commands that you've previously learned in this course. Well, it's time to practice what you’ve learned. Let’s do this!

Note: The lab starts with your user account, called analyst, already logged in to the Bash shell. This means you can start with the tasks as soon as you click the Start Lab button. Disclaimer: For optimal performance and compatibility, it is recommended to use either Google Chrome or Mozilla Firefox browsers while accessing the labs.

Start your lab

You'll need to start the lab before you can access the materials. To do this, click the green “Start Lab” button at the top of the screen.

Lab Start button displayed.

After you click the Start Lab button, you will see a shell, where you will be performing further steps in the lab. You should have a shell like this:

Linux Terminal displayed.

When you have completed all the tasks, refer to the End your Lab section that follows the tasks for information on how to end your lab.

Task 1. Get the current directory information

In this task, you must use the commands you learned about to check the current working directory and list its contents.

  1. Display your working directory.

The command to complete this step:

pwd

This will show that your current working directory is your home directory.

/home/analyst
  1. Display the names of the files and directories in the current working directory.

The command to complete this step:

ls

The output should be:

logs projects reports temp

Answer: The lab starts with /home/analyst as your current working directory.

Answer: The lab starts with four subdirectories in the /home/analystdirectory, namely logs, notes, temp, and reports.

Click Check my progress to verify that you have completed this task correctly.

Get the current directory information Note: There is no penalty for clicking Check my progress and you’ll be shown a hint.

Task 2. Change directory and list the subdirectories

In this task, you must navigate to a new directory and determine the subdirectories it contains.

  1. Navigate to the /home/analyst/reports directory.

The command to complete this step using a relative path:

cd reports Note: The cd command accepts absolute and relative paths. An absolute path includes all the directories from the root of the file system and starts with a /. An alternative is a relative path, which is expressed starting from the current directory and starts without the initial /. The above command uses a relative path.

The command to complete this step using an absolute path:

cd /home/analyst/reports
  1. Display the files and subdirectories in the /home/analyst/reports directory.

The command to complete this step:

ls

The output should be:

users

Answer: The subdirectory contained in the /home/analyst/reports directory is called users.

Click Check my progress to verify that you have completed this task correctly.

Change directory and list the subdirectories

Task 3. Locate and read the contents of a file

In this task, you must navigate to a subdirectory and read the contents of a file it contains.

  1. Navigate to the /home/analyst/reports/users directory.

The command to complete this step:

cd /home/analyst/reports/users

The above command uses an absolute path. You could also use a relative path as follows:

cd users
  1. List the files in the current directory.

The command to complete this step:

ls
  1. Display the contents of the Q1_added_users.txt file.

The command to complete this step:

cat Q1_added_users.txt Note: The cat command prints the contents of a file to the shell. You can specify the file to display using absolute or relative paths.

The same command using an absolute path:

cat /home/analyst/reports/users/Q1_added_users.txt

Answer: The employee with username aezra works in the Human Resources department.

Answer: The employee_id of the employee with username mreed in the Information Technology department is 1104.

Click Check my progress to verify that you have completed this task correctly.

Locate and read the contents of a file

Task 4. Navigate to a directory and locate a file

In this task, you must navigate to a new directory, locate a file, and examine the contents of the file.

  1. Navigate to the /home/analyst/logs directory.

The command to complete this step:

cd /home/analyst/logs
  1. Display the name of the file it contains.

The command to complete this step:

ls

This command will display the following output:

server_logs.txt
  1. Display the first 10 lines of this file.

The command to complete this step:

head server_logs.txt Note: The head command displays just the beginning of a file, by default ten lines. You can specify how many lines to display using the -n argument, which specifies the number of lines to display.

Answer: There are three warning messages in the first 10 lines of the server_logs.txt file.

Click Check my progress to verify that you have completed this task correctly.

Navigate to a directory and locate a file

Conclusion

Great work!

You now have practical experience in using basic Linux Bash shell commands to

  • navigate directory structures with the cd command,
  • display the current working directory with the pwd command,
  • list the contents of a directory with the ls command, and
  • display the contents of files with the cat and head commands.

Navigating through directories and reading file contents are fundamental skills that you’ll often use when communicating through the shell.

End your lab

Before you end the lab, make sure you’re satisfied that you’ve completed all the tasks, and follow these steps:

  1. Click End Lab. A pop-up box will appear. Click Submit to confirm that you're done. Ending the lab will remove your access to the Bash shell. You won’t be able to access the work you've completed in it again.
  2. Another pop-up box will ask you to rate the lab and provide feedback comments. You can complete this if you choose to.
  3. Close the browser tab containing the lab to return to your course.
  4. Refresh the browser tab for the course to mark the lab as complete.

Before you begin

  1. Labs create a Google Cloud project and resources for a fixed time
  2. Labs have a time limit and no pause feature. If you end the lab, you'll have to restart from the beginning.
  3. On the top left of your screen, click Start lab to begin

Use private browsing

  1. Copy the provided Username and Password for the lab
  2. Click Open console in private mode

Sign in to the Console

  1. Sign in using your lab credentials. Using other credentials might cause errors or incur charges.
  2. Accept the terms, and skip the recovery resource page
  3. Don't click End lab unless you've finished the lab or want to restart it, as it will clear your work and remove the project

This content is not currently available

We will notify you via email when it becomes available

Great!

We will contact you via email if it becomes available

One lab at a time

Confirm to end all existing labs and start this one

Use private browsing to run the lab

Using an Incognito or private browser window is the best way to run this lab. This prevents any conflicts between your personal account and the Student account, which may cause extra charges incurred to your personal account.

Complete this quick step to start your lab.