Starting from:
$35

$29

Assignment 1 Working With Unix & Linux Solution

Questions




Question 1: ssh and Basic Commands (12 Marks)




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



Issue a command to print the hostname of the server.



Print a list of users currently logged into the server.



Print the current date.



Print the current working directory.



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



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



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



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



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



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



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.




Files whose names are exactly 5 characters long.



Files that have g as the second letter.



Files that start with z or q.



Files that end with a number.



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:




Display the content of letter.txt.



Display the last 5 lines of letter.txt



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



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.



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



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




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



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



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



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:




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



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



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



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.



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:




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.




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



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



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



File1 should have read permission alone set for all.



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



Display the permissions of Top1 and no other les.



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




man man



wc -l my le.txt



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



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



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

More products