Sunday, January 30, 2011

shell and unix answers


UNIX Question Bank 01 / FAQs [ 20 QUESTIONS ] A

Question1
All Unix commands

Must be in lower case
Must be in upper case
Must be in mixed case letters
All of the above


Question 2
Unix operating system cannot run on which of the following
Microprocessor? A

8086
80286
80386
Pentium


Question 3
Unix is D

Single user
Multi-user
Multitasking operating system
Both B and C


Question 4 B
Which command is used for searching a given pattern in a file?

Lookup
Grep
Find
Search


Question 5 B
In which language Unix is written

Perl language
C language
Pascal language
None of the above


Question 6 C
Which of the following is a filter command?

ls
who
cat
find


Question 7 B
The bin directory contains
     
Binary files
Executable files for most of the Unix commands
General application files
None of the above


Question 8 B
Directory /dev contains

user related files
device related files
command file
temporary files


Question 9 D
Which of the following is true above Unix File System?

It has a hierarchical file structure
Files have access permissions
All devices are implemented as files
All of the above


Question 10 C
By default what are permissions given to the user when a file is
created

read
write
read and write
None of the above


Question 11 C
Which of the following can be used for creating a file

touch
cat
vi
All of the above


Question 12 B
Identify the false statement about 'ln'

When a file has two links, it is not physically present at two places,
but can be referred by either of the names
When a file has two links, it is physically present at two places, but
can be referred by either of the names
By default a file has one link
By default a directory has two links


Question 13 B
The existing permissions of file can be changed by

The super user
The owner or group
Others
All of the above


Question 14 A
The exit status of Grep if it fails to find a match

false
true
null
None of the above


Question 15 D
Shell recognizes three types of commands

external commands
shell scripts
internal commands
All of the above


Question 16 D
Choose the correct option to create file "middle" consisting of keyword
input sandwiched between the contents of two files start and end

Cat start end - > middle
Cat start - end < middle
Cat start end - < middle
Cat start - end > middle


Question 17 C
The correct way to send date and contents of file called "results" to
file "final" is

date ; cat results > final
date | cat results > final
(date ; cat results) > final
(date, cat results) > final


Question 18 A
cp first second 2 > msg

Errors are stored in file msg
Syntax error
Error message is printed on screen
Contents of first and second are stored in msg


Question 19 B
To merge the standard error into the standard output

1 > &2
2 > &1
1& > 2
2 & > 1


Question 20 A
To compile demo.c and run, we can use

cc demo.c ; a.out
cc demo.c ; demo.exe
cc -c demo.c ; a.out
Both A and B



===================================================================================
UNIX Question Bank 02 / FAQs [ 20 QUESTIONS ]


Question1 B
To get the PID of last background process

echo $#
echo $!
echo $0
echo $$


Question 2 C
The -v option of sh causes the shell to

Debugs if shell script has any error
Does nothing
Echo each command before it is executed
Gives verbal output


Question 3 B
The option to o test for zero length string is

-s
-z
-a
-d


Question 4 A
A file is identified by _____ associated with it

Inode number
Process-id number
Group-id number
User-id number


Question 5 C
The default value of umask is

777
644
022
422


Question 6 B
Which of the following command is used to find the largest capacity of
a file (maximum bytes a file can hold)

Umask
Ulimit
FLargeLimit
None of the above
 

Question 7 A
Using ___ you can accept input from the standard input, process it and
send the output to the standard output

Filters
Pipe
Both A and B
None of the above


Question 8 C
What is the internal value associated with the standard error device?

0
1
2
None of the above


Question 9 A
Block commands work

On group of lines
On single line
On a single file
None of the above


Question 10 D
In which of the following modes vi (editor) works

Command mode
Insert mode
Ex command mode
All of the above


Question 11 B
Which commands help in viewing lines at the beginning or at the end of
the file?

Touch and cat
Head and tail
Touch and head
Cat and tail


Question 12 D
Which of the following commands are used to save disk space?

Ulimit
Compress
Pack
Both B and C


Question 13 C
What is the command for viewing a compressed file?

cat
touch
zcat
acat


Question 14 C
Password created for a user is stored in a file

/dev/passwd
/usr/passwd
/etc/passwd
/bin/passwd


Question 15 B
Which of the following is true?

A DOS formatted floppy can be used in Unix and a Unix formatted floppy
can be used in DOS
A DOS formatted floppy can be used in Unix but a Unix formatted floppy
cannot be used in DOS
A Unix formatted floppy can be used in DOS but a DOS formatted floppy
cannot be used in Unix
None of the above


Question 16 D
Which of the following is a metacharacter?

m>
&&
$1..$9
All of the above


Question 17 C
Block command works in

Command mode
Insert mode
Ex command mode
All of the above


Question 18 B
How can you create hidden files in Unix

*filename
.filename
$filename
#filename


Question 19 C
What happens when the following command is executed?
(date; banner welcome; ls)> one 2>two

date along with the banner and list of all the files is written into
files one and two
date along with the banner and list of all the files is written only
into file two
date along with the banner and list of all the files is written only
into file one
syntax error


Question 20 B
Which of the following command is used to execute commands at specified
date and time?

nohup
cron
fgrep
None of the above


UNIX Question Bank 03 / FAQs [ 20 QUESTIONS ]

Question1
Which of the following is true? D

Both user and superuser can execute the executable file etc/cron
Only user can execute the executable file etc/cron
Only superuser can execute the executable file etc/cron
Neither the user nor the superuser can execute the executable file
etc/cron


Question 2 A
What is the output of the following command?
    ls | grep '^d' | wc -l

Gives a count of all the files starting with the word d
gives a count of all the files except the files starting with the word
d
gives a count of all the files in present directory
syntax error


Question 3 B
What is the output of the following code

    A=$1
    B=$2
    for i in $A
        do
            mv $i ${i}$B
        done

    if the arguments passed are
    test *5t

test*
test*5t
testtest*5t
syntax error


Question 4 C
Default status permission for a file is set based on

chmod
Owner
umask
Group


Question 5 B
For setting environment variables in Unix which of the following files
do you edit

.profile
.exrc
.login
None of the above


Question 6 D
To compile program in Unix having mathematical library functions, we
need to

include math.h
include stdlib.h
cc filename -lm
Both A and C


Question 7 C
What happens if the following command is executed?

    At 12:00 am Jan 1
    Echo "happy New Year"

Syntax error
At 12:00 am on January 1, displays the message happy new year on the
terminal
At 12:00 am on January 1, the following message is mailed by cron
Incorrect usage of at command


Question 8 C
To list the files in a directory, we need to have

Write permission to the directory
Read permission to the directory
Execute permission to the directory
Both A and B


Question 9 B
Which one among the following is a filter command?

ls
awk
vi
None of the above


Question 10 B
What happens if you don't redirect the output to the terminal, when
using at command

It would throw a syntax error
It would be mailed to us by the cron
It would throw an error stating improper usage of the at command
Nothing, because by default it would be redirected to the terminal


Question 11 A
Which of the following provides information regarding which users are
allowed and which users are disallowed from using the at command

at.deny and at.allow
at.allow and at.disallow
at.deny and at.show
All of the above


Question 12 A
Which command would you use to find out how much time is required to
execute a particular process?

time
nice
who
ps


Question 13 D
Using the kill command which of the following processes cannot be
killed?

sched
vhand
nice
Both A and B


Question 14 A
The correct way to search for a pattern in a file one, sort that file
and file called two and write the contents of the sorted files to a new
file called three is

grep test one | sort - two > three
grep test one | sort cat two > three
grep test one | sort one | sort two > three
All of the above


Question 15 C
How can you say that a particular command is a filter or not?

If the command takes only input from the standard input
If the command send only output to the standard output
If the command takes input form the standard input and it sends its
output to the standard output
All of the above


Question 16 B
Which of the following files do you edit for setting the path in Unix

.exrc
.profile
.login
None of the above


Question 17 A
Which of the following shell variable would change the existing prompt
to your name?

PS1
PS2
PATH
HOME


Question 18 D
What is the output of the following program?

    echo "Enter your name"
    read name
    t=`expr $name | wc -c | bc`
    echo "The length of the given string is $t"

    if the input given is "this is a test from genesis"

5
28
22
Syntax error


Question 19 B
How to compile a list a files given as command-line arguments, and if
they are complied successfully how do we run them?

cc $* || a.out
cc $* && a.out
cc $* -a a.out
cc $* -o a.out


Question 20 A
If the grep command is successful in finding a pattern, it returns a
exit status of

0
1
2
3
UNIX Question Bank 04 / FAQs [ 20 QUESTIONS ]

This is a mock Exam for the Unix programmers.

Question1 D
How will you separate one command from another if you want to put
several commands on the same line?

:
||
-a
;


Question 2 B
If the following echo command is used, what would be the output

    Echo This is a test of * meta character in Unix operating system

This is a test for * meta character in Unix operating system
The meta character * is replaced by a list of all your files
Improper usage of meta character in echo command
Syntax error


Question 3 B
Contents of file "test" are as follows

    Echo ${1? "This is a test for argument"} is the only argument

    What is the output, if you execute the following file

Bad substitution
This is a test for argument
Test is the only argument
This is a test for argument is the only argument


Question 4 B
Which of following shell variables provides information of the command
being executed and its PID?

$! and $0
$0 and $$
$$ and $!
$$ and $-


Question 5 A
What is the output of the following command if file one is undefined?

    sort one > one.sort 1>&2 two

throws an error on the standard output and writes to file called two,
stating file or directory does not exist
throws an error only on the standard output, stating file or directory
does not exist
the standard error is redirected to the file called two, stating file
or directory does not exist
None of the above


Question 6 C
What is the output of the following command assuming the variable
called name is defined as
Name=Genesis
: ${name?' is the name of our organization'}

Syntax error
Genesis is the name of our organization
Nothing, because it is a do nothing command
Wrong usage of : , $ and ? in one statement


Question 7 A
Which of the following shell command is used as a comment in Unix

//
:
#
Both A and B


Question 8 C
To find the files containing word "printf" in the system

find / -name * -exec grep "printf"
find / -name "*" -exec grep "printf" {} \;
find / -name "*" -exec grep -l "printf" {} \;
find / -name "*" -exec ls -l {} \;


Question 9 D
What is the significance of fork function

Kills an existing process
Temporarily half an existing process
Create a new process, killing the previous process
Create a new process


Question 10 A
On successful completion of fork()

It returns a value of 0 to the child process and also returns process
ID of the child process to the parent process
It returns a value of -1 to the parent process, with no creation of
child process
It returns a value of 0 to the parent process and also returns process
ID of the child process to the parent process
It returns a value of -1 to the child process and also returns process
ID of the child process to the parent process


Question 11 B
What is the output of the following code

    main()
    {
        printf("Line1 ");
        fork();
        printf("Line2 ");
    }

Line1 Line2
Line1 Line2 Line2
Line1
Line2 Line1


Question 12 A
What is the output of the following code

    main()
    {
        printf("Line1 ");
        execl("/bin/date","date",0);
        printf("Line2 ");
    }

Line1 followed by date
Line1, date followed by Line2
Line1 followed by Line2
Syntax error


Question 13 B
The /etc/passwd file can be updated only by superusers. But a ordinary
user can update his password through /bin/passwd executable file,
because

The owner can change his password
Temporary permission is given to update /etc/passwd
Superuser gives permission to change his passwd
None of the above


Question 14 C
Which command waits until all background processes known to the current
shell have been terminated?

sleep
stop
wait
continue


Question 15 D
What does wait() system call return to all parent process, when a child
process is created by fork()?

PID of the child process
Exit status of the child process
Returns zero or one
Both A and B


Question 16 A
Which command compares two text files?

diff
compare
write
tell


fQuestion 17 A
What is the output of the following statement?
    echo */*

displays all files in all directories
displays only the files in the current directory
displays only the directories
syntax error


Question 18 B
If you want to display message at the time of login, which of the
following files do you edit?

/etc/passwd
/etc/motd
/etc/news
/etc/msg


Question 19 A
Which of the following category of user can send message at the time of
login?

Only the superuser
Only the users
Only the groups
Others


Question 20 D
What is the output of the following shell script?

    t=`cat /etc/passwd | grep -s $1`
    echo $t
    if [ $? -eq 1 ] then
        Echo " $1 is not created"
    else
        Echo " $1 is created"
    fi

Syntax error
Improper usage /etc/passwd, because you cannot edit /etc/passwd (read
permission is denied)
Searches for the name given at the command line in the /etc/passwd and
on success displays the message name is not created
Searches for the name given at the command line in the /etc/passwd and
on success displays the message name is created

UNIX Question Bank 05 / FAQs [ 20 QUESTIONS ]

Question1 B
What is the output of the program?

    echo "Give input \c";read str
    set $str
    echo " Give the word \c";read word
    count=0
    for i in $*
    do
        if [ $i -eq $word ]
            then
            count=`expr $count + 1`
        fi
    done
    echo $count

    if the input is "This is a test to test your knowledge"
    and the given word to search is "test"

Syntax error
8
2
9


Question 2 A
Which of the following provides information about the current users and
their terminal types?

who | tr -s ' ' | cut -f1,2 -d ' '
who | tr -s ' ' | cut -f1-2 -d ' '
who | cut -f1-2 -d ' '
who | cut -f1,2 -d ' '


Question 3 C
How can you find out the exit status of a shell script using exit?

echo $#
echo $@
echo $?
echo $??


Question 4 A
What is the output of the following shell script, if a file "test"
exists?

    cat test |
    tr -sc A-Za-z |
    sort |
    uniq -c |
    sort -n |
    tail

displays the last ten lines from the file "test"
displays the first ten lines from the file "test"
displays only the last line from the file "test"
displays only the first line from the file "test"


Question 5 C
What is the output of the following shell script?

    While true
    Do
        Sleep 5
        Echo "\007 Check it out again \007"
    Done

After every 5 seconds it displays the message \007 Check it out again
\007
After every 5 seconds it displays the message Check it out again in
bold letters
After every 5 seconds it displays the message Check it out again with a
beep sound
None of the above


Question 6 D
Which of the following option is used to find out whether a given name
is the name of a file or a directory?

-fd
-d
-ff
-f


Question 7 B
Which command displays maximum of 10 lines from the end of the file?

Head
Tail
Both A and B
None of the above


Question 8 D
Which of the following gives the count of number of links of a
particular file?

ls -l |grep filename |cut -f2 -d ' '
ls |grep filename | tr -s ' ' | cut -f2 -d ' '
ls |grep filename | cut -f2 -d ' '
ls -l |grep filename | tr -s ' ' | cut -f2 -d ' '


Question 9 B
What is the signal number to terminate a process?

1
9
3
12


Question 10 B
Console is a

Ordinary file
Character based file
Stream
None of the above


Question 11 D
When you login to Unix system kernel starts

Init
Getty
Device files
Both A and B


Question 12 B
What does the following statement perform?

    who -u | grep unix | tr -s ' ' | cut -f6 -d ' '

It will search for all the user logged, and return their login time
It will search for all the user logged, and return their ideal time
It will search for all the user logged, and return the time spend by
them in the lab
None of the above


Question 13 D
Which command displays the first few lines of a particular file?

grep tail search head


Question 14 B
What is the significance of execl()?

It kills the original process and start a new process
It continues the original process by overlaying memory with a new set
of instructions
It does not kill the original process but creates a copy of the
existing one and starts a new process
None of the above


Question 15 D
What would be the output of the following shell script "Display", if
the files one, two and three exist

echo Displaying the contents of all the files
cat "$*"

It is executed as: sh Display one two three

displays the contents of the file one, two and three
displays the contents of the file one and two
displays the contents of the file two and three
displays the message cannot open file one two and three


Question 16 D
// Old ones follow

What does the following shell script do?

    echo "Enter the name ";read name
    for name
        do
            if [ -d $name ]
                then
                echo "YES"
            elif [ -f $name ]
                then
                echo "NO"
            else
                echo "JUNK"
            fi
        done

displays YES if the given name is the name of a directory
displays NO if the given name is the name of a file
displays JUNK if the given name is neither a file nor a directory
All of the above


Question 17 B
Which of the following command compares two files, and displays bytes
and line number if there are differences?

diff cmp comm ed


Question 18 C
What is the exit status of the following, if file "one" is existing and
the other "file" two in not existing?

cmp one two

0
1
2
4


Question 19 C
When unix is adapted to a new kind of computer, what needs to be done?

Commands has to be changed
Command interpreter (shell) has to be modified
Kernel has to be modified
None of the above


Question 20 B
The command which waits for user to login is?

Init Getty Kernel Getttydef


No comments:

Post a Comment