Intro To The Command Line Lab
Intro 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.
Note: When interpreting the above command, date is the command and +%r is a modifier,
specific to the date command, that modifies command output.
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.
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
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.
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.
6
Revised: 12/19/23
Feedback incorporated from student teaching assistants Rohan Karki and Kayla Saunders