Red Hat System Administration I 2.9 Lab PDF

Download as pdf or txt
Download as pdf or txt
You are on page 1of 17

RED HAT SYSTEM ADMINISTRATION I

2.9. Lab: Managing Files with Shell Expansion


Document Version: 2015-12-28

Copyright © 2015 Network Development Group, Inc.


www.netdevgroup.com

NETLAB Academy Edition, NETLAB Professional Edition, and NETLAB+ are registered trademarks of Network Development Group, Inc.

“Red Hat,” Red Hat Linux, and the Red Hat “Shadowman” logo are trademarks or registered trademarks of Red Hat, Inc. in the US
and other countries.
2.9. Lab: Managing Files with Shell Expansion

Contents
Introduction ........................................................................................................................ 3
Outcomes ............................................................................................................................ 3
Lab Topology ....................................................................................................................... 4
Lab Settings ......................................................................................................................... 5
1 Performance Checklist ................................................................................................ 6

12/28/2015 Copyright © 2015 Network Development Group, Inc. www.netdevgroup.com Page 2


2.9. Lab: Managing Files with Shell Expansion

Introduction

In this lab, you will create, move, and remove files and folders using a variety of file
name matching shortcuts.

Outcomes

Familiarity and practice with many forms of wildcards for locating and using files.

12/28/2015 Copyright © 2015 Network Development Group, Inc. www.netdevgroup.com Page 3


2.9. Lab: Managing Files with Shell Expansion

Lab Topology

12/28/2015 Copyright © 2015 Network Development Group, Inc. www.netdevgroup.com Page 4


2.9. Lab: Managing Files with Shell Expansion

Lab Settings

The information in the table below will be needed in order to complete the lab. The
task sections below provide details on the use of this information.

Virtual Machine IP Address Account Password


(if needed) (if needed)

Server1 Machine 172.25.1.11 student student

Desktop1 Machine 172.25.1.10 student student

12/28/2015 Copyright © 2015 Network Development Group, Inc. www.netdevgroup.com Page 5


2.9. Lab: Managing Files with Shell Expansion

1 Performance Checklist

Before you begin...

Access the graphical login screen of the Server1 virtual machine.

The topology includes two virtual machines that are accessible to users. Take care to
perform the tasks as instructed, including using the appropriate virtual machine as
directed.

1. Log in as student using the password student.

a. At the GNOME login screen, click the student user account. Enter
student when prompted for the password.

b. Click Sign In once the password has been typed in.

12/28/2015 Copyright © 2015 Network Development Group, Inc. www.netdevgroup.com Page 6


2.9. Lab: Managing Files with Shell Expansion

2. Open a terminal window that will provide a bash prompt.

Select Applications → Utilities → Terminal.

12/28/2015 Copyright © 2015 Network Development Group, Inc. www.netdevgroup.com Page 7


2.9. Lab: Managing Files with Shell Expansion

3. In your home directory, create sets of empty practice files to use for the
remainder of this lab. Use the shell tab completion to locate and complete path
names more easily.

Create a total of 12 files with names tv_seasonX_episodeY.ogg. Replace X with


the season number and Y with that season's episode, for two seasons of six
episodes each.

[student@server1 ~]$ touch tv_season{1..2}_episode{1..6}.ogg


[student@server1 ~]$ ls -l

12/28/2015 Copyright © 2015 Network Development Group, Inc. www.netdevgroup.com Page 8


2.9. Lab: Managing Files with Shell Expansion

4. As the author of a successful series of mystery novels, your next bestseller's


chapters are being edited for publishing. Create a total of eight files with names
mystery_chapterX.odf. Replace X with the numbers 1 through 8.

[student@server1 ~]$ touch mystery_chapter{1..8}.odf


[student@server1 ~]$ ls –l

12/28/2015 Copyright © 2015 Network Development Group, Inc. www.netdevgroup.com Page 9


2.9. Lab: Managing Files with Shell Expansion

5. To organize the TV episodes, create two subdirectories named season1 and


season2 under the existing Videos directory. Use one command.

[student@server1 ~]$ mkdir Videos/season{1..2}


[student@server1 ~]$ ls –lR

12/28/2015 Copyright © 2015 Network Development Group, Inc. www.netdevgroup.com Page 10


2.9. Lab: Managing Files with Shell Expansion

6. Move the appropriate TV episodes into the season subdirectories. Use only two
commands, specifying destinations using relative syntax.

[student@server1 ~]$ mv tv_season1* Videos/season1


[student@server1 ~]$ mv tv_season2* Videos/season2
[student@server1 ~]$ ls –lR

12/28/2015 Copyright © 2015 Network Development Group, Inc. www.netdevgroup.com Page 11


2.9. Lab: Managing Files with Shell Expansion

7. To organize the mystery book chapters, create a two-level directory hierarchy


with one command. Create my_bestseller under the existing Documents
directory, and chapters beneath the new my_bestseller directory.

[student@server1 ~]$ mkdir –p Documents/my_bestseller/chapters


[student@server1 ~]$ ls -lR

8. Using one command, create three more subdirectories directly under the
my_bestseller directory. Name these subdirectories editor, plot_change,
and vacation. The create parent option is not needed since the my_bestseller
parent directory already exists.

[student@server1 ~]$ mkdir


Documents/my_bestseller/{editor,plot_change,vacation}
[student@server1 ~]$ ls -lR

12/28/2015 Copyright © 2015 Network Development Group, Inc. www.netdevgroup.com Page 12


2.9. Lab: Managing Files with Shell Expansion

9. Change to the chapters directory. Using the home directory shortcut to specify
the source files, move all book chapters into the chapters directory, which is
now your current directory. What is the simplest syntax to specify the
destination directory?

[student@server1 ~]$ cd Documents/my_bestseller/chapters


[student@server1 chapters]$ mv ~/mystery_chapter* .
[student@server1 chapters]$ ls -l

10. The first two chapters are sent to the editor for review. To remember to not
modify these chapters during the review, move those two chapters only to the
editor directory. Use relative syntax starting from the chapters subdirectory.

[student@server1 chapters]$ mv mystery_chapter1.odf


mystery_chapter2.odf ../editor
[student@server1 chapters]$ ls -l
[student@server1 chapters]$ ls -l ../editor

12/28/2015 Copyright © 2015 Network Development Group, Inc. www.netdevgroup.com Page 13


2.9. Lab: Managing Files with Shell Expansion

11. Chapters 7 and 8 will be written while on vacation. Move the files from
chapters to vacation. Use one command without wildcard characters.

[student@server1 chapters]$ mv mystery_chapter7.odf


mystery_chapter8.odf ../vacation
[student@server1 chapters]$ ls –l
[student@server1 chapters]$ ls -l ../vacation

12. With one command, change the working directory to the season 2 TV episodes
location, then copy the first episode of the season to the vacation directory.

[student@server1 chapters]$ cd ~/Videos/season2


[student@server1 season2]$ cp tv_season2_episode1.ogg
~/Documents/my_bestseller/vacation

12/28/2015 Copyright © 2015 Network Development Group, Inc. www.netdevgroup.com Page 14


2.9. Lab: Managing Files with Shell Expansion

13. With one command, change the working directory to vacation, then list its files.
Episode 2 is also needed. Return to the season2 directory using the previous
working directory shortcut. This will succeed if the last directory change was
accomplished with one command. Copy the episode 2 file into vacation. Return
to vacation using the shortcut again.

[student@server1 season2]$ cd ~/Documents/my_bestseller/vacation


[student@server1 vacation]$ ls -l
[student@server1 vacation]$ cd -
[student@server1 season2]$ cp tv_season2_episode2.ogg
~/Documents/my_bestseller/vacation
[student@server1 vacation]$ cd -
[student@server1 vacation]$ ls -l

14. Chapters 5 and 6 may need a plot change. To prevent these changes from
modifying original files, copy both files into plot_change. Move up one directory
to vacation's parent directory, then use one command from there.

[student@server1 vacation]$ cd ..
[student@server1 my_bestseller]$ cp chapters/mystery_chapter[56].odf
plot_change
[student@server1 my_bestseller]$ ls -l chapters
[student@server1 my_bestseller]$ ls -l plot_change

12/28/2015 Copyright © 2015 Network Development Group, Inc. www.netdevgroup.com Page 15


2.9. Lab: Managing Files with Shell Expansion

15. To track changes, make three backups of chapter 5. Change to the plot_change
directory. Copy mystery_chapter5.odf as a new file name to include the full
date (Year-Mo-Da). Make another copy appending the current time-stamp (as
the number of seconds since the epoch) to ensure a unique file name. Also make
a copy appending the current user ($USER) to the file name. See the solution for
the syntax of any commands you are unsure of (such as the arguments to pass
the date command).

[student@server1 my_bestseller]$ cd plot_change


[student@server1 plot_change]$ cp mystery_chapter5.odf mystery_chapter5_$(date
+%F).odf
[student@server1 plot_change]$ cp mystery_chapter5.odf mystery_chapter5_$(date
+%s).odf
[student@server1 plot_change]$ cp mystery_chapter5.odf
mystery_chapter5_$USER.odf
[student@server1 plot_change]$ ls –l

16. The plot changes were not successful. Delete the plot_change directory. First,
delete all of the files in the plot_change directory. Change directory up one
level because the directory cannot be deleted while it is the working directory.
Try to delete the directory using the rm command without the recursive option.
This attempt should fail. Now use the rmdir command, which will succeed.

[student@server1 plot_change]$ rm mystery*


[student@server1 plot_change]$ cd ..
[student@server1 my_bestseller]$ rm plot_change
rm: cannot remove 'plot_change': Is a directory
[student@server1 my_bestseller]$ rmdir plot_change
[student@server1 my_bestseller]$ ls –l

12/28/2015 Copyright © 2015 Network Development Group, Inc. www.netdevgroup.com Page 16


2.9. Lab: Managing Files with Shell Expansion

17. When the vacation is over, the vacation directory is no longer needed. Delete it
using the rm command with the recursive option. When finished, return to the
home directory.

[student@server1 my_bestseller]$ rm –r vacation


[student@server1 my_bestseller]$ ls –l
[student@server1 my_bestseller]$ cd

18. Finish your session with the bash shell.

[student@server1 ~]$ exit

12/28/2015 Copyright © 2015 Network Development Group, Inc. www.netdevgroup.com Page 17

You might also like