Assignment 1 Working With Unix & Linux Solution

$30.00 $26.40

Description

Questions

Question 1: ssh and Basic Commands (12 Marks)

  1. Log in to the course server (cs2211b.gaul.csd.uwo.ca) using SSH as you would in the Lab. Give the full command you gave to log in (no output is required for this question).

  1. Issue a command to print the hostname of the server.

  1. Print a list of users currently logged into the server.

  1. Print the current date.

  1. Print the current working directory.

  1. Using your favourite editor, create a le named helloworld.txt in your home directory containing the text \Hello World! My name is [Your Name].” where \[Your Name]” is your real name (only give the command to open the editor/ le and not the output for this question).

  1. Without using an editor, give a command to display the contents of helloworld.txt assuming your working directory is your home directory. Use relative paths (give both the command and output).

  1. Without using an editor, give a command to display the contents of helloworld.txt that will work for any current working directory (give both the command and output).

  1. Make a directory called my text les in your home directory.

  1. Copy helloworld.txt into my text les and name it hello2.txt (in one command).

  1. With your home directory as your current directory, rename hello2.txt (in the my text les directory) to myhello.txt. Use only one command.

  1. Change your current working directory to my text les and delete myhello.txt (give both commands).

Question 2: List Command (10 Marks)

On the cs2211b server change your working directory to /usr/bin. This location stores the executable programs available to users on the server. Using only the ls command, display the following les names in /usr/bin. Make sure you show both the command and output for each of the following parts.

  1. Files whose names are exactly 5 characters long.

  1. Files that have g as the second letter.

  1. Files that start with z or q.

  1. Files that end with a number.

  1. Files that have a non-alpha character (not a letter) as the second last character (for example 9 , – or . would all be valid second last characters).

Question 3: Redirection (14 Marks)

Go to your home directory and create a text le called letter.txt. Write 15 lines in this le, where each line will have just a number from the list 01, 02, 03, …, 13, 14, 15 in this order.

Use the commands cat, tail or head for part B-F:

  1. Display the content of letter.txt.

  1. Display the last 5 lines of letter.txt

  1. Store the rst 4 lines of letter.txt in letter2.txt. Provide the command and the contents of letter2.txt.

  1. Use the sort command to reverse the contents of letter.txt and both store the result in letter3.txt and display it to the screen (Hint: Check the manual page for sort and tee). The command should not alter the contents of letter.txt in anyway.

  1. Explain the di erence between cat < letter.txt and cat letter.txt.

  1. Explain the di erence between echo cat and cat echo.

Question 4: Pipes (16 Marks)

Give a command for each of the following and show the output you received on the cs2211b server.

Each command should use a pipe. (Hint: Check the manual page for the wc command).

  1. Count the number of users currently on the server (it is ok to count users twice if they are logged in twice).

  1. Count the number of les in /usr/bin that contain the word \cat” anywhere in the name.

  1. Display the 7th to 11th lines (inclusively) of letter.txt from Question 3 using the head and tail commands and a pipe.

  1. Display to the screen and store in last10.txt the last 10 lines of .bash history (a le in your home directory) sorted and with duplicate lines removed (Hint: Check the manual page for sort). Provide the command and both your output and the contents of last10.txt.

Question 5: grep (18 Marks)

The le /usr/share/dict/words contains a list of dictionary words separated by new lines (one word per line). Use this le and the grep command nd/do the following:

  1. Count the number of words that do not contain the word mil anywhere in them (do not use the wc command).

  1. Count the number of words that end in ing (do not use the wc command).

  1. Display any word that contains 5 or more vowels in a row. The match should be case-insensitive (i.e. AAAAAA would match as would AeIou or eeeeeee).

  1. Display any word that starts with the letter z , ends with the letters ly and does not contain the letter f or t anywhere in the word.

  1. Display any word that starts and ends with the same two letters. For example, toronto, papa or eraser. You do not need to provide your output for this part.

Question 6: File Permissions (15 Marks)

On the cs2211b server, accomplish the following tasks and provide the commands you used and the output you received:

  1. Create a directory called Top1 in your home directory and setup its contents like so:

Under Top1, create a sub-directories Dir1 and a regular le File1. Under Dir1, create directories Dir3 and Dir4.

Under Dir3, create a regular le File3.

Under Dir4, create three regular les File4, File5 and File6. Under Top1 make Dir2 a symbolic link to Dir1/Dir4.

  1. Set the permissions on the directory Top1 such that all permissions are granted for the owner, and none are granted for others and group.

  1. Set the permissions on Dir1 such that the owner has all permissions and only read and execute for others and group.

  1. Dir3 should have all permissions set for the owner, read permission alone for group, and none for others.

  1. File1 should have read permission alone set for all.

  1. File5 should have execute permission alone set for others and group, and read and execute permission for the owner.

  1. Display the permissions of Top1 and no other les.

  1. Display the permissions of File4, File5 and File6 with one command.

Question 7: Terminology (15 Marks)

Using the proper terminology (e.g., command, option, option argument, and command argument), identify the constituent parts of the following UNIX commands (you do not need to explain what the command does, just identify the parts):

  1. man man

  1. wc -l my le.txt

  1. ls {all -l /usr/bin/*cat*

  1. grep -icv ?[aeio].* my le.txt

  1. nano -w -o /gaul/s1/student/1985/dservos5 my le.txt

Hint: It may be helpful to read the manual pages for these commands.

4 of 4