Starting from:
$35

$29

UNIX Commands & Pair Programming Solution

Objectives

    • Get familiarized with Linux environment

    • Learn an editor: vim/emac

    • Experience pair programming

    • Learn Unix Commands


Lab 1 Exercise – UNIX Step 1: - Find a partner

Buddy‐up to help get through the answers faster and experience pair programming. You will need to sit next to each other. If there ends up being an extra person, you can make a group of 3.

Step 2: - VM

Ensure you have the latest Virtual Machine from the CS department:

https://foundation.cs.colorado.edu/vm/

Open your VM and open a terminal window so we can play with UNIX!

Step 3: - Text Editors

Unix systems feature a lot of different text editors, such as pico, emacs and vim. Choose any of them and start the exercise.

Step 4: - UNIX Commands

In this section, we will be using UNIX commands to explore the directory Lab1, which can be downloaded from Moodle. Using any text editor, create a file called Lab1_Solutions.txt. Write all partners’ names at the top of the file and the unix commands used to carry out each of the below tasks.
Some useful commands you may need: grep, cd, mkdir, rm, find, head, tail, cp, zip, unzip, rmdir, cat, sort, uniq, less, touch. Feel free to use the man pages, trial and error (but be careful!), and your favorite search engine to complete this lab.

    1. Make a directory named cs3308

    2. Rename the directory cs3308 to CSCI3308_SectionNumber [write your recitation section number!] and enter the directory.

    3. Download Lab1 folder from Moodle and place it in the renamed directory. What command did you use to extract Lab1’s files?

    4. List the contents of the Lab1 directory. Are there any hidden files? What command did you use to display the hidden files?

    5. List the files in the images directory, sorted according to their size, listing one file per line. Which file is the biggest one and what command did you use to find this?

    6. Create a new directory called tinyData and copy both the smallest file from the images directory and the smallest file from the textFiles directory into it. How many bytes is this directory and what commands did you use?

    7. Use a unix command to create a zipped file called tinyData.zip that contains files currently in tinyData. How many bytes is this file?

    8. Use a unix command to create a tar file called tinyData.tar that contains the files currently in tinyData. How many bytes is this file?

    9. Delete the tinydata directory and the file tinyData.zip. What commands did you use?

    10. Extract the contents in the tar file tinyData.tar. What options did you use? What does each one do?

    11. What is the difference between little1.zip and little2.zip? Use the unzip command to find out.

    12. Use the find command to find the file called target.txt. What is its path from the Lab1 directory? What’s its full path on your machine?

    13. Finally, use the commands head and tail to create a new short story made up of the first five lines of one of the books in the texts directory and the last 5 lines of a different book in the texts directory. Output your new short story into a text file named MyShortStory (placed inside the textFiles directory). Write down the commands that you used.
Step 5: - Fancy UNIX commands

For the next set of questions, make a copy of file /etc/passwd into the Lab1 directory with the name password_demo.txt

Source: http://www.cyberciti.biz/faq/understanding-etcpasswd-file-format/ Understanding fields in /etc/passwd file

The /etc/passwd file contains one entry per line for each user (or user account) of the system. All fields are separated by a colon (:) symbol. Total seven fields as follows:







    1. Username: It is used when user logs in. It should be between 1 and 32 characters in length.

    2. Password: An x character indicates that encrypted password is stored in /etc/shadow file

    3. User ID (UID): Each user must be assigned a user ID (UID). UID 0 (zero) is reserved for root and UIDs 1- 99 are reserved for other predefined accounts. Further UID 100-999 are reserved by system for administrative and system accounts/groups.

    4. Group ID (GID): The primary group ID (stored in /etc/group file)

    5. User ID Info: The comment field. It allows you to add extra information about the users such as user’s full name, phone number etc., This field is used by the finger command.
    6. Home directory: The absolute path to the directory. If this directory does not exist, then users’ directory becomes /

    7. Command/shell: The absolute path of a command or shell (/bin/bash). Typically, this is a shell.


Using password_demo.txt file content as input, please figure out the commands that do the below tasks. Some useful commands you may need: grep, sort, chmod

    1) Sort the file based on the username(first field)

    2) Sort the file based on GroupID. Since it is a number, be sure to specify that it is a number so it sorts the numbers correctly.

    3) Show all the lines in the file with the name system in it

    4) Get the number of words in the file using a Unix command

    5) Print only those lines in the file with a unique UserID

    6) Use your command for the previous question and now redirect the output to a file named tmp. Use the > operator

    7) Write the unix command used to find the number of lines in question 6 to a script file named getUniqueGID.sh
What is the command to run this script file? Did you encounter “permission denied” error? Change the permissions of the file to allow users to execute the file. What is the command used to changed file access permissions? Did the script run this time?




Credit: To get credit for this lab exercise, get your Lab1_Solutions.txt file checked with your TA or submit the file on Moodle. All partners should submit copies of the same file. Also make sure to submit a zipped version of your Lab1 directory.

More products