Lab 7C: Using the BASH Shell

Lab 7C: Using the BASH Shell

LINUX+ LAB SERIES (LX0-101) Lab 7c: Using the BASH Shell Document Version: 2013-09-19 Copyright © National Information Security, Geospatial Technologies Consortium (NISGTC) The development of this document is funded by the Department of Labor (DOL) Trade Adjustment Assistance Community College and Career Training (TAACCCT) Grant No. TC-22525-11-60-A-48; The National Information Security, Geospatial Technologies Consortium (NISGTC) is an entity of Collin College of Texas, Bellevue College of Washington, Bunker Hill Community College of Massachusetts, Del Mar College of Texas, Moraine Valley Community College of Illinois, Rio Salado College of Arizona, and Salt Lake Community College of Utah. This work is licensed under the Creative Commons Attribution 3.0 Unported License. To view a copy of this license, visit http://creativecommons.org/licenses/by/3.0/ or send a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA. The Center for Systems Security and Information Assurance (CSSIA), in partnership with the Network Development Group (NDG) is given a perpetual worldwide waiver to distribute per US Law this lab and future derivatives of these works. Linux+ Lab Series (LX0-101) Lab 7c: Using the BASH Shell Contents Introduction ........................................................................................................................ 2 Objective ............................................................................................................................. 2 Linux+ LX0-101 Exam Objectives ........................................................................................ 3 Lab Topology ....................................................................................................................... 4 Lab Settings ......................................................................................................................... 5 1 Using gunzip, bzip2, tar, dd, and cpio ......................................................................... 6 9/19/2013 Copyright © 2013 NISGTC Page 1 of 14 Linux+ Lab Series (LX0-101) Lab 7c: Using the BASH Shell Introduction This lab provides guidance on performing Lab 7c: Using the BASH Shell of the Linux+ LX0-101 course, using a NETLAB+ system. By performing this lab, students will learn how to execute various archiving and compression commands. Objective In this lab, you will perform the following tasks: 1. Create archive files using tar, cpio and dd 2. Compress and uncompress files using gzip, gunzip and bzip2 9/19/2013 Copyright © 2013 NISGTC Page 2 of 14 Linux+ Lab Series (LX0-101) Lab 7c: Using the BASH Shell Linux+ LX0-101 Exam Objectives This lab will cover the topics for the following LX0-101 objectives that are listed in bold italics (the remaining topics will be covered in other labs): 103.3 Perform basic file management 1. Copy, move, and remove files and directories individually. 2. Copy multiple files and directories recursively. 3. Remove files and directories recursively. 4. Use simple and advanced wildcard specifications in commands. 5. Using find and locate and act on files based on type, size, or time. 6. Usage of tar, cpio and dd. The following is a partial list of the used files, terms, and utilities: a. cp b. find c. mkdir d. mv e. ls f. rm g. rmdir h. touch i. tar j. cpio k. dd l. file m. gzip n. gunzip o. bzip2 p. file globbing 9/19/2013 Copyright © 2013 NISGTC Page 3 of 14 Linux+ Lab Series (LX0-101) Lab 7c: Using the BASH Shell Lab Topology 9/19/2013 Copyright © 2013 NISGTC Page 4 of 14 Linux+ Lab Series (LX0-101) Lab 7c: Using the BASH Shell Lab Settings The information in the table below will be used to complete the lab. Additional details will be provided within the task sections as required. System Username/Password CentOS Server sysadmin/netlab123 Ubuntu Server sysadmin/netlab123 Fedora Workstation sysadmin/netlab123 Ubuntu Workstation sysadmin/netlab123 All Machines root/netlab123 9/19/2013 Copyright © 2013 NISGTC Page 5 of 14 Linux+ Lab Series (LX0-101) Lab 7c: Using the BASH Shell 1 Using gunzip, bzip2, tar, dd, and cpio In this task, we will use gzip, bzip2, tar and cpio to archive and restore data. 1. Click on the Fedora Workstation icon in the pod topology to launch the virtual machine. 2. The virtual machine will display a login screen. Make sure sysadmin is in the user field. Enter the password netlab123 and press Enter. 9/19/2013 Copyright © 2013 NISGTC Page 6 of 14 Linux+ Lab Series (LX0-101) Lab 7c: Using the BASH Shell 3. Once you have logged in, a terminal window may appear. If it does not, click on the Kickoff Application Launcher, the “f”, in the lower- left corner of the desktop. In the search bar, type konsole and click on Konsole, which will launch a terminal window: 9/19/2013 Copyright © 2013 NISGTC Page 7 of 14 Linux+ Lab Series (LX0-101) Lab 7c: Using the BASH Shell 4. The next few commands you will run in this lab require superuser rights. Use the su command to switch to the root account. If prompted for a password, type netlab123. su - root Your output should be similar to the following: 5. Use tar to create an archive of the /etc/dhcp directory. Save the backup in the ~/mybackups directory. (tar options, c = create, v = verbose, f = filename of archive) cd mkdir mybackups tar –cvf mybackups/dhcp.tar /etc/dhcp Your output should be similar to the following: 9/19/2013 Copyright © 2013 NISGTC Page 8 of 14 Linux+ Lab Series (LX0-101) Lab 7c: Using the BASH Shell 6. Display the contents of a tar file. (t = list contents, v = verbose, f = filename). tar –tvf mybackups/dhcp.tar Your output should be similar to the following: Notice that files are backed up recursively using relative path names. 7. Create a tar file that is compressed using gzip (z = compress using gzip). tar –zcvf mybackups/dhcp2.tar.gz * ls –lh mybackups Your output should be similar to the following: Notice the difference in size; first backup (10 Kbytes) is larger than the second backup (2.5 Kbytes). 9/19/2013 Copyright © 2013 NISGTC Page 9 of 14 Linux+ Lab Series (LX0-101) Lab 7c: Using the BASH Shell 8. Extract the contents of an archive. Data is restored to the current directory by default. cd mybackups tar –xvf dhcp.tar ls ls etc ls etc/dhcp Your output should be similar to the following: 9. Add a file to an existing archive (-r = append to the end of an archive) then use tar to display the contents of the tar file. tar -rvf dhcp.tar /etc/hosts tar –tvf dhcp.tar Your output should be similar to the following: 9/19/2013 Copyright © 2013 NISGTC Page 10 of 14 Linux+ Lab Series (LX0-101) Lab 7c: Using the BASH Shell 10. Use gzip and gunzip to compress and uncompress a file. The compressed file is created with a .gz extension. The extension is removed when uncompressed. Execute the following commands to compress a copy of the linux.words file: cp /usr/share/dict/linux.words . ls -l linux.words gzip linux.words ls -l linux.words.gz Your output should be similar to the following: 11. Execute the following commands to uncompress the linux.words.gz file: ls -l linux.words.gz gunzip linux.word.gz ls -l linux.words Your output should be similar to the following: Linux provides a large number of compression utilities in addition to gzip/gunzip. Each of them have pros and cons (faster compression, better compression rates, more flexible, more portable, faster decompression, etc.). The gzip/gunzip commands are very popular in Linux, but you should be aware that bzip2/bunzip2 are also popular on some Linux distributions. The nice thing is that most of the functionality (the way you run the commands) and options are the same as gzip/gunzip. 9/19/2013 Copyright © 2013 NISGTC Page 11 of 14 Linux+ Lab Series (LX0-101) Lab 7c: Using the BASH Shell 12. Use cpio to create an archive of the specified files. As you will see in the examples below, cpio has some features not found with the tar command. Use the -O option (upper case letter O) to specify the destination. Common cpio options: v = verbose, o = create a new archive, B = set block size to 5120 bytes (for faster transfers). The | command will send the output of the command before it, to the command after it. cd ~/mybackups find /etc -name "*.conf" | cpio -voB -O conf.cpio Your output should be similar to the following: 13. Display files in a cpio archive. cpio –it –F conf.cpio | head Your output should be similar to the following: 9/19/2013 Copyright © 2013 NISGTC Page 12 of 14 Linux+ Lab Series (LX0-101) Lab 7c: Using the BASH Shell 14. Try to extract files from a cpio archive. Note that success is not expected (options, i = read from archive, d = create directories as needed, v=verbose, F = archive filename). cpio –idv –F conf.cpio Your output should be similar to the following: Notice that cpio uses the absolute path when archiving files. Thus, upon extraction, it will restore to the original location from where the file(s) was archived. If the original file exists, and it is of the “same age” or newer, the file(s) being extracted will not be restored so as not to overwrite existing or current data. 15. Delete existing file and restore it from a cpio archive. rm /etc/xdg/user-dirs.conf cat conf.cpio | cpio -idv /etc/xdg/user-dirs.conf ls /etc/xdg/user-dirs.conf Your output should be similar to the following: 9/19/2013 Copyright © 2013 NISGTC Page 13 of 14 Linux+ Lab Series (LX0-101) Lab 7c: Using the BASH Shell 16. The dd command is typically used to create a "raw" copy of an entire device, for instance a partition, an entire hard drive or a USB thumb drive. In the first example, we want to generate an ISO image from the contents of a CDROM.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    15 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us