a guest Jun 19th, 2017 48 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
- 1. The man pages can be found in /usr/share/man/ . The files for the man pages pertaining to a program can be found in man1/ and are compressed using gzip. Do the following exercises:
- a. Copy all the man pages that pertain to md5 to a new directory in ~.
- mkdir assignment4
- cd /usr/share/man/man1
- cp md5sum.1.gz ~/assignment4
- cp md5.1ssl.gz ~/assignment4
- cp md5sum.textutils.1.gz
- b. Extract the files using gunzip.
- gunzip md5sum.1.gz
- gunzip md5sum.textutils.1.gz
- gunzip md5.1ssl.gz
- c. Search all the files for any lines pertaining to "passin". List the line numbers and file names for any matches. What is "passin"?
- cat -n * | passin
- 144 [\fB\-passin arg\fR]
- 181 .IP "\fB\-passin arg\fR" 4
- 182 .IX Item "-passin arg"
- passin is an arguement
- 2. You know there is an important file in /etc that contains a reference to the ethernet card. The name of the card is "eth0" in standard Unix-like distros. List all the filenames in /etc and all its subdirectories that contain any mention of "eth0".
- cd /etc/
- grep -cr "etc0" * | grep -v [:]
- 3. The ps command outputs a list running processes. We will examine this command in further detail, but for now just know that the "-e" flag prints all currently running processes.
- a. Use ps -e in combination with grep to get a list of all currently running terminal processes. (Note that by default the 'X' terminal runs on terminal 7.) You will need to figure out a good regex to use.
- ps -e | grep tty
- b. How many "daemon" processes are running? What are their names?
- 7 processes
- c. What are the "PID"s (Process ID) for these daemon processes? Which column do you think is the PID? It seems odd that there is no headers to the columns when you pipe the command to grep... why do you think that happens? Could you modify your regex to somehow fix that?
- If you ps -e then the headers show up because its the ful command. If you grep you are only searching for certain files. You can grep the first field to solve this.
- 4. The next portion of the assignment requires you to interact with your /etc/passwd file. You may need to use the "sudo" command to access it. If you work from ~ and use absolute paths to /etc and output using relative paths, you can minimize the risk of damaging your installation.
- a. Use the "cut" command on your /etc/password file to extract all the usernames. Sort them in alphabetical order.
- cut -d: -f1 /etc/passwd | sort
- b. How many of the users contain the word "daemon"?
- cut -d: -f1 /etc/passwd | sort | grep daemon
- c. Use the cut command to extract the default shell of each user. How many use "bash"? How many use "null"? How many use "sh"? How many use "false"?
- cut -d: -f7 /etc/passwd | sort | grep bash 3
- cut -d: -f7 /etc/passwd | sort | grep null 0
- cut -d: -f7 /etc/passwd | sort | grep false 12
- cut -d: -f7 /etc/passwd | sort | grep sh 18
- 5. Find your .bash_history file. It should be in ~. If you do not find one or have one (which I find highly unlikely) email me and one will be provided.
- a. How many lines are their in the file?
- 169 lines
- b. How many times have you used the "grep" command? The "sort" command? The "cut" command? How many variations of the "ls" command have you used (different set of flags is a variation). Note that there are certain flags you can append to "sort" to remove duplicates.
- cat .bash_history | grep -c grep 11
- cat .bash_history | grep -c cut 0
- cat .bash_hostory | grep -c ls* 73
- cat .bash_hostory | grep -c sort 0
- c. What is the three most common first, second, and third arguments you used in your commands?
- cat .bash_history | grep -o [-][Aa-Zz]* | sort -d | uniq -c | sort -nr
- 6 -cr
- 5 -e
- 3 -a
- d. How many different commands have you read the man pages for? What are they, in alphabetical order?
- grep ^man .bash_history | sort -d | uniq -c | cat -n
- I have 10 man page lookups
- man ~$, alias, cd, cron, free, init, init.d, man, nano, unalias
- 6. Create a compressed archive called assignment_4_<yourname>.tar.gz that contains the following:
- a. A file containing your answers to questions 1-5 called "answers".
- b. A file containing all important commands you used to complete these questions called "commands".
- c. Your .bash_history file. Rename it to "bash_history" (no period).
- Good luck!
RAW Paste Data
Pastebin PRO Summer Special!
Get 40% OFF on Pastebin PRO accounts!
Get 40% OFF on Pastebin PRO accounts!