Docstoc

University of Bridgeport

Document Sample
University of Bridgeport Powered By Docstoc
					                                         University of Bridgepor
                             Department of Computer Science and Engineering
                                       Unix System Programming




Student Name(Last, First):

Student ID:

UB E-mail Address:

Signature:




                                               1
                                                        7. You are the owner of the stock directory. Type
Student Name:                                           the command to copy the entire stock directory
Student ID:                                             structure under the current working directory to
                                                        another directory stockbak
Question 1: Chose the correct answer                    a. $copy stock stockbak
                                                        b. $cp stock stockbak
1. Add the execute permission to the user, assign       c. $cp –r stockbak stock
the write permission to the group and remove the        d.$cp –r stock stockbak
read permission from others on the file docs.
                                                        8. You want to compare all the files in the allrec
a.   $chmod u+x,g+w,o-r docs                            directory. Type the command to assign the
b.   $chmod x+u,w+g,r+o docs                            output of the command to list the files in the
c.    $chmod 124 docs                                   allrec directory to the wc command
d.     $chmod +124 docs
                                                        a.    $wc `ls allrec`
2. You changed your current directory to the tmp        b.    $wc ; ls allrec
directory using the absolute pathname.                  c.    $wc > ls allrec

a.   cd /tmp                                            9. $cat myprog
b.   cd ../                                                 echo This a program file
c.   cd ../tmp                                              echo This program just prints some lines on
d.   cd tmp                                             the standard output

3. Sort a file oldproduct in the numerical
descending order of the second field. Save the
sorted output in a file oldproduct1.                         echo this line comes after three blank lines
a.$sort –nr +1                                               echo you can remove these lines using grep
b $ sort –nr +1 oldproduct –o oldproduct1
c.$sort –nt +1 oldproduct –o oldproduct1                Type the command to remove the blank lines in
d. .$sort +1n oldproduct –o oldproduct1                 the myprog file by using the grep command

4. A file new is to be created. The file should         a.    $grep –v „^$‟ myprog
contain the text This is a new file. Type the           b.    $grep –d „^$‟ myprog
command to create the file new by using the cat         c.    $grep –v myprog
command                                                 d.    $grep –u „^$‟ myprog

a. $cat <new                                            10. You need to list the filenames containing two
b. $cat > new                                           or more characters, beginning with any character
c. $cat |new                                            and followed by the letter n.
d. $cat >>new
                                                        a.$ls ?n*
5. Type the ls command to determine the three           b.$ls *n?
sets of permissions on the file myrec.                  c.$ls *n*
                                                        d.$ls ?n?
a. ls -p
b. ls -a                                                11. Type the command to assign the full
c. ls –l myrec                                          pathname of the
d. ls -L                                                /home/sherry/important/official/memo directory
                                                        to the variable memos
6. Type the command to create a subdirectory
dir2 under a directory dir1 that does not exist         a.memo =/home/sherry/important/official/memo
a. $md dir1/dir2                                        b.memo=/home/sherry/important/official/memo
b. $mkdir dir1/dir2                                     c.
c. $ mkdir –p dir1/dir2                                 memo=$/home/sherry/important/official/memo




                                                    2
12. Type the command to redirect the input to            a.    (sort studentfile | tee student1 | wc –l
the wc command, counting the number of lines                   >finalfile)&
from the pfile and store the result in the sfile         b.    b. sort studentfile | tee student1 | wc –l
                                                               >finalfile&
a. wc –l<pfile<sfile
b.wc –l<pfile>sfile                                      c.     (sort studentfile | tee student1 | wc –l
c. wc –l>pfile>sfile                                           |finalfile)&
d. wc –l<pfile|sfile

13. Type the command to append the contents of           18.    Display fields 1 through 5 of /etc/passwd
the file docs1 to the contents of the file docs2 .
                                                         a.    $cat –d: -f1,5 /etc/passwd
a. .$cat docs1 > docs2                                   b.    $cat –d: -f1-5 /etc/passwd
b. .$cat docs1 << docs2
c. $cat docs1 >> docs2                                   19.    $date | cut –c1-3
d. $cat docs1 > docs2
                                                         a.    Sat
                                                         b.    Apr
14. Create a file named newproject to store the          c.    EDT
contents of the files project1 and project2. The         d.    Sat Apr 15 00:12:24 EDT 2000
UNIX command prompt is displayed on the
screen. Type the command to place the contents           20.    Display all processes owned by user linda
of the project1 file in the newproject file .
                                                         a.    ps –ef | grep „^ *linda‟
a.$ cat project1 >project2 >newproject                   b.    ps –ef | grep „^*linda‟
b.$cat project1 > newproject                             c.     ps –ef
   $ cat project2 >> newproject
                                                         21.tr -d „ „ <fileex

15. Use the file descriptor to redirect the error        a.    deleted all spaces from filex
message generated while displaying the contents          b.     Replaces multiple spaces with single spaces
of the file inquiry to a file named err-msg.                   in filex

a. .$cat inquiry > err-msg                               22.   The difference between ed and sed
b. .$cat inquiry >2 err-msg                              a.    ed can be used interactively but sed not
c.$cat inquiry 2> err-msg                                b.    sed can be used interactively but ed not
d. .$cat inquiry e> err-msg                              c.    ed can use RA but sed not
                                                         d.    sed can use RA but ed not
16. Search for the names of all the files created
or modified on Feb. 24th by redirecting the              23.sed „1,3d‟ filex
output of the list command as input to the grep          a. Delets line 1 and 3
command                                                  b. Deletes line 1 through 3
a. ls –l | grep Feb 24                                   c. Delete all the lines but 1 and 3
b. ls –l | grep „Feb 24th‟                               d. Delets all the lines but 1 through 3
c. ls –l > grep „Feb 24‟
d.$ ls –l | grep „Feb 24‟                                24. The output of
                                                              $wc –l <aaa

17. Sort the contents of studentfile and store the       a.        4
sorted output in the student1 file. Also count the       b         4 aaa
number of lines in the sorted file student1 and          c.        4aaa
store the result in finalfile. Type the command to
execute this process by using background                 25. $sort –u names               does the same job as
processing                                               a. sort –d names
                                                         b. uniq names
                                                         c. sort names | uniq*



                                                     3
                                                       Write a born shell program to count how many
Question 2: Chose the correct answer                   files and how many directories in the current
                                                       working directory.
1. $ echo 'This is the\University of Bridgeport'
                                                       Example:
a. This is the\University of Bridgeport                $count -f
b. This is the                                         Number Of Files is 6
  University of Bridgeport
c. This is the University of Bridgeport                $count -d
d. This is the university of Bridgeport                Number Of Directories is 3


2. $ echo "This is the\University of Bridgeport"       Question 4:

a. This is the\University of Bridgeport                Write a shell program, which will move every
b. This is the                                         file
  University of Bridgeport                             created/will_be_created to a directory named as
c. This is the University of Bridgeport                the extension of that file.
                                                       Example: The program will move files which
d. This is the university of Bridgeport                have doc extension
                                                       (i.e. lab1.doc, class.DOC, sasa.Doc) to a
                                                       directory called $HOME/DOCs. Other
3. $ echo 'What is your name?,                         directories could be XLSs, TXTs, DATs ...
> ...................... '

a. What is your name?,......................           Question 5: If you have 4 files f1, f2, f3, f4 and
b. What is your name?,                                 f5 with the following contents:
......................
c. What is your name?                                  f1:
......................
d.What is your name?......................             a=100
                                                       b=50
4.$ files='*'                                          c=200
$ echo $files                                          d=300
                                                       export a
a. *                                                   export b
b. '*'
c. aaa b n nofile s                                    f2:
d. 'aaa b n nofile s'
                                                       a=10
5. $ echo '$files'                                     b=5
                                                       c=20
a. *                                                   d=30
b. '*'                                                 export c
c. $files                                              export d
d. aaa b n nofile s                                    f1

6. To multiply 10 by 20                                f3:

a. $10 * 20                                            a=1
b. $10 \* 20                                           b=2
c. $expr 10 \* 20                                      c=3
d. $expr 10 * 20                                       d=4
                                                       export a
Question 3:                                            export b
                                                       export c



                                                   4
export d

f4:                                                       g. f1;f2;d=2;c=20;export c; export a; echo $a $b
                                                          $c $d
echo $a
echo $b
echo $c
echo $d

f5:                                                       h. export a b;c=10;d=20;f5

a=10                                                      Question 6: What is the output of the following:
b=5
c=20                                                      a. echo “ I am a student in //„CS345//‟”
d=30
export c
export d
f1
f4                                                        b. echo „I am a very \\\\SHELL\\\\ programmer‟

What is the output of the following, if you run all
the following from the parent shell:

a. a=10;c=10;export a;export c;f4                         c. echo “I am a very \\\\SHELL\\\\ programmer”



b. f2;f4
                                                          d.
                                                          date
                                                          Sat Aug 5 23:21:18 EDT 2000
                                                          echo I am going home in this `date`

c. f2;f5




                                                          e. date
d. f1;f5                                                  Sat Aug 5 23:21:18 EDT 2000
                                                          echo „I am going home in this `date`‟




e. a=1;b=10;c=100;d=1000;export a b c d;f1;f4             Question 7:
                                                          Write a program called t that displays the time of
                                                          day in am or pm notation, rather than in24-hour
                                                          clock time. The option d will calculate how
                                                          many days left to end the current month. Here‟s
                                                          an example showing t run at night:

f. a=1;b=10;c=100;d=1000;export a b c d;f5                $date
                                                          Sat Aug 5 23:21:18 EDT 2000
                                                          $t
                                                          11:18 pm



                                                      5
$t –d
26 days




          6
7

				
DOCUMENT INFO