You are on page 1of 15

Activity 3-1: Using the pwd and cd Commands Time Required: 10 minutes Objective: Practice

navigating the Linux directory structure. Description: In this activity, you open a terminal
window and use the pwd command to display your current directory and the cd command to
change your current directory. You also get practice using the BASH command-completion
feature. 1. Use the skills you learned in Chapter 2 to start VMware Player and start an openSUSE
virtual machine. 2. Log in to openSUSE as a user other than root, and open a terminal window,
using the instructions given earlier in this chapter.
3. Type pwd and press Enter to view your current directory. What is your current directory?

4. Type cd /etc and press Enter, and then type pwd and press Enter. Is your current directory the
same? Why or why not? What method did you use to change to the /etc directory?
5. Use the relative method to change to your parent directory by typing cd .. and pressing Enter.
What directory are you in now?

6. Type cd and press Enter. What happens when you use the cd command without arguments?

7. Type cd D and press Tab two times. What’s displayed onscreen, and why?
Activity 3-2: Using the ls Command Time Required: 10 minutes

Objective: Use commands for viewing Linux files and directories.

Description: In this activity, you use the ls command to view files and directories in your current
directory and practice using options, including two you choose from Table 3-2.

1. If necessary, start VMware Player and start an openSUSE virtual machine. Log in to openSUSE
as a user other than root, and open a terminal window.

2. Type ls and press Enter, and then type ls -l and press Enter.
3. Display a long list of the /etc directory by typing ls -l /etc and pressing Enter.
4. Display a long list of the /etc/hosts file by typing ls -l /etc/hosts and pressing Enter. What’s
the timestamp of this file?

5. Display all files in your home directory, including hidden files, by typing ls -a ~ and

pressing Enter.
6. Review Table 3-2 and choose two options to use in your current directory. List the options
you chose and briefly describe the results of using them:

ls -F

ls -R
Activity 3-3: Working with Man Pages

Time Required: 10 minutes

Objective: Find and navigate man pages for any Linux command.

Description: In this activity, you use the man command to open help files on the pwd, cd,

and ls commands. You also use the man command to find documentation on another command
of your choice and refer to Table 3-4 to navigate the man page.

1. If necessary, start VMware Player and start an openSUSE virtual machine. Log in to
openSUSE as a user other than root, and open a terminal window

2. Display the man page for the pwd command by typing man pwd and pressing Enter.
Press q to quit, and then try typing man 1 pwd and pressing Enter. What’s the difference
in the output of these two commands?
3. Display the man page for the cd command by typing man cd and pressing Enter. Read
the information, as time permits.
4. Display the man page for the ls command by typing man ls and pressing Enter. Read the
information, as time permits.
5. Display the man page for a command of your choice. Refer to Table 3-4 to practice
navigating it.
6. Leave the terminal window open and the virtual machine running for the next activity..

Activity 3-4: Using Wildcards

Time Required: 10 minutes

Objective: Use wildcards to search for files and directories.

Description: In this activity, you use the common wildcards * and ?. You also see the results of
more uncommon wildcards.

1. If necessary, start VMware Player and start an openSUSE virtual machine. Log in to
openSUSE as a user other than root, and open a terminal window.
2. Use the absolute method to change to the /etc directory by typing cd /etc and pressing
Enter.
3. Display a long list of files and directories in the /etc directory by typing ls -l and pressing
Enter.
4. Display a long list of files and directories in the /etc directory starting with the letter “h”
by typing ls -l h* and pressing Enter. How are the results different from Step 3?.
5. Display a long list of files and directories in the /etc directory and use two wildcards by
typing ls -l *.? and pressing Enter. How are the results different from Step 3?
6. Display a long list of files and directories in the /etc directory starting with a, c, or k by
typing ls -l [ack]* and pressing Enter.
7. Display a long list of files and directories in the /etc directory starting with a, b, or c by
typing ls -l [a-c]* and pressing Enter.
8. Display a long list of files and directories in the /etc directory that don’t start with the
letters a through s by typing ls -l [!a-s]* and pressing Enter.
9. Change the current directory by typing cd /h* and pressing Enter. What happened, and
why?
10. Leave the terminal window open and the virtual machine running for the next activity.

Activity 3-5: Creating and Deleting Directories and Files

Time Required: 15 minutes

Objective: Use Linux commands for creating and deleting directories and files.

Description: In this activity, you create a directory with the mkdir command, create files

with the touch command, and update file timestamps by using the touch command

with wildcards. Finally, you use the rm command to delete files and the rmdir command

to delete a directory.

1. If necessary, start VMware Player and start an openSUSE virtual machine. Log in to
openSUSE as a user other than root, and open a terminal window.
2. Change to your home directory by typing cd and pressing Enter.
3. Create and name a directory by typing mkdir Activity3-5 and pressing Enter.
4. Change to the Activity3-5 directory by typing cd Activity3-5 and pressing Enter.
5. Create three files in the Activity3-5 directory by typing touch actfile1 actfile2 actfile3
and pressing Enter.
6. Display a long list of all files in the Activity3-5 directory by typing ls -l and pressing Enter.
7. Update the timestamps of these files by typing touch *[2-3] and pressing Enter. What
files are updated?
8. To return to your home directory, type cd and press Enter
9. Try to delete the Activity3-5 directory by typing rmdir Activity3-5 and pressing Enter.
Were you able to delete the directory? Why or why not?
10. Change to the Activity3-5 directory by typing cd Activity3-5 and pressing Enter. Delete
the three files (actfile1, actfile2, and actfile3) by typing rm * and pressing Enter.
11. Type ls and press Enter. Is the directory empty?
12. Change to your home directory by typing cd and pressing Enter.
13. Now that the Activity3-5 directory is empty, delete it by typing rmdir Activity3-5 and
pressing Enter.
14. Leave the terminal window open and the virtual machine running for the next activity.

Activity 3-6: Renaming, Moving, and Copying Files

Time Required: 15 minutes

Objective: Use Linux commands for renaming, moving, and copying files.

Description: In this activity, you create a directory called Activity3-6 and create a file in this
directory. You use the mv command to rename the file and then move it to the parent directory.
You also use the cp command to make a copy of the file in the Activity3-6 directory.

1. If necessary, start VMware Player and start an openSUSE virtual machine. Log in to
openSUSE as a user other than root, and open a terminal window.
2. Type mkdir Activity3-6 and press Enter, and then change to this new directory by typing
cd Activity3-6 and pressing Enter.

3. Type touch actfile1 and press Enter. Type ls and press Enter.

4. Type mv actfile1 actfile2 and press Enter, and then type ls and press Enter. What’s the
result of this mv command?

5. Type mv actfile2 .. and press Enter, and then type ls and press Enter. What’s the result
of this command?

6. Type cd .. and press Enter. What directory are you in?

7. Type cp actfile2 actfile3 and press Enter. What’s the result of this command?

8. Type cp actfile2 Activity3-6 and press Enter. What happens? Change to the Activity3-6
directory, and then type ls and press Enter. What files are in this directory?

9. Leave the terminal window open and the virtual machine running for the next activity.

You might also like