Linux & X windows Programming - Assignment III With Solutions

advertisement
Code – ETCS-307
LINUX AND X WINDOWS PROGRAMMING
Assignment III
Question1:
a) How do you insert a line before the first line?
(Hint: Move to the first line with 1G and press O)
b) How do you change the contents of current line completely?
(Hint: use S, enter the new text and press escape and save & quit)
c) How do you abort an editing session?
(Hint: q!)
d) How d and y are different in command mode commands?
(Hint: They are operators and are used in combination with other
commands)
e) How do you delete text from current line to the beginning of the file?
(Hint: d1G )
f) How do you redo your undone instruction?
(Hint: ctrl + R )
g) How do you move six lines up?
(Hint: 6k)
h) What is the difference between the following vi commands:
:w (Hint: Only saves and not quits)
:q! (Hint: Quits without saving)
:wq (Hint: Saves and quits)
Question 2:
a) Does rm * remove all the files?
(Hint: the files beginning with dot will not be removed)
b) How do you list all the file names that have atleast four characters?
(Hint: ls ????*)
Arena Nishant
1
c) When using cat > foo, what happens if the file already contains
something?
(Hint: contents of the file foo will be overwritten)
d) What happens when you use who >> foo and foo doesn’t exist?
(Hint: output of the command who will be written in the foo file, if the
file is not there, the file will be created first)
e) What is the difference between echo “$SHELL” and echo
‘$SHELL’?
(Hint: echo “$SHELL” will print the current working shell
and echo ‘$SHELL’ will print $SHELL )
f) How do you find number of users logged in?
(Hint: who | wc -l)
g) What is the best method to ensure errors are not seen on the terminal?
(Hint: if they are directed to /dev/null or error.txt)
h) What is the standard shell used in Linux?
(Hint: bash)
i) What is the difference between $ wc –l < file1 and $ wc –l
file1?
(Hint: wc –l file1 & wc –l < file1. Run these two commands and you will
get to know the difference
Execute the following commands
$ wc –l file1 file2 file3
Output: 23 file1
12 file2
32 file3
Will display the total also
$ wc –l file1
23)
j) To read v1, v2 and v3, how many values can be supplied?
(Hint: three)
Arena Nishant
2
k) What does the command $ cut –c 10-14 file2 do?
(Hint: this command will cut 10-14 columns of file2)
l) What are the various ways to execute the shell script?
(Hint: bash script_name
sh script_name
./script_name
. script_name)
m) Is the output of the command $ cat foo1 foo2 > /dev/tty
directed to standard output?
(Hint: Yes)
Question 3: Write a command to
a) Replace every occurrence of pattern “isn’t” with “isnot” in the file
(Hint: :%s/”isn’t”/isnot/G)
b) Change all occurrences of the word “the” with “THE”.
(Hint: :%s/the/THE/G )
c) Remove duplicate lines in sort.
(Hint: sort -u)
d) Present lines in reverse order
(Hint: sort -r)
e) To find out common names from two sorted lists
(Hint: sort -u)
Question 4:
a) What is the exit status of a command? What is the normal value and
where the value is stored?
(Hint: the exit status of a command is a value that is returned to the
caller before termination. A command returns a value 0 on successful
termination. The exit status is available in the shell parameter, $? )
b) If a script run as foo –l –t bar[1-3]. What are the values of $#
and $*?
Arena Nishant
3
(Hint: $# = 3, $* = -l, -t, bar[1-3])
c) If a file containing nothing is executed, what value will be returned?
(Hint: 0)
Arena Nishant
4
Download