Assignment 5 Week5
Assignment 5 Week5
Assignment 5 Week5
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:
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
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)
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
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
1) Copy all the contents of lab5 into lab5.2. being in lab5.2 directory, do as follows:
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]
What is the output of below commands? (First try to answer without typing the
command.)
Task 2
Redirecting output:
cat /etc/passwd and redirect the output to file dump.txt located under your
Assignemnt5 directory.
$ cat dump.txt
B) Redirecting Errors:
In Assignments directory of user1 home directory, try the following commands:
$ ls W5 Assignment5
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
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)
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
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)
This task is reverse of above task so for each three-digit octal permission in
the following table, give the equivalent nine-character symbolic
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
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
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
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.
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