0% found this document useful (0 votes)
13 views14 pages

Assignment 5 Week5

This document outlines Assignment 5 for a Linux course at Algonquin College, consisting of multiple tasks related to Linux commands and file management. Students are required to complete tasks involving path name expansion, output redirection, permission analysis, and SSH break-in attempts, with specific instructions for documentation and demonstration to lab professors. The assignment emphasizes practical application of Linux commands and understanding of file permissions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views14 pages

Assignment 5 Week5

This document outlines Assignment 5 for a Linux course at Algonquin College, consisting of multiple tasks related to Linux commands and file management. Students are required to complete tasks involving path name expansion, output redirection, permission analysis, and SSH break-in attempts, with specific instructions for documentation and demonstration to lab professors. The assignment emphasizes practical application of Linux commands and understanding of file permissions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

lOMoARcPSD|53663770

Assignment 5 Week5

Linux (Algonquin College)

Scan to open on Studocu

Studocu is not sponsored or endorsed by any college or university


Downloaded by Sachita Ghoora ([email protected])
lOMoARcPSD|53663770

S23_CST8207_Linux System Support Algonquin College

Week 5 – Assignment 5

Deliverables
 This lab assignment is divided into 5 tasks.
 Use the same document to answer question and add screenshots.
 After completing all 5 tasks show this document to your lab professors
for grading.
 Demo your work to your lab professor during lab class for grades.
(No submission will be accepted, student must demo during lab class ).
Note: All Linux Commands are with small letters!

Assignment’s TASKS:

For Task 1 to 5 (Total 15 points, you lose 1 point for each


mistake)

Task 1
Part1
Path name expansion (Globbing)
The useful command is echo to see how patterns expand first, before you use them
in a real command line, for example try to expand the pattern using echo command.

Try this

$ echo ~/Week*

$ echo /dev/sd*
$ echo /bin/*sh

Explain what you observe

Downloaded by Sachita Ghoora ([email protected])


lOMoARcPSD|53663770

S23_CST8207_Linux System Support Algonquin College

The * is a meta character that will allow the system to look into all
the possible pathnames. The last command will be looking for all
the possible pathnames that end with the letters “sh”

Part2

Create Assignment5 directory under your Assignments directory (that you created
in the Week4 assignment)

Under Assignment5 create the below file structure (Blue – directory)


(Green – file)

Screen shot here

Downloaded by Sachita Ghoora ([email protected])


lOMoARcPSD|53663770

S23_CST8207_Linux System Support Algonquin College

Use the echo command to see how patterns expand first,


before you use them in a real command line.
$ cp f? dir1

a. Which files have been copied to the directory dir1? (First try to answer without
typing the command.)
Ans-
F1, f2, and f3 are the files that was copied to the directory dir1
$ cp f?0 dir2

b. Which files have been copied to the directory dir2? (First try to answer without
typing the command.)
Ans-
F10,f20, and f30 are copied to dir2
$ cp f?3 dir3

c. Which files have been copied to the directory dir3? (First try to answer without
typing the command.)
Ans-
F13 and f33 are copied to dir3

$ cp ?? ????? dir3

Downloaded by Sachita Ghoora ([email protected])


lOMoARcPSD|53663770

S23_CST8207_Linux System Support Algonquin College

d. Why does the above command line give an error message from the copy
command?

Ans-

In the first part “??”, the shell will attempt to copy files that have a 2 character
filename. We don’t have any filename with 2 characters.

$ ls /dev/tty*

e. The above command shows all terminal devices configured in your Linux system.
Using this method type a command to show only terminal device names with 4
characters
i.e. shows tty1 and tty6 and tty9, etc. but does not show tty or tty12 or tty60
etc.?

Ans-

Part3
Using * to match zero or more characters

Go to the Assignment5 directory and execute below commands.

$ mkdir lab5.2 ; cd lab5.2

1) Copy all the contents of lab5 into lab5.2. being in lab5.2 directory, do as follows:

$ ls (take screen shot of output of ls command and paste here)

Screen shot of command line

Downloaded by Sachita Ghoora ([email protected])


lOMoARcPSD|53663770

S23_CST8207_Linux System Support Algonquin College

2) What is the output of the below command (First try to answer without typing the
command.)

$ ls f*
$ ls -d d*
Explain why the output of above commands are the way they are?
Ans:-
First command: list all the files or directories that start with the letter f.
Second command: list all the directories (only directories) that start with the letter
d.
3) Explain what would be the output of the below commands without using the shell
terminal?
$ ls dir?/*
It will list all the possible directories that have 1 character after dir (dir1, dir2, and
dir3) and all possible paths inside of it.

Part4
Using [ ] to match a single character from a list of characters

Square brackets are shell meta-characters that indicate a GLOB pattern match for
any one character in the list of characters between the square brackets. You can
also match any one character that is not in the list by starting the list with an
exclamation point !, e.g. [!abc] or [^abc]

Go to Assignment5 directory and create below file structure (Blue – directory)


(Green – file)

Downloaded by Sachita Ghoora ([email protected])


lOMoARcPSD|53663770

S23_CST8207_Linux System Support Algonquin College

What is the output of below commands? (First try to answer without typing the
command.)

$ ls h[ao]t hat - hot


$ ls h[aeiou]t hat – hit – hot - hut
$ ls h[aeiou]* hat-help-hit-hot-hut
$ ls sda[1-4] sda1
$ echo sd[!ab][!12] sdc3-sdd4

Task 2
Redirecting output:
cat /etc/passwd and redirect the output to file dump.txt located under your
Assignemnt5 directory.

Screenshot of command line

Now try this:


$ ls /home/user1 and redirect the output to file dump.txt located under
Assignment5 directory

$ cat dump.txt

The previous content of dump.txt is gone explain why


The above command gave an error “ no such file or directory “ referring to the
“user1” name.

When using output redirection, the file dump.txt will be truncated


to be prepared for the command output, in this case it was
truncated but the command failed.

How to append two files using >> (append)


$ ls /etc/passwd >> dump.txt
$ cat dump.txt
The previous content of dump.txt is NOT gone!

Downloaded by Sachita Ghoora ([email protected])


lOMoARcPSD|53663770

S23_CST8207_Linux System Support Algonquin College

Explain the difference between “>” and “>>”


“>” is an output redirection, and it created a file if needed to redirect the output.
“>>” it is also an output redirection but it write adding more information on an
existing file instead of creating a new one or truncating a file.

B) Redirecting Errors:
In Assignments directory of user1 home directory, try the following commands:

$ ls W5 Assignment5

1. Observe the output we have one error message.


2. Now create a command line to just redirect the error message to file dirlist
under your Assignment5 directory.
(This practice in industry used for hiding possible run-time error from users of
the service)

screenshot of command line

3. In next step try to redirect the standard output to same file (dirlist) so that
nothing shown after running previous command.
(Hint: you can accomplish this by using 2>&1 [redirect all errors to
where the output goes])
screenshot of command line

Piping the output of a command into another


command:

A) Try this in Week5 directory:

$ ls /etc (what is the output?)

Downloaded by Sachita Ghoora ([email protected])


lOMoARcPSD|53663770

S23_CST8207_Linux System Support Algonquin College

Here we pipe the output of above into head command to show first 5 line ( -5
options)
$ ls /etc | head -5 ( if you change -5 to -2, the output only shows first two line
of output)

B) Now try this:


$ ls /etc | more
Here we pipe the output of ls command into more command which shows the
output page by page

Task 3
Count IP addresses used in SSH break-in attempts
in January
1. To work on this task first download the Logfile posted on Bright space under
Week 5 content to your Linux machine. (Make sure you have your Linux
machine connected to network, recall Week 1 assignment where we
confirmed how to connect and disconnect your Linux machine)
2. Now use the find command to look where your logfile was downloaded.

3. Once you find the path of downloaded logfile copy that file to
~/Assignment5/logs/ (you need to create a logs directory)

4. Use filter commands to find the unique IP addresses used in SSH break-in
attempts in January and then count how many times each IP address was
used.
we need to look for lines in the logfile (you downloaded) that contain both the
string 'refused connect' and the date string 'Jan '. now we need to extract
the IP address from each line and count the number of times each IP address
appears.
Hint :- Below

Downloaded by Sachita Ghoora ([email protected])


lOMoARcPSD|53663770

S23_CST8207_Linux System Support Algonquin College

First grep command selects the lines containing the text string 'refused connect'
inside the Logfile. The output of this first command (only lines containing the
'refused connect' string) goes into the first pipe, not onto the screen.
Second grep reads the output of the first grep from the pipe and only selects lines
that also contain the date pattern for January 'Jan '. The lines being selected have to
contain both the string 'refused connect' from the first grep and the string 'Jan '
from the second grep. The output of this second grep (lines containing both strings)
goes into another pipe.
The awk command reads the selected lines from the pipe. It displays just the last
field (NF) on each line, which happens to be the IP address used by the attacker.
The awk output (a list of IP addresses, one per line) goes into another pipe. (The list
of addresses are not in sorted order; they are in whatever order they appear in the
input file.)
The uniq -c command reads the sorted list of IP addresses from the pipe. It counts
how many adjacent addresses are the same and sends the uniq output (lines with
the count followed by the IP address with that count) into another pipe.
The sort -nr command reads the lines with the counts and IP addresses from the
pipe. It sorts numerically and in reverse (descending) order the lines containing the
leading count numbers and sends the sort output (sorted lines, each containing a
count and an IP address) onto the screen.
Your output after executing the command line will look like this

After confirming your work (show your output to your lab professor)

Downloaded by Sachita Ghoora ([email protected])


lOMoARcPSD|53663770

S23_CST8207_Linux System Support Algonquin College

Task 4 - Conversion between symbolic mode


and octal mode
1. As shown in the class, here you will do conversion for each nine-character
symbolic permission, give the equivalent three-digit octal permission (the
red is as example) :

Symbolic Mode Octal Mode User/Owner Group Other


rwxrw-r-x _ 765 _ 7 _ 6 _ 5
r---wx-w- _ 432 _4 _3 _2
--x------ _ 100 _1 _0 _0

Downloaded by Sachita Ghoora ([email protected])


lOMoARcPSD|53663770

S23_CST8207_Linux System Support Algonquin College

2. More of conversion between octal mode and symbolic mode.

This task is reverse of above task so for each three-digit octal permission in
the following table, give the equivalent nine-character symbolic

Octal Mode Symbolic Mode User/Owner Group Other


001 _ --------x _ --- _ --- _ --x
421 r - - -w- - - x _ r-- -w- --x
300 _ -wr------ _ -wr _ --- _ ---
504 _ r-x---r-- _ r-x _ --- _ r--
756 _ rwxr-xrw- _ rwx _ r-x _ rw-

Task 5
Analyze Effect of permission on File/Directory
in practice
Create below file structure under your /home/user1/Week6 directory
Blue – directories
Green - files

1. Add any content to these files (content must contain its corresponding
filename).
2. Open all the files (f1.txt, f2.txt, and f3.txt) together

add a screenshot of the output

Downloaded by Sachita Ghoora ([email protected])


lOMoARcPSD|53663770

S23_CST8207_Linux System Support Algonquin College

Now just change the permissions for owner set , don’t change the
permissions for group and other set.
3. Give execute permission to f1.txt, write permission to f2.txt and read
permission to f3.txt
4. Execute the command to see the permissions of all files.

Add screenshot

5. Now open all files together, you are not able to see the content of which file?
why?
Ans:- file 2 and file 3 (f2.txt and f3.txt)
6. Now try to append any text to all three files (using >>).
7. For which file you were able to append text and why not to other files?
Ans:- only f1.txt was giving permission to append
Add screenshot of command lines

Changing permissions for dir1,dir2 and dir3

Just change the permissions for owner set, don’t change the permissions for
group and other set.
8. Give execute permission to dir1, write permission to dir2 and read permission
to dir3
9. Execute the command to see the permissions of dir1, dir2, and dir3.

Add Screenshot
10. Make task6 directory your working directory and cd to dir1, dir2, and
dir3 one by one
Explain why you were able to cd to dir1 but not for dir2 and dir3
Ans:- the dir2 and dir3 doesn’t have execute permission which is necessary .
11. Now execute ls command for dir1 dir2 and dir3

Downloaded by Sachita Ghoora ([email protected])


lOMoARcPSD|53663770

S23_CST8207_Linux System Support Algonquin College

12. For which director you are able to list the content?
Ans:- dir1 only
13. Try to see the content of files f1.txt f2.txt f3.txt using cat command.
You wont be able to see the content of any of the files.
14. Now give min permissions that are required to read the content of files f1.txt
f2.txt f3.txt.

Fill in the table below with min permissions you gave to


dir1,dir2,dir3, f1.txt, f2.txt, f3.txt

Permissions
dir1 -x --- ---
dir2 -x --- ---
dir3 -x --- ---
f1.txt r-- --- ---
f2.txt r-- --- ---
f3.txt r-- --- ---

After completing your assignment show your document to your lab professor

Downloaded by Sachita Ghoora ([email protected])

You might also like