Solved-Assignment 1- Working With Unix & Linux- Solution

$35.00 $24.00

Questions Question 1: ssh and Basic Commands (12 Marks) (a) 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). (b) Issue a command to print the hostname of the server. (c) Print a…

You’ll get a: . zip file solution

 

 
Categorys:

Description

5/5 – (2 votes)

Questions

Question 1: ssh and Basic Commands (12 Marks)

(a) 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).

(b) Issue a command to print the hostname of the server.

(c) Print a list of users currently logged into the server.

(d) Print the current date.

(e) Print the current working directory.

(f) 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).

(g) 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).

(h) 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).

(i) Make a directory called my text les in your home directory.

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

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

(l) 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.

(a) Files whose names are exactly 5 characters long.

(b) Files that have g as the second letter.

(c) Files that start with z or q.

(d) Files that end with a number.

(e) 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:

(a) Display the content of letter.txt.

(b) Display the last 5 lines of letter.txt

(c) Store the rst 4 lines of letter.txt in letter2.txt. Provide the command and the contents of letter2.txt.

(d) 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.

(e) Explain the di erence between cat < letter.txt and cat letter.txt.

(f) 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).

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

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

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

(d) 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:

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

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

(c) 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).

(d) 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.

(e) 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:

(a) 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.

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

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

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

(e) File1 should have read permission alone set for all.

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

(g) Display the permissions of Top1 and no other les.

(h) 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):

(a) man man

(b) wc -l my le.txt

(c) ls {all -l /usr/bin/*cat*

(d) grep -icv ?[aeio].* my le.txt

(e) 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