Linux Lab #2

Due Wednesday, May 25

Use the script command to make a log of your activities. The log should be named Lab2.HOSTNAME.DATE where HOSTNAME is your hostname fetched from an environment variable, and DATE is the current date and time in the format MMDDYY_HHMM (24hr time) fetched with inline command execution. (E.g. "Lab2.LINFORD3040.052305_1830")

In answering direct questions below (as marked by the question-mark '?'), use a shell comment to give your answer. For example, if I say: "What is the command to give you the system time?" You should type, at the command prompt, "# date is the command" or something to that effect. The important part is the hash-mark '#' which causes the shell to ignore everything behind it.

Basic Unix Commands (38pts)

  1. Show the present working directory
  2. Show the current user's session information in long format
  3. Show the current user's group membership
  4. Show the current user's PATH
  5. List the contents of /boot in long format in three ways:
    1. Calling ls with an absolute path
    2. Calling ls with a relative path
    3. Changing directory to /boot and calling ls
  6. Make a directory in the current user's home directory called lab2
  7. Make two files in the lab2 directory: test and .test
  8. Make a directory in the lab2 directory named sub1
  9. Change the permissions on test so only the owner can read and write the file and the file is not executable
  10. Change the permissions on .test so the file is globally readable, write-protected, and globally executable
  11. List all processes for the current user and store the results into test
  12. Use head to show the first line in test
  13. Use tail to show the last line in test
  14. Use cat to show the contents of test
  15. Change to the current user's home directory
  16. Use find to recursively list the lab2 directory
  17. Use ls to recursively list the lab2 directory
  18. Use rmdir to delete the sub1 directory
  19. Use rm to delete the lab2 directory recursively

Users / Groups, File Permissions, Access Control Lists (ACLs) (46pts)

  1. Become root
  2. Use useradd to create a user named chef with the following attributes:
  3. Use passwd to set a password for chef
  4. Use groupadd to create two groups: fourthgrade and diesdaily
  5. Edit the group file to add stan, kyle, kenny, cartman, and chef to the fourthgrade group and kenny to the diesdaily group. DO NOT use an editor on the terminal running the 'script' command. This will damage your log file. Open a second terminal and edit from there.
  6. Create a directory in / named secret
  7. Use chown to change the user and group of /secret to be kenny:diesdaily
  8. Change the permissions on /secret so only 'user' can read, write, or execute in that directory
  9. Change users to cartman. Try to create a file named /secret/kennysucks. What happens?
  10. Log out of cartman (you will be root again).
  11. Use getfacl to list the ACL of /secret
  12. Use setfacl to add cartman as a user on /secret with read, write, and execute permissions
  13. Change users to cartman. Try to create a file named /secret/kennysucks. What happens?
  14. Log out of cartman (you will be root again).
  15. List the file permissions on /secret. If you didn't know that cartman is in the ACL, could you tell that he can create files in /secret?
  16. List the ACL of /secret
  17. Use setfacl to remove cartman from the ACL of /secret
  18. List the ACL of /secret
  19. Use groups to show kenny's groups
  20. Use groupdel to remove the group diesdaily
  21. Show kenny's groups
  22. Use userdel to delete chef and his home directory
  23. Use grep to show users in group fourthgrade

Unix Filesystems (22pts)

  1. Use mount to show all mounted filesystems
  2. Use df to show free space on all filesystems in human-readable format
  3. Use umount to unmount /home
  4. Use fsck to check the device where /home is stored for errors
  5. List mounted devices into /home/hidden_on_mount. Which /dev/hda device is this file stored on?
  6. Use mount to mount /home. What happened to /home/hidden_on_mount?
  7. Unmount /home. Is /home/hidden_on_mount still there?
  8. Mount the device where /home is stored on /mnt
  9. List the files in /mnt. Has anything "really" changed?
  10. Unmount /mnt
  11. Mount /home

Virtual Memory (28pts)

  1. Become root
  2. Use free to show free memory in megabytes
  3. Use swapoff to deactivate the swap partition.
  4. List mounted partitions. Is swap mounted?
  5. Use dd to create a file named /swapfile with size of 50MB filled with zeros
  6. Use mkswap to format the new file for swap
  7. Make the user and group of /swapfile to both be root
  8. Make the file permissions of /swapfile to be 0600
  9. Use swapon to mount /swapfile as virtual memory
  10. Show free memory in megabytes.
  11. List mounted partitions. Why doesn't /swapfile show up?
  12. Deactivate the new swapfile
  13. Remove /swapfile
  14. Activate the swap partition

When finished, type exit or press ^D until you get a message like "Script done, file is Lab2.HOSTNAME.DATE". To turn in the assignment, scp the logfile to 192.168.0.100:/public_3040 as user "cs3040" and password "cs3040"