Upload
alwaysastudent
View
216
Download
0
Embed Size (px)
Citation preview
8/16/2019 2016 Answers Assignment1 Software Development Tools Usq Csc2408
1/6
Assignment 1answers
Question 1:
If a file’s permissions is ’rw’, and the directory which the file is in has ’r’ only,
you can perform ’ls’ on the directory and see all files’ name in the directory, but
you can not view the file, not edit the file, nor delete the file.
However, if the directory has ’x’ only, you would not be able to perform ’ls’ on
the directory, but you are still able to view, edit the file if you somehow knew
the name of the file, not delete the file.
Question 2:
a) What is the difference between ab.cd and ab*cd?
ab.cd will match a string with only one character between ab and cd.
Example: ab1cd will match
ab*cd will match a string when there is ero or more characters between ab and
cd.
Example: ab1!"#$cd will match
b) what is the diference between ab.*cd and abb*cd ?
8/16/2019 2016 Answers Assignment1 Software Development Tools Usq Csc2408
2/6
ab.*cd will accept for any string inbetween ab and cd.Abb*cd will accept if ab is followed by b and then followed
by zero or any characters until cd.c) What is the difference between ^abc and ̂ abc$?
“^abc” will accept all the characters matching abc at the start in the
given file
%&abc'( will return if the file is starting with abc.
d) What is the difference between [abc]d and [^abc]d?
[abc]d will return all the characters with previous characters any of %a( or
%b( or %c( followed by d
[^abc]d will return all the characters with any other previous characters
excluding %a( or %b( or %c( followed by d
e) What is the difference between [!"][#a!!"%!&]* and [!"#][a!!
"%!&]*?
[A-Z][_a-zA-Z-!]* )irst one will accept capital letters followed by
any digit and underscore.
[A-Z_][_a-zA-Z-!]*" nly difference is it can accept even if a string
starts with underscore
+uestion "
a) #i$e the command-line of using %nd to search for all &'()and () programs.%nd )(+,/+0 -perm u2s3g2s
b) 'i(e the cmmand!line f sin+ find t list all the sbdirectries inthe crrent directr,
ls -4l to list all the subdirectories in the current directory
c) -se find t prdce a ln+ ls listin+ f all filles in srbin that aremre than /0%1b ln+. 'i(e all the ar+ments and ptins in thefllwin+ cmmand!line
%nd usrbin -size 5678 9e:ec ls -l ;< =>
8/16/2019 2016 Answers Assignment1 Software Development Tools Usq Csc2408
3/6
+uestion #
reate a big %le ?(f you don@t 8now how to create a big %le3try ls -l usrbin big%leB. Ca8e a copy of it using cp3 andcall them big1 and bigD.
a) -he commandline to compress big1 using gip./ommand gzip -c big1 big1.gz
b) -he commandline to compress big! using bip!/ommand bzipD bigD
c) -he compression ratio of each compression method 0sing command diff
or diff to compare the compressed files and diff to compare the original
file.
d) ive the commandline of checking the file type of compressed files andthe original.2mmand: %le Eoriginal %le and %le Ecompressed %le
e) -he commandline to list top 12 lines of the content of big1.g andbig!.b!2mmand: zcat big1.gz F head -12mmand: bzcat bigD.bzD F head -1
8/16/2019 2016 Answers Assignment1 Software Development Tools Usq Csc2408
4/6
3estin 0:
a) -se tar t create an archi(e 4dn5t se the r 6 ptin) f all the files
in the crrent directr,.
/ommand tar -c$f my%le.tar home&GHD1
b) 2mpress the tar file with +ip.
8/16/2019 2016 Answers Assignment1 Software Development Tools Usq Csc2408
5/6
c) 3iew the contents of archive with gunip and targunzip -c %les.tar.gz F tar tf$ -
d4 3iew without using gunip but use the tar instead. 5Hint find the rightoption to use from the man page4.
6olution tar -tzf %les.tar.gz
e4 /reate a subdirectory of the current directory.
6olution m7dir .sbdirectr,#name
f4 0se tar to unpack the archive into that directory at the current directory.
6olution gunzip -z:f %les.tar.gz - suddir
3estin 8:
-his file is a text file.
sed 9n IthepI %le
7atches the substring 8the’ in the file. 9nd prints the whole line that has got the
substring %the( in it.
@p@ is for printing.
sed -n Is[A-Z]JgpI %le
-his command line will do all lines containing the upper case letters in the
file are replaced by itself 8:9.;
8/16/2019 2016 Answers Assignment1 Software Development Tools Usq Csc2408
6/6
sed IKD3H7s[?B]gI %le
-his command line removes all braces ’5’ and ’4’ from line "! to line #$ in the
file.
8:545:2.?4’ is the first part of =egular expression , ’>5:2.?4’ is the second part of
=egular expression . -he regular expression is a pattern to any strings like s1
"t, !1!"1", etc. ’>1’ is what the first part of the =egular expression , ’>!’ is the
second part. 9fter the execution, the matched strings will be put back, but the
8 ’ is removed. )or instance, string ’a1."t’ is substituted by ’a1"t’, and 8!1!."1"’
by 8!1!"1"’.