Get the current directory information

检查我的进度

/ 1

Change directory and list the subdirectories

检查我的进度

/ 1

Locate and read the contents of a file

检查我的进度

/ 1

Navigate to a directory and locate a file

检查我的进度

/ 1

此实验可能会提供 AI 工具来支持您学习。

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.

准备工作

  1. 实验会创建一个 Google Cloud 项目和一些资源,供您使用限定的一段时间
  2. 实验有时间限制,并且没有暂停功能。如果您中途结束实验,则必须重新开始。
  3. 在屏幕左上角,点击开始实验即可开始

使用无痕浏览模式

  1. 复制系统为实验提供的用户名密码
  2. 在无痕浏览模式下,点击打开控制台

登录控制台

  1. 使用您的实验凭证登录。使用其他凭证可能会导致错误或产生费用。
  2. 接受条款,并跳过恢复资源页面
  3. 除非您已完成此实验或想要重新开始,否则请勿点击结束实验,因为点击后系统会清除您的工作并移除该项目

此内容目前不可用

一旦可用,我们会通过电子邮件告知您

太好了!

一旦可用,我们会通过电子邮件告知您

一次一个实验

确认结束所有现有实验并开始此实验

使用无痕浏览模式运行实验

使用无痕模式或无痕浏览器窗口是运行此实验的最佳方式。这可以避免您的个人账号与学生账号之间发生冲突,这种冲突可能导致您的个人账号产生额外费用。

完成此快速步骤即可开始实验。