Project 1
3-1 to 3-7
When doing the projects in any application please use the
following name destro32@destro32
Do: Hands - on Projects from 3-1 to 3-7
P.S. Ignore question 1 from every exercise.
Copy and paste your commands and your results into MS Word.
You can do that by copy and paste from your terminal into text
editor in Linux and email to yourself in webrowser that exist in
your Linux OS.
1. In linux ubuntu. When completed screen shot the
end results.
1. 1
Boot your Fedora Linux virtual machine. After your Linux system has
been loaded, switch to a command-line terminal (tty2) by
pressing Ctrl+Alt+F2 and log in to the terminal using the user name
of root and the password of LNXrocks!.
2. 2
At the command prompt, type pwd and press Enter to view the current
working directory. What is your current working directory?
3. 3
At the command prompt, type cd and press Enter. At the command
prompt, type pwd and press Enter to view the current working directory.
Did your current working directory change? Why or why not?
4. 4
At the command prompt, type cd . and press Enter. At the command
prompt, type pwd and press Enter to view the current working directory.
Did your current working directory change? Why or why not?
5. 5
At the command prompt, type cd .. and press Enter. At the command
prompt, type pwd and press Enter to view the current working directory.
Did your current working directory change? Why or why not?
6. 6
At the command prompt, type cd root and press Enter. At the
command prompt, type pwd and press Enter to view the current working
directory. Did your current working directory change? Where are you
now? Did you specify a relative or absolute pathname to your home
directory when you used the cd root command?
7. 7
At the command prompt, type cd etc and press Enter. What error
message did you receive and why?
8. 8
At the command prompt, type cd /etc and press Enter. At the
command prompt, type pwd and press Enter to view the current working
directory. Did your current working directory change? Did you specify a
relative or absolute pathname to the /etc directory when you used the cd
/etc command?
9. 9
At the command prompt, type cd / and press Enter. At the command
prompt, type pwd and press Enter to view the current working directory.
Did your current working directory change? Did you specify a relative or
absolute pathname to the / directory when you used the cd / command?
10. 10
At the command prompt, type cd ~user1 and then press Enter. At the
command prompt, type pwd and press Enter to view the current working
directory. Did your current working directory change? Which command
discussed earlier performs the same function as the cd ~ command?
11. 11
At the command prompt, type cd Desktop and press Enter (be certain
to use a capital D). At the command prompt, type pwd and press Enter to
view the current working directory. Did your current working directory
change? Where are you now? What kind of pathname did you use here
(absolute or relative)?
12. 12
Currently, you are in a subdirectory of user1’s home folder, three levels
below the root. To go up three parent directories to the / directory,
type cd ../../.. and press Enter at the command prompt. Next,
type pwd and press Enter to ensure that you are in the / directory.
13. 13
At the command prompt, type cd /etc/samba and press Enter to
change the current working directory using an absolute pathname. Next,
type pwd and press Enter at the command prompt to ensure that you
have changed to the /etc/samba directory. Now, type in the command cd
../sysconfig at the command prompt and press Enter. Type pwd and
press Enter to view your current location. Explain how the relative
pathname seen in the cd ../sysconfig command specified your
current working directory.
14. 14
At the command prompt, type cd ../../home/user1/Desktop and
press Enter to change your current working directory to the Desktop
directory underneath user1’s home directory. Verify that you are in the
target directory by typing the pwd command at a command prompt and
press Enter. Would it have been more advantageous to use an absolute
pathname to change to this directory instead of the relative pathname
that you used?
15. 15
Type exit and press Enter to log out of your shell.
Project 3-2
In this hands-on project, you navigate the Linux filesystem using the Tab-
completion feature of the BASH shell.
1. 1
Switch to a command-line terminal (tty2) by pressing Ctrl+Alt+F2 and
log in to the terminal using the user name of root and the password
of LNXrocks!.
2. 2
At the command prompt, type cd / and press Enter.
3. 3
Next, type cd ro at the command prompt and press Tab. What is
displayed on the screen and why? How many subdirectories under the
root begin with “ro”?
4. 4
Press the Ctrl and c keys simultaneously to cancel the command and
return to an empty command prompt.
5. 5
At the command prompt, type cd b and press Tab. Did the display
change?
6. 6
Press the Tab key again. How many subdirectories under the root begin
with “b”?
7. 7
Type the letter i. Notice that the command now reads “cd bi.” Press
the Tab key again. Which directory did it expand to? Why? Press
the Ctrl and c keys simultaneously to cancel the command and return to
an empty command prompt.
8. 8
At the command prompt, type cd m and press Tab. Press Tab once again
after hearing the beep. How many subdirectories under the root begin
with “m”?
9. 9
Type the letter i. Notice that the command now reads “cd me.” Press Tab.
10. 10
Press Enter to execute the command at the command prompt. Next, type
the pwd command and press Enter to verify that you are in the /media
directory.
11. 11
Type exit and press Enter to log out of your shell.
Project 3-3
In this hands-on project, you examine files and file types using
the ls and file commands.
1. 1
Switch to a command-line terminal (tty2) by pressing Ctrl+Alt+F2 and
log in to the terminal using the user name of root and the password
of LNXrocks!.
2. 2
At the command prompt, type cd /etc and press Enter. Verify that you
are in the /etc directory by typing pwd at the command prompt and
press Enter.
3. 3
At the command prompt, type ls and press Enter. What do you see listed
in the four columns? Do any of the files have extensions? What is the most
common extension you see and what does it indicate? Is the list you are
viewing on the screen the entire contents of /etc?
4. 4
At the command prompt, type ls | more and then press Enter (the |
symbol is usually near the Enter key on the keyboard and is obtained by
pressing the Shift and \ keys in combination). What does the display
show? Notice the highlighted --More-- prompt at the bottom of the
screen. Press Enter. Press Enter again. Press Enter once more. Notice
that each time you press Enter, you advance one line further into the file.
Now, press the spacebar. Press the spacebar again. Notice that with
each press of the spacebar, you advance one full page into the displayed
directory contents. Press the h key to get a help screen. Examine the
command options.
5. 5
Press the q key to quit the more command and return to an empty
command prompt.
6. 6
At the command prompt, type ls | less and then press Enter. What does
the display show? Notice the : at the bottom of the screen. Press Enter.
Press Enter again. Press Enter once more. Notice that each time you
press Enter, you advance one line further into the file. Now press
the spacebar. Press the spacebar again. Notice that with each press of
the spacebar, you advance one full page into the displayed directory
contents. Press the h key to get a help screen. Examine the command
options, and then press q to return to the command output.
7. 7
Press the ↑ (up arrow) key. Press ↑ again. Press ↑ once more. Notice that
each time you press the ↑ key, you go up one line in the file display toward
the beginning of the file. Now, press the ↓ (down arrow) key. Press ↓ again.
Press ↓ once more. Notice that each time you press the ↓ key, you move
forward into the file display.
8. 8
Press the q key to quit the less command and return to a shell command
prompt.
9. 9
At the command prompt, type cd and press Enter. At the command
prompt, type pwd and press Enter. What is your current working
directory? At the command prompt, type ls and press Enter.
10. 10
At the command prompt, type ls /etc and press Enter. How does this
output compare with what you saw in Step 9? Has your current directory
changed? Verify your answer by typing pwd at the command prompt and
press Enter. Notice that you were able to list the contents of another
directory by giving the absolute name of it as an argument to
the ls command without leaving the directory in which you are currently
located.
11. 11
At the command prompt, type ls /etc/skel and press Enter. Did you
see a listing of any files? At the command prompt, type ls -a
/etc/skel and press Enter. What is special about these files? What do
the first two entries in the list ( . and .. ) represent?
12. 12
At the command prompt, type ls -aF /etc/skel and press Enter.
Which file types are available in the /etc/skel directory?
13. 13
At the command prompt, type ls /bin and press Enter. Did you see a
listing of any files? At the command prompt, type ls -F /bin and
press Enter. What file types are present in the /bin directory?
14. 14
At the command prompt, type ls /boot and press Enter. Next, type ls
l /boot and press Enter. What additional information is available on
the screen? What types of files are available in the /boot directory? At the
command prompt, type ll /boot and press Enter. Is the output any
different from that of the ls -l /boot command you just entered? Why
or why not?
15. 15
At the command prompt, type file /etc and press Enter. What kind of
file is etc?
16. 16
At the command prompt, type file /etc/inittab and press Enter.
What type of file is /etc/inittab?
17. 17
At the command prompt, type file /boot/* to see the types of files in
the /boot directory. Is this information more specific than the
information you gathered in Step 14?
18. 18
Type exit and press Enter to log out of your shell.
Project 3-4
In this hands-on project, you display file contents using
the cat, tac, head, tail, strings, and od commands.
1. 1
Switch to a command-line terminal (tty2) by pressing Ctrl+Alt+F2, and
then log in to the terminal using the user name of root and the password
of LNXrocks!.
2. 2
At the command prompt, type cat /etc/hosts and press Enter to
view the contents of the file hosts, which reside in the directory /etc.
Next, type cat -n /etc/hosts and press Enter. How many lines does
the file have? At the command prompt, type tac /etc/hosts and
press Enter to view the same file in reverse order. The output of both
commands should be visible on the same screen. Compare them.
3. 3
To see the contents of the same file in octal format instead of ASCII text,
type od / etc/hosts at the command prompt and press Enter.
4. 4
At the command prompt, type cat /etc/inittab and press Enter.
5. 5
At the command prompt, type head /etc/inittab and press Enter.
What is displayed on the screen? How many lines are displayed, which
ones are they, and why?
6. 6
At the command prompt, type head -5 /etc/inittab and
press Enter. How many lines are displayed and why? Next, type head -3
/etc/inittab and press Enter. How many lines are displayed and
why?
7. 7
At the command prompt, type tail /etc/inittab and press Enter.
What is displayed on the screen? How many lines are displayed; which
ones are they and why?
8. 8
At the command prompt, type tail -5 /etc/inittab and
press Enter. How many lines are displayed and why? Type the cat -
n /etc/inittab command at a command prompt and press Enter to
justify your answer.
9. 9
At the command prompt, type file /bin/nice and press Enter. What
type of file is it? Should you use a text tool command on this file?
10. 10
At the command prompt, type strings /bin/nice and press Enter.
Notice that you are able to see some text within this binary file. Next,
type strings /bin/nice | more to view the same content page-by-
page. When finished, press q to quit the more command.
11. 11
Type exit and press Enter to log out of your shell.
Project 3-5
In this hands-on project, you create and edit text files using the vi editor.
1. 1
Switch to a command-line terminal (tty2) by pressing Ctrl+Alt+F2 and
log in to the terminal using the user name of root and the password
of LNXrocks!.
2. 2
At the command prompt, type pwd, press Enter, and ensure that /root is
displayed, showing that you are in the root user’s home folder. At the
command prompt, type vi sample1 and press Enter to open the vi
editor and create a new text file called sample1. Notice that this name
appears at the bottom of the screen along with the indication that it is a
new file.
3. 3
At the command prompt, type My letter and press Enter. Why was
nothing displayed on the screen? To switch from command mode to
insert mode to allow the typing of text, press i. Notice that the word
Insert appears at the bottom of the screen. Next, type My letter and
notice that this text is displayed on the screen. What types of tasks can be
accomplished in insert mode?
4. 4
Press Esc. Did the cursor move? What mode are you in now? Press ← two
times until the cursor is under the last t in letter. Press the x key. What
happened? Next, type i to enter insert mode, then type the letter “h.” Did
the letter “h” get inserted before or after the cursor?
5. 5
Press Esc to switch back to command mode and then move your cursor to
the end of the line. Next, type the letter “o” to open a line underneath the
current line and enter insert mode.
6. 6
Type the following:
Notice that the line wraps to the next line partway through the sentence.
Though displayed over two lines on the screen, this sentence is treated as
one continuous line of text in vi. Press Esc to return to command mode,
and then press ↑. Where does the cursor move? Use the cursor keys to
navigate to the letter “l” at the beginning of the word “level,” and then
press the i key to enter insert mode. Press the Enter key while in insert
mode. Next, press Esc to return to command mode, and then press ↑.
Where does the cursor move?
7. 7
Type dd three times to delete all lines in the file.
8. 8
Type i to enter insert mode, and then type:
and press Enter. Press Enter again. Type:
and press Enter. Type:
and press Enter. Type:
and press Enter. Type:
and press Enter. Press Enter again. Type:
and press Enter. Type:
and press Enter. Type:
and press Enter. Press Enter again. Type:
and press Enter. Type:
and press Enter. Press Enter again. Type:
and press Enter. Type:
and press Enter. You should now have the sample letter used in this
chapter on your screen. It should resemble the letter in Figure 3-4.
9. 9
Press Esc to switch to command mode. Next press the Shift and ; keys
simultaneously to open the : prompt at the bottom of the screen. At this
prompt, type w and press Enter to save the changes you have made to the
file. What is displayed at the bottom of the file when you are finished?
10. 10
Press the Shift and ; keys simultaneously to open the : prompt at the
bottom of the screen again, type q, and then press Enter to exit the vi
editor.
11. 11
At the command prompt, type ls and press Enter to view the contents of
your current directory. Notice that there is now a file called sample1
listed.
12. 12
Next, type file sample1 and press Enter. What type of file is sample1?
At the command prompt, type cat sample1 and press Enter.
13. 13
At the command prompt, type vi sample1 and press Enter to open the
letter again in the vi editor. What is displayed at the bottom of the screen?
How does this compare with Step 9?
14. 14
Use the cursor keys to navigate to the bottom of the document. Press
the Shift and ; keys simultaneously to open the : prompt at the bottom of
the screen again, type !date and press Enter. The current system date
and time appear at the bottom of the screen. As indicated, press Enter to
return to the document.
15. 15
Press the Shift and ; keys simultaneously again to open the : prompt at
the bottom of the screen again, type r !date and press Enter. What
happened and why?
16. 16
Use the cursor keys to position your cursor on the line in the document
that displays the current date and time, and type yy to copy it to the
buffer in memory. Next, use the cursor keys to position your cursor on
the first line in the document, and type P (capitalized) to paste the
contents of the memory buffer above your current line. Does the original
line remain at the bottom of the document?
17. 17
Use the cursor keys to position your cursor on the line at the end of the
document that displays the current date and time, and type dd to delete
it.
18. 18
Use the cursor keys to position your cursor on the t in the word “there”
on the second line of the file that reads Hi there, I hope this day finds
you well., and press dw to delete the word. Next, type i to enter insert
mode, type the word Bob, and then press Esc to switch back to command
mode.
19. 19
Press the Shift and ; keys simultaneously to open the : prompt at the
bottom of the screen again, type w sample2 and press Enter. What
happened and why?
20. 20
Press i to enter insert mode, and type the word test. Next, press Esc to
switch to command mode. Press the Shift and ; keys simultaneously to
open the : prompt at the bottom of the screen again, type q, and
press Enter to quit the vi editor. Were you able quit? Why not?
21. 21
Press the Shift and ; keys simultaneously to open the : prompt at the
bottom of the screen again, type q!, and press Enter to quit the vi editor
and discard any changes since the last save.
22. 22
At the command prompt, type ls and press Enter to view the contents of
your current directory. Notice that there is now a file called sample2,
which was created in Step 19.
23. 23
At the command prompt, type vi sample2 and press Enter to open the
letter again in the vi editor.
24. 24
Use the cursor keys to position your cursor on the line that reads Hi Bob,
I hope this day finds you well.
25. 25
Press the Shift and ; keys simultaneously to open the : prompt at the
bottom of the screen, type s/Bob/Barb/g, and press Enter to change all
occurrences of “Bob” to “Barb” on the current line.
26. 26
Press the Shift and ; keys simultaneously to open the : prompt at the
bottom of the screen again, type 1,$ s/to/TO/g, and press Enter to
change all occurrences of the word “to” to “TO” for the entire file.
27. 27
Press the u key to undo the last function performed. What happened and
why?
28. 28
Press the Shift and ; keys simultaneously to open the : prompt at the
bottom of the screen again, type wq, and press Enter to save your
document and quit the vi editor.
29. 29
At the command prompt, type vi sample3 and press Enter to open a
new file called sample3 in the vi editor. Type i to enter insert mode. Next,
type P.S. How were the flies this year? Press the Esc key
when finished.
30. 30
Press the Shift and ; keys simultaneously to open the : prompt at the
bottom of the screen again, type wq, and press Enter to save your
document and quit the vi editor.
31. 31
At the command prompt, type vi sample1, press Enter to open the file
sample1 again, and use the cursor keys to position your cursor on the line
that reads “Mackenzie Elizabeth.”
32. 32
Press the Shift and ; keys simultaneously to open the : prompt at the
bottom of the screen again, type r sample3, and press Enter to insert
the contents of the file sample3 below your current line.
33. 33
Press the Shift and ; keys simultaneously to open the : prompt at the
bottom of the screen, type s/flies/flies and bears/g and
press Enter. What happened and why?
34. 34
Press the Shift and ; keys simultaneously to open the : prompt at the
bottom of the screen again, type set number, and press Enter to turn on
line numbering.
35. 35
Press the Shift and ; keys simultaneously to open the : prompt at the
bottom of the screen again, type set nonumber, and press Enter to turn
off line numbering.
36. 36
Press the Shift and ; keys simultaneously to open the : prompt at the
bottom of the screen again, type set all, and press Enter to view all vi
parameters. Press Enter to advance through the list, and press q when
finished to return to the vi editor.
37. 37
Press the Shift and ; keys simultaneously to open the : prompt at the
bottom of the screen again, type wq, and press Enter to save your
document and quit the vi editor.
38. 38
Type exit and press Enter to log out of your shell.
Project 3-6
In this hands-on project, you use the ls command alongside wildcard
metacharacters in your shell to explore the contents of your home directory.
1. 1
Switch to a command-line terminal (tty2) by pressing Ctrl+Alt+F2 and
log in to the terminal using the user name of root and the password
of LNXrocks!.
2. 2
At the command prompt, type pwd, press Enter, and ensure /root is
displayed showing that you are in the root user’s home folder. At the
command prompt, type ls. How many files with a name beginning with
the word “sample” exist in /root?
3. 3
At the command prompt, type ls * and press Enter. What is listed and
why?
4. 4
At the command prompt, type ls sample and press Enter. What is
listed and why?
5. 5
At the command prompt, type ls sample? and press Enter. What is
listed and why?
6. 6
At the command prompt, type ls sample?? and press Enter. What is
listed and why?
7. 7
At the command prompt, type ls sample[13] and press Enter. What is
listed and why?
8. 8
At the command prompt, type ls sample[!13] and press Enter. What
is listed and why? How does this compare to the results from Step 7?
9. 9
At the command prompt, type ls sample[1-3] and press Enter. What
is listed and why?
10. 10
At the command prompt, type ls sample[!1-3] and press Enter.
What is listed and why? How does this compare to the results from Step
9?
11. 11
Type exit and press Enter to log out of your shell.
Project 3-7
In this hands-on project, you use the grep and egrep commands alongside
regular expression metacharacters to explore the contents of text files.
1. 1
Switch to a command-line terminal (tty2) by pressing Ctrl+Alt+F2 and
log in to the terminal using the user name of root and the password
of LNXrocks!.
2. 2
At the command prompt, type grep “Inn” sample1 and press Enter.
What is displayed and why?
3. 3
At the command prompt, type grep -v “Inn” sample1 and
press Enter. What is displayed and why? How does this compare to the
results from Step 2?
4. 4
At the command prompt, type grep “inn” sample1 and press Enter.
What is displayed and why?
5. 5
At the command prompt, type grep -i “inn” sample1 and
press Enter. What is displayed and why? How does this compare to the
results from Steps 2 and 4?
6. 6
At the command prompt, type grep “I” Sample1 and press Enter.
What is displayed and why?
7. 7
At the command prompt, type grep “ I ” sample1 and press Enter.
What is displayed and why? How does it differ from the results from Step
6 and why?
8. 8
At the command prompt, type grep “t.e” sample1 and press Enter.
What is displayed and why?
9. 9
At the command prompt, type grep “w…e” sample1 and press Enter.
What is displayed and why?
10. 10
At the command prompt, type grep “ ^I” sample1 and press Enter.
What is displayed and why?
11. 11
At the command prompt, type grep “^I” sample1 and press Enter.
What is displayed and why? How does this differ from the results in Step
10 and why?
12. 12
At the command prompt, type grep “(we|next)” sample1 and
press Enter. Is anything displayed? Why?
13. 13
At the command prompt, type egrep “(we|next)” sample1 and
press Enter. What is displayed and why?
14. 14
At the command prompt, type grep “Inn$” sample1 and press Enter.
What is displayed and why?
15. 15
At the command prompt, type grep “?$” sample1 and press Enter.
What is displayed and why? Does the ? metacharacter have special
meaning here? Why?
16. 16
At the command prompt, type grep “^$” sample1 and press Enter. Is
anything displayed? (Hint: Be certain to look closely!) Can you explain the
output?
17. 17