0% found this document useful (0 votes)
2 views6 pages

Intro To The Command Line Lab

The CIT 171 lab focuses on teaching basic command line operations in a CentOS VM, including navigating directories, displaying file contents, and using command history. Students will practice commands like 'pwd', 'ls', 'date', and 'wc', as well as create and manage files in specific directories. The lab culminates in a quiz that tests knowledge of the commands learned during the session.

Uploaded by

qalbeabbas247
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views6 pages

Intro To The Command Line Lab

The CIT 171 lab focuses on teaching basic command line operations in a CentOS VM, including navigating directories, displaying file contents, and using command history. Students will practice commands like 'pwd', 'ls', 'date', and 'wc', as well as create and manage files in specific directories. The lab culminates in a quiz that tests knowledge of the commands learned during the session.

Uploaded by

qalbeabbas247
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

CIT 171 Introduction to the Command Line Lab

In this lab, you will use your CentOS VM to learn how to execute basic commands in the terminal.

Outcomes
 Practice using basic command line editing and history functions to efficiently execute commands
 Execute commands used to identify your current working directory
 Execute commands to display directory contents

CentOS will timeout after a few minutes of inactivity. If this happens to you, click inside of your VM, hit
enter, and then simply login again. Your password should be cit171 if you correctly completed the first
lab.

Part 1: Terminal Practice


1. Open a terminal window to access a bash prompt by first clicking Activities (top left corner) and
then Terminal.

2. Display the path of your current working directory.


Command: pwd
1
Revised: 12/19/23
Feedback incorporated from student teaching assistants Rohan Karki and Kayla Saunders
The pwd command stands for print working directory and prints the absolute path of your
current working directory. This helps to identify your location in the filesystem.

3. Display the current date and time.


Command: date

4. Display the current time in the following format: HH:MM:SS A/PM.


Command: date +%r

Note: When interpreting the above command, date is the command and +%r is a modifier,
specific to the date command, that modifies command output.

5. Display the contents of the current directory.


Command: ls

6. Display the newline, word, and byte counts for the /etc/passwd file.
Command: wc /etc/passwd

7. Display the contents of the /etc/passwd file. Note, this will be many more lines of output than
what you see in the below screenshot.
Command: cat /etc/passwd

2
Revised: 12/19/23
Feedback incorporated from student teaching assistants Rohan Karki and Kayla Saunders
8. Display the first 10 lines of the /etc/passwd file.
Command: head /etc/passwd

The up-arrow displays the previous command. Esc+b makes the cursor jump back one
word at a time. There are many more command line editing key combos!
9.
Display the first 5 lines of the /etc/passwd file. To easily recall your last command so you don’t
have to retype it, hit the up-arrow key. You can either use the left-arrow key to move towards
the front of the line or you can hit Esc+b to move the cursor back one word at a time. Modify
your command.

Command: head -5 /etc/passwd

10. Display a list of previous commands using the history command. Make note of the number
identifying the date +%r command that you ran earlier. Note that your history may look
different from the screenshot.

3
Revised: 12/19/23
Feedback incorporated from student teaching assistants Rohan Karki and Kayla Saunders
Take a screenshot of your history output. You will need this as part of your lab
submission.

11. Using the number next to date +%r, run the below command in order to re-execute date
+%r without having to retype the command (in my example, the number is 3, but your number
might be different).
Command: !3

Part 2: File system commands


1. In your home directory (run cd ~ if you aren’t already located there), you will create a set of
empty files under a new directory called Seasons that will be used in the next lab.

Create a directory called Seasons. Then run the ls command to confirm successful creation.ls
Commands: mkdir Seasons

ls

4
Revised: 12/19/23
Feedback incorporated from student teaching assistants Rohan Karki and Kayla Saunders
2. Change directories to the Seasons directory that you just created. Because it is located in your
current working directory, you can use a relative path.
Command: cd Seasons

3. Once you have successfully changed directories to Seasons (you should see Seasons after localhost
like in the above screenshot), you will create a total of 12 files with this naming convention:
tv_seasonX_episodeY.ogg

‘X’ will be replaced with the season number and ‘Y’ will be replaced with that season’s episode
number. There will be two seasons with six episodes per season. Once you create the files, run the
ls command to confirm file creation.
Command: touch tv_season{1..2}_episode{1..6}.ogg

The touch command creates an empty file. In order to avoid running the touch command 12
separate time, we use brace expansion, a feature in Linux shells, to generate multiple file names in a
concise manner. In this case, {1..2} inside the braces expands to "1 2," and {1..6} expands to
"1 2 3 4 5 6." The combination of these expansions creates a series of file names with different
season and episode numbers.

Do you make a typo?


If it is a single file, you can easily rename it. Example:
mv tvseason1_episode1.ogg tv_season1_episode1.ogg
This will rename the file. Note that there are two parameters: 1) the original file name and 2) the new
file name. A space separates each parameter.

Did you mess up all 12 files? Let’s delete them all and you can run the touch command again.

rm t*
This command will remove all files that begin with a lowercase ‘t’.

4. You are also writing a series of mystery novels and your next bestseller’s chapters will need edited
for publishing. You will be creating a total of eight files, but first, let’s move up one directory level.
This will take you back to your user’s home directory.
Command: cd ..

5
Revised: 12/19/23
Feedback incorporated from student teaching assistants Rohan Karki and Kayla Saunders
Note how your prompt changes to show the directory name of your current working directory. The ~
expands to the full path to your home directory. In this example, ~ expands to /home/etaylor.

5. From your home directory, create a directory called Chapters. Once done, move into Chapters.
Reference earlier examples if you need help (Pt. 2 #1)

6. Once you are located in Chapters, create a total of eight files with names mystery_chapterX.odf.
Replace X with the numbers 1 through 8. Reference earlier examples if you need help (Pt 2. #3)

7. Once you have successfully created your files, you can complete the questions below. Power off
your VM once you are completely done.

Canvas “Quiz” Questions


1. Submit a screenshot of your history command output. If you accidentally closed your terminal,
simply reopen it and run the history command again. It is ok if your history has errors!
2. Which command prints the newline, word, and byte counts for a file? Type in ONLY the
command. For example, if the answer is the ls command, I would just enter ls for my answer.
3. Which command prints the path to your current working directory? Type in ONLY the
command. For example, if the answer is the ls command, I would just enter ls for my answer.
4. Which command displays a list of commands previously run? Type in ONLY the command. For
example, if the answer is the ls command, I would just enter ls for my answer.
5. What command did you use in this lab to displays the contents of a file?
6. Based on the command used in this lab, how would you display the contents of a file called
/etc/shadow?
7. What command displays the current date and time?
8. What command can you use to create a directory?
9. What symbol expands to the full path of your home directory?
10. What command do you use to change directories in Linux?

6
Revised: 12/19/23
Feedback incorporated from student teaching assistants Rohan Karki and Kayla Saunders

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy