3.1.2.7 Lab - Getting Familiar With The Linux Shell
3.1.2.7 Lab - Getting Familiar With The Linux Shell
Introduction
In this lab, you will use the Linux command line to manage files and folders, and perform some basic
administrative tasks.
Recommended Equipment
CyberOps Workstation Virtual Machine
Cisco and/or its affiliates. All rights reserved. Cisco Confidential Page 1 of 13 www.netacad.com
Lab – Getting Familiar with the Linux Shell
Cisco and/or its affiliates. All rights reserved. Cisco Confidential Page 2 of 13 www.netacad.com
Lab – Getting Familiar with the Linux Shell
Cisco and/or its affiliates. All rights reserved. Cisco Confidential Page 3 of 13 www.netacad.com
Lab – Getting Familiar with the Linux Shell
Answer: The man pwd command is used to access the man page about pwd. The pwd command
prints the name of the current or working directory.
Cisco and/or its affiliates. All rights reserved. Cisco Confidential Page 4 of 13 www.netacad.com
Lab – Getting Familiar with the Linux Shell
c. Type ls -l at the command prompt to list the files and folders that are in the current folder. Standing for
list, the -l option displays file size, permissions, ownership, date of creation and more.
[analyst@secOps ~]$ ls -l
total 20
drwxr-xr-x 2 analyst analyst 4096 Sep 26 2014 Desktop
drwx------ 3 analyst analyst 4096 Jul 14 11:28 Downloads
drwxr-xr-x 8 analyst analyst 4096 Jul 25 16:27 lab.support.files
drwxr-xr-x 2 analyst analyst 4096 Mar 3 15:56 second_drive
-rw-r--r-- 1 analyst analyst 254 Aug 16 13:38 space.txt
d. In the current directory, use the mkdir command to create three new folders: cyops_folder1,
cyops_folder2, and cyops_folder3. Type mkdir cyops_folder1 and press Enter. Repeat these steps to
create cyops_folder2 and cyops_folder3.
[analyst@secOps ~]$ mkdir cyops_folder1
[analyst@secOps ~]$ mkdir cyops_folder2
[analyst@secOps ~]$ mkdir cyops_folder3
[analyst@secOps ~]$
Cisco and/or its affiliates. All rights reserved. Cisco Confidential Page 5 of 13 www.netacad.com
Lab – Getting Familiar with the Linux Shell
Cisco and/or its affiliates. All rights reserved. Cisco Confidential Page 6 of 13 www.netacad.com
Lab – Getting Familiar with the Linux Shell
i. Up to this point, we have been using full paths. Full path is the term used when referring to paths that
always start at the root (/) directory. It is also possible to work with relative paths. Relative paths reduce
the amount of text to be typed. To understand relative paths, we must understand the . and .. (dot and
double) directories. From the cyops_folder3 directory, issue a ls –la:
analyst@secOps ~]$ ls –la /home/analyst/cyops_folder3
total 12
drwxr-xr-x 3 analyst analyst 4096 Aug 16 15:04 .
drwxr-xr-x 20 analyst analyst 4096 Aug 16 15:02 ..
drwxr-xr-x 2 analyst analyst 4096 Aug 16 15:04 cyops_folder4
The -a option tells ls to show all files. Notice the . and .. listings shown by ls. These listings are used by
the operating system to track the current directory (.) and the parent directory (..) You can see the use of
the . and .. when using the cd command to change directories. Using the cd command to change the
directory to the . directory incurs no visible directory change as the . points to the current directory itself.
Cisco and/or its affiliates. All rights reserved. Cisco Confidential Page 7 of 13 www.netacad.com
Lab – Getting Familiar with the Linux Shell
k. Type cd .
[analyst@secOps cyops_folder3]$ cd .
[analyst@secOps cyops_folder3]$
What happens?
Answer: When you type the command cd . and press Enter, nothing visibly happens, and the
command prompt remains the same. The reason for this is that the "." (dot) notation is used to
represent the current directory itself.
l. Changing the directory to the .. directory, will change to the directory that is one level up. This directory is
also known as parent directory. Type cd ..
[analyst@secOps cyops_folder3]$ cd ..
[analyst@secOps ~]$
What happens?
Answer: When you execute cd .., you are instructing the shell to change the current working
directory to the parent directory of the directory you were previously in. In your example, you
were initially in the "cyops_folder3" directory, and by running cd .., you moved up one level to the
parent directory, which is represented by "~" (the home directory of the user "analyst").As a
result, your command prompt now shows that you are in the home directory of the "analyst" user,
which is indicated as "[analyst@secOps ~]$".
What would be the current directory if you issued the cd .. command at [analyst@secOps ~]$?
Directory home
Cisco and/or its affiliates. All rights reserved. Cisco Confidential Page 8 of 13 www.netacad.com
Lab – Getting Familiar with the Linux Shell
What would be the current directory if you issued the cd .. command at [analyst@secOps home]$?
Directory “/”
What would be the current directory if you issued the cd .. command at [analyst@secOps /]$?
If you issue the cd .. command at the prompt [analyst@secOps /]$, you would move up one level from the
current directory, which is the root directory /. However, the root directory doesn't have a parent directory,
so attempting to move up from the root directory using cd ..
b. Use the echo command to echo a message. Because no output was defined, echo will output to the
current terminal window:
analyst@secOps ~]$ echo This is a message echoed to the terminal by echo.
This is a message echoed to the terminal by echo.
Cisco and/or its affiliates. All rights reserved. Cisco Confidential Page 9 of 13 www.netacad.com
Lab – Getting Familiar with the Linux Shell
c. Use the > operator to redirect the output of echo to a text file instead of to the screen:
analyst@secOps ~]$ echo This is a message echoed to the terminal by echo. >
some_text_file.txt
No output was shown. Is that expected?
Answer: Yes, it is expected that no output is shown when you use the > operator to redirect the
output of a command to a text file.
d. Notice that even though the some_text_file.txt file did not exist, it was automatically created to receive
the output generated by echo. Use the ls -l command to verify if the file was really created:
[analyst@secOps ~]$ ls –l some_text_file.txt
-rw-r--r-- 1 analyst analyst 50 Feb 24 16:11 some_text_file.txt
e. Use the cat command to display the contents of the some_text_file.txt text file:
[analyst@secOps ~]$ cat some_text_file.txt
This is a message echoed to the terminal by echo.
f. Use the > operator again to redirect a different echo output of echo to the some_text_file.txt text file:
analyst@secOps ~]$ echo This is a DIFFERENT message, once again echoed to the
terminal by echo. > some_text_file.txt
g. Once again, use the cat command to display the contents of the some_text_file.txt text file:
[analyst@secOps ~]$ cat some_text_file.txt
This is a DIFFERENT message, once again echoed to the terminal by echo.
What happened to the text file? Explain.
____________________________________________________________________________________
____________________________________________________________________________________
Cisco and/or its affiliates. All rights reserved. Cisco Confidential Page 10 of 13 www.netacad.com
Lab – Getting Familiar with the Linux Shell
Cisco and/or its affiliates. All rights reserved. Cisco Confidential Page 11 of 13 www.netacad.com
Lab – Getting Familiar with the Linux Shell
c. Use the ls command to verify that some_text_file.txt is also in the home directory:
[analyst@secOps ~]$ ls -l
total 36
drwxr-xr-x 2 analyst analyst 4096 Aug 16 15:01 cyops_folder1
drwxr-xr-x 2 analyst analyst 4096 Aug 16 15:11 cyops_folder2
drwxr-xr-x 3 analyst analyst 4096 Aug 16 15:04 cyops_folder3
drwxr-xr-x 2 analyst analyst 4096 Sep 26 2014 Desktop
drwx------ 3 analyst analyst 4096 Jul 14 11:28 Downloads
drwxr-xr-x 8 analyst analyst 4096 Jul 25 16:27 lab.support.files
drwxr-xr-x 2 analyst analyst 4096 Mar 3 15:56 second_drive
-rw-r--r-- 1 analyst analyst 142 Aug 16 15:09 some_text_file.txt
-rw-r--r-- 1 analyst analyst 254 Aug 16 13:38 space.txt
Cisco and/or its affiliates. All rights reserved. Cisco Confidential Page 12 of 13 www.netacad.com
Lab – Getting Familiar with the Linux Shell
Reflection
What are the advantages of using the Linux command line?
_______________________________________________________________________________________
_______________________________________________________________________________________
Cisco and/or its affiliates. All rights reserved. Cisco Confidential Page 13 of 13 www.netacad.com