Recent Question/Assignment

Project 3-4
In this hands-on project, you display file contents using the cat, tac, head, tail, strings, and od commands.
1. Switch to a command-line terminal (tty5) by pressing Ctrl1Alt1F5, and then log in to the terminal using the user name of root and the your Linux password.
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. 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. At the command prompt, type cat /etc/inittab and press Enter.
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. 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. 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. 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. 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. At the command prompt, type strings /bin/nice and press Enter. Notice that you can 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. 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. Switch to a command-line terminal (tty5) by pressing Ctrl1Alt1F5 and log in to the terminal using the user name of root and the password.
2. At the command prompt, type grep “Inn” sample1 and press Enter. What is displayed and why?
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. At the command prompt, type grep “inn” sample1 and press Enter. What is displayed and why?
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. At the command prompt, type grep “I” sample1 and press Enter. What is displayed and why?
7. At the command prompt, type grep “ I ” sample1 and press Enter. What is displayed and why?
8. At the command prompt, type grep “t.e” sample1 and press Enter. What is displayed and why?
9. At the command prompt, type grep “w...e” sample1 and press Enter. What is displayed and why?
10. At the command prompt, type grep “^I” sample1 and press Enter. What is displayed and why?
11. At the command prompt, type grep “^I ” sample1 and press Enter. What is displayed and why?
12. At the command prompt, type grep “(we|next)” sample1 and press Enter. What is displayed? Why?
13. At the command prompt, type egrep “(we|next)” sample1 and press Enter. What is displayed and why?
14. At the command prompt, type grep “Inn$” sample1 and press Enter. What is displayed and why?
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. 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. Type exit and press Enter to log out of your shell.
Project 4-5
In this hands-on project, you find files on the filesystem using the find, locate, which, type, and whereis commands.
1. Switch to a command-line terminal (tty5) by pressing Ctrl1Alt1F5 and log in to the terminal using the user name of root and the password
2. At the command prompt, type touch newfile and press Enter. Next, type locate newfile at the command prompt and press Enter. Did the locate command find the file you just created? Why?
3. At the command prompt, type updatedb and press Enter. When the command is finished, type locate newfile at the command prompt and press Enter. Did the locate command find the file? If so, how quickly did it find it? Why?
4. At the command prompt, type find / -name -newfile- and press Enter. Did the find command find the file? If so, how quickly did it find it? Why?
5. At the command prompt, type find /root -name -newfile- and press Enter. Did the find command find the file? How quickly did it find it? Why?
6. At the command prompt, type which newfile and press Enter. Did the which command find the file? Why? Type echo $PATH at the command prompt and press Enter. Is the /root directory listed in the PATH variable? Is the /usr/bin directory listed in the PATH variable?
7. At the command prompt, type which grep and press Enter. Did the which command find the file? Why?
8. At the command prompt, type type grep and press Enter. Next, type whereis grep and press Enter. Do these commands return less or more than the which command did
1. in the previous step? Why?
9. At the command prompt, type find /root –name -sample- and press Enter. What files are listed? Why?
10. At the command prompt, type find /root –type l and press Enter. What files are listed? Why?
11. At the command prompt, type find /root –size 0 and press Enter. What types of files are listed? Type find / –size 0 | more to see all of the files of this type on the system.
12. Type exit and press Enter to log out of your shell.
Project 4-7
In this hands-on project, you apply and modify access permissions on files and directories and test their effects.
1. Switch to a command-line terminal (tty5) by pressing Ctrl1Alt1F5 and log in to the terminal using the user name of root and the password.
2. At the command prompt, type touch permsample and press Enter. Next, type chmod 777 permsample at the command prompt and press Enter.
3. At the command prompt, type ls -l and press Enter. Who has permissions to this file?
4. At the command prompt, type chmod 000 permsample and press Enter. Next, type ls –l at the command prompt and press Enter. Who has permissions to this file?
5. At the command prompt, type rm –f permsample and press Enter. Were you able to delete this file? Why?
6. At the command prompt, type cd / and press Enter. Next, type pwd at the command prompt and press Enter. What directory are you in? Type ls –F at the command prompt and press Enter. What directories do you see?
7. At the command prompt, type ls –l and press Enter to view the owner, group owner, and permissions on the foruser1 directory created in Hands-On Project 4-1. Who is the owner and group owner? If you were logged in as the user user1, in which category would you be placed (user, group, other)? What permissions do you have as this category (read, write, execute)?
8. At the command prompt, type cd /foruser1 and press Enter to enter the foruser1 directory. Next, type ls -F at the command prompt and press Enter. Are there any files in this directory? Type cp /etc/hosts . at the command prompt and press Enter. Next, type ls -F at the command prompt and press Enter to ensure that a copy of the hosts file was made in your current directory.
9. Switch to a different command-line terminal (tty3) by pressing Ctrl1Alt1F3 and log in to the terminal using the user name of user1 and the password of LINUXrocks!.
10. At the command prompt, type cd /foruser1 and press Enter. Were you successful? Why? Next, type ls -F at the command prompt and press Enter. Were you able to see the contents of the directory? Why? Next, type rm –f hosts at the command prompt and press Enter. What error message did you see? Why?
11. Switch back to your previous command-line terminal (tty5) by pressing Ctrl1Alt1F5. Note that you are logged in as the root user on this terminal and within the /foruser1 directory.
12. At the command prompt, type chmod o+w /foruser1 and press Enter. Were you able to change the permissions on the /foruser1 directory successfully? Why?
13. Switch back to your previous command-line terminal (tty3) by pressing Ctrl1Alt1F3. Note that you are logged in as the user1 user on this terminal and within the /foruser1 directory.
14. At the command prompt, type rm –f hosts at the command prompt and press Enter. Were you successful now? Why?
15. Switch back to your previous command-line terminal (tty5) by pressing Ctrl1Alt1F5.
Note that you are logged in as the root user on this terminal.
16. At the command prompt, type cp /etc/hosts . at the command prompt and press Enter to place another copy of the hosts file in your current directory (/foruser1).
17. At the command prompt, type ls –l and press Enter. Who is the owner and group owner of this file? If you were logged in as the user user1, in which category would you be placed (user, group, other)? What permissions do you have as this category (read,
18. write, execute)?
19. Switch back to your previous command-line terminal (tty3) by pressing Ctrl1Alt1F3. Note that you are logged in as the user1 user on this terminal and in the /foruser1 directory.
20. At the command prompt, type cat hosts at the command prompt and press Enter. Were you successful? Why? Next, type vi hosts at the command prompt to open the hosts file in the vi editor. Delete the first line of this file and save your changes. Were you successful? Why? Exit the vi editor and discard your changes.
21. Switch back to your previous command-line terminal (tty5) by pressing Ctrl1Alt1F5.
Note that you are logged in as the root user on this terminal and in the /foruser1 directory.
22. At the command prompt, type chmod o+w hosts and press Enter.
23. Switch back to your previous command-line terminal (tty3) by pressing Ctrl1Alt1F3. Note that you are logged in as the user1 user on this terminal and in the /foruser1 directory.
24. At the command prompt, type vi hosts at the command prompt to open the hosts file in the vi editor. Delete the first line of this file and save your changes. Why were you successful this time? Exit the vi editor.
25. At the command prompt, type ls -l and press Enter. Do you have permission to execute the hosts file? Should you make this file executable? Why? Next, type ls –l /usr/bin at the command prompt and press Enter. Note how many of these files to which you have execute permission. Type file /usr/bin/* | more at the command prompt and press Enter to view the file types of the files in the /bin directory. Should these files have the execute permission?
26. Type exit and press Enter to log out of your shell.
27. Switch back to your previous command-line terminal (tty5) by pressing Ctrl1Alt1F5.
Note that you are logged in as the root user on this terminal.
28. Type exit and press Enter to log out of your shell.
Project 5-4
In this hands-on project, you create two new partitions using the GNU Parted utility, and configure the LVM to host an LV using the space within. During this process, you will learn how to create PVs, VGs, and LVs, as well as add storage to extend a VG and LV. Finally, you will edit the /etc/fstab file to ensure that your LV is mounted at boot time.
In this hands-on project you may need to create extended partitions in additional hard disk. For example you can add additional had disk /dev/sdb, and partition it to get /dev/sdb5 /dev/sdb4, and /dev/sdb6.
1. Switch to a command-line terminal (tty5) by pressing Ctrl1Alt1F5 and log in to the terminal using the user name of root and the password.
2. At the command prompt, type parted /dev/sda and press Enter. At the parted prompt, type help and press Enter to view the available commands.
3. At the parted prompt, type print and press Enter. Write down the End value for your first logical drive (/dev/sda5): _________ (A). Next, write down the End value for your extended partition (/dev/sda4): _________ (B). These two values represent the start and end of the remainder of the free space on your virtual hard disk.
4. At the parted prompt, type mkpart and press Enter to accept the default of logical drive. Press Enter again to accept the default partition type (Linux ext2). When prompted for the Start of the new partition, enter the (A) value you recorded in Step 3 and press Enter. When prompted for the End of the new partition, enter the (A) value you recorded in Step 3 plus 1GB and press Enter to create a 1GB partition.
5. At the parted prompt, type p and press Enter to view the partition table on your hard disk. What type of partition is /dev/sda6? Write down the End value for your second logical drive (/dev/sda6): _________ (C).
6. At the parted prompt, type mkpart and press Enter to accept the default of logical drive. Press Enter again to accept the default partition type (Linux ext2). When prompted for the Start of the new partition, enter the (C) value you recorded in Step 5 and press Enter. When prompted for the End of the new partition, enter the (C) value you recorded in Step 5 plus 1GB and press Enter to create another 1GB partition.
7. At the parted prompt, type quit and press Enter to save the changes to the hard disk and exit the GNU Parted utility.
8. At the command prompt, type reboot and press Enter to reboot your machine and ensure that the partition table was read into memory correctly. After your Linux system has been loaded, switch to a command-line terminal (tty5) by pressing Ctrl1Alt1F5 and log in to the terminal using the user name of root and the password.
9. At the command prompt, type pvcreate /dev/sda6 and press Enter. Next, type pvscan and press Enter to verify the creation of your PV. Following this, type pvdisplay and press Enter to view the PE size chosen as well as the total size of the PV.
10. At the command prompt, type vgcreate vg00 /dev/sda6 and press Enter. Next, type vgscan and press Enter to verify the creation of your vg00 VG. Following this, type vgdisplay and press Enter to view the PE size chosen as well as the total size of your VG.
11. At the command prompt, type lvcreate –L 0.9GB –n newdata vg00 and press Enter to create a 0.9GB LV called newdata from the vg00 VG. Why couldn’t you specify a 1GB size for your LV? Next, type lvscan and press Enter to verify the creation of your LV. Following this, type lvdisplay and press Enter to view the path to the LV device file as well as the total size of your LV.
12. At the command prompt, type mkfs –t ext4 /dev/vg00/newdata and press Enter to format the newdata LV using the ext4 filesystem. Next, type mkdir /newdata and press Enter to create a mount point for the newdata LV. Following this, type mount
/dev/vg00/newdata /newdata and press Enter to mount the newdata LV to the /newdata directory.
13. At the command prompt, type df -hT and press Enter to verify that your LV is mounted via the device mapper. Next, type ls -l /dev/vg00/newdata and press Enter, noting it is a symbolic link to a device mapper device file. Following this, type lsblk and press Enter to note the relationship between your LV and your PV (/dev/sda6).
14. At the command prompt, type ls –F /newdata and press Enter. Is there a lost1found directory available? Why?
15. At the command prompt, type pvcreate /dev/sda7 and press Enter. Next, type pvscan and press Enter to verify the creation of your PV. Following this, type pvdisplay and press Enter to view the PE size chosen as well as the total size of the PV.
16. At the command prompt, type vgextend vg00 /dev/sda7 and press Enter. Next, type vgdisplay and press Enter to view the PE size chosen as well as note that the total size of your VG reflects both PVs.
17. At the command prompt, type lvextend –L +0.9GB -r /dev/vg00/newdata and press
Enter to extend your newdata LV by another 0.9GB. Next, type lvdisplay and press Enter, noting the size has doubled. Following this, type df -hT and press Enter, noting the ext4 filesystem was automatically resized to match the new LV capacity.
18. At the command prompt, type lsblk and press Enter to note the relationship between your LV and your two PVs (/dev/sda6 and /dev/sda7).
19. At the command prompt, type vi /etc/fstab and press Enter. Add the following line to the bottom of the file to ensure that the newdata LV is mounted at boot time:
/dev/vg00/newdata /newdata ext4 defaults 0 0
20. Save your changes and quit the vi editor.
21. At the command prompt, type reboot and press Enter. After your Linux system has been loaded, switch to a command-line terminal (tty5) by pressing Ctrl1Alt1F5 and log in to the terminal using the user name of root and the password.
22. At the command prompt, type df -hT and press Enter to verify that your LV was automatically mounted at boot time.
23. Type exit and press Enter to log out of your shell.