Get the current directory information

Controlla i miei progressi

/ 1

Change directory and list the subdirectories

Controlla i miei progressi

/ 1

Locate and read the contents of a file

Controlla i miei progressi

/ 1

Navigate to a directory and locate a file

Controlla i miei progressi

/ 1

Questo lab potrebbe incorporare strumenti di AI a supporto del tuo apprendimento.

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.

Prima di iniziare

  1. I lab creano un progetto e risorse Google Cloud per un periodo di tempo prestabilito
  2. I lab hanno un limite di tempo e non possono essere messi in pausa. Se termini il lab, dovrai ricominciare dall'inizio.
  3. In alto a sinistra dello schermo, fai clic su Inizia il lab per iniziare

Utilizza la navigazione privata

  1. Copia il nome utente e la password forniti per il lab
  2. Fai clic su Apri console in modalità privata

Accedi alla console

  1. Accedi utilizzando le tue credenziali del lab. L'utilizzo di altre credenziali potrebbe causare errori oppure l'addebito di costi.
  2. Accetta i termini e salta la pagina di ripristino delle risorse
  3. Non fare clic su Termina lab a meno che tu non abbia terminato il lab o non voglia riavviarlo, perché il tuo lavoro verrà eliminato e il progetto verrà rimosso

Questi contenuti non sono al momento disponibili

Ti invieremo una notifica via email quando sarà disponibile

Bene.

Ti contatteremo via email non appena sarà disponibile

Un lab alla volta

Conferma per terminare tutti i lab esistenti e iniziare questo

Utilizza la navigazione privata per eseguire il lab

Il modo migliore per eseguire questo lab è utilizzare una finestra del browser in incognito o privata. Ciò evita eventuali conflitti tra il tuo account personale e l'account studente, che potrebbero causare addebiti aggiuntivi sul tuo account personale.

Completa questo rapido passaggio per avviare il lab.