Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

UNIX/LINUX Please answer questions in their entirety . Answers are case-sensitiv

ID: 3769987 • Letter: U

Question

UNIX/LINUX

Please answer questions in their entirety. Answers are case-sensitive.

1)   What command will search the file /tmp/MCSE for the pattern “MCSE”?

2)   Write a single command line that will change the permissions on your home directory so that you and members of your group can change into it, but others cannot.

3)   What command will show the amount of free disk space on the file systems attached to the server?

4)   Read the man page for tcpdump and provide the command and accompanying options required to read the file named /tmp/tcpdump.dmp, suppress name resolution (avoid DNS lookups), and print each packet in both hex and ASCII.

5)   Write a single command line that defines the variables N=444, M=555, O as the product (multiple) of N and M, and then echoes the value of O.

6)   Write a single command line that uses netstat and grep to count all connections in a state of “ESTABLISHED” and outputs a single number representing how many connections are currently open to the server.

7)   Write a short, interactive shell script that
a.   Asks the user for a numeric variable A
b.   Asks the user for a numeric variable B
c.   Echoes the text “A minus B equals:”
d.   Prints the value of a variable C which is A minus B

8)   Write a short, interactive shell script that:
a.   Asks the user to enter an IP address
b.   Performs a host lookup on the IP address and returns a name if available.
Note: I will test this using 72.14.204.104

9)   Write a short, interactive shell script that
a.   Asks the user to enter a host name (like www.google.com)
b.   Performs a traceroute on the host and then outputs a single line stating “The host %HOSTNAME is ____ Hops Away” where the ____ is the number of hops. (I will test this using www.google.com)

Explanation / Answer

1. Search your command history with CTRL-R Press CTRL-R and then type any portion of a recent command. It will search the commands for you, and once you find the command you want, just press ENTER

2.cd cd, chdir “Change Directory”. When typed all by itself, it returns you to your home directory

3. df Report filesystem disk space usage (“Disk Free” is how I remember it)

4. Character Description Escape character. If you want to reference a special character, you must “escape” it with a backslash first. Example: touch /tmp/filename* / Directory separator, used to separate a string of directory names. Example: /usr/src/linux . Current directory. Can also “hide” files when it is the first character in a filename. .. Parent directory ~ User's home directory * Represents 0 or more characters in a filename, or by itself, all files in a directory. Example: pic*2002 can represent the files pic2002, picJanuary2002, picFeb292002, etc. ? Represents a single character in a filename. Example: hello?.txt can represent hello1.txt, helloz.txt, but not hello22.txt [ ] Can be used to represent a range of values, e.g. [0-9], [A-Z], etc. Example: hello[0-2].txt represents the names hello0.txt, hello1.txt, and hello2.txt | “Pipe”. Redirect the output of one command into another command. Example: ls | more > Redirect output of a command into a new file. If the file already exists, over-write it. Example: ls > myfiles.txt >> Redirect the output of a command onto the end of an existing file. Example: echo “Mary 555-1234” >> phonenumbers.txt < Redirect a file as input to a program. Example: more < phonenumbers.txt ; Command separator. Allows you to execute multiple commands on a single line. Example: cd /var/log ; less messages && Command separator as above, but only runs the second command if the first one finished without errors. Example: cd /var/logs && less messages & Execute a command in the background, and immediately get your shell back. Example: find / -name core > /tmp/corefiles.txt

5. 0 =M +N

echo " 0 value ";

6.Command-Line Arguments:

The command-line arguments $1, $2, $3,...$9 are positional parameters, with $0 pointing to the actual command, program, shell script, or function and $1, $2, $3, ...$9 as the arguments to the command. Following script uses various special variables related to command line:

#!/bin/sh echo "File Name: $0"

echo "First Parameter : $1" echo "First Parameter : $2"

echo "Quoted Values: $@"

echo "Quoted Values: $*"

echo "Total Number of Parameters : $#"

7 c. #!/bin/sh a=10 b=20

val=`expr $a + $b`

echo "a + b : $val" val=`expr $a - $b`

echo "a - b : $val" val=`expr $a * $b`

echo "a * b : $val"