0% found this document useful (0 votes)
285 views39 pages

Test Linux

UNIX is an operating system originally written in C language in the 1970s. It is a multi-user, multitasking operating system known for its portability and powerful commands. Commands are specific instructions used to perform tasks, categorized as external or internal. Common UNIX commands include date, uname, ls, and man to display documentation. Options begin with - and provide additional functionality to commands.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
285 views39 pages

Test Linux

UNIX is an operating system originally written in C language in the 1970s. It is a multi-user, multitasking operating system known for its portability and powerful commands. Commands are specific instructions used to perform tasks, categorized as external or internal. Common UNIX commands include date, uname, ls, and man to display documentation. Options begin with - and provide additional functionality to commands.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 39

UNIX/LINUX -

intro

1. What is UNIX?
a) an operating system
b) a text editor
c) programming language
d) software program View Answer
Answer: a Explanation: UNIX is an operating system developed in the early 1970’s at Bell Labs by Dennis
Ritchie, Ken Thompson, and others. It is a multiuser, multitasking and timesharing operating system. The power
of UNIX is derived from its commands and their multiple options.
2. In which language UNIX is
written?
a) JAVA
b) Python
c) C++
d) C
View Answer Answer: d Explanation: UNIX was originally written in Assembly language but Dennis Ritchie
and Ken Thompson wanted an operating system which could run on more than one type of hardware. So in 1973,
they rewrote the whole operating system in C language due to which one of the strongest features i.e. portability
was added to the operating system.
3. Which of the following is not a feature of
UNIX?
a) multitasking
b) multiuser
c) portability
d) easy to use
View Answer Answer: d Explanation: UNIX is a multitasking operating system i.e. a user can run multiple tasks
concurrently. Similarly, it is a multiuser system because it permits working with multiple users on a single
operating system. But a major disadvantage of UNIX lies in the fact that the richness provided by its commands
requires a special type of commitment to understand the subject. i.e. the user must be well aware of commands
he is using and the functions performed by them.
4. Which of the following is not a part of all the versions of
UNIX?
a) Kernel and Shell
b) Commands and utilities
c) Graphical user interface
d) System Calls
View Answer Answer: c Explanation: The kernel is the heart of the operating system while the shell is the utility
which processes our requests. While system calls are a handful of functions which are used to interact with the
kernel and make available the services provided by the operating system. A Graphical user interface (GUI) is
available in UNIX, but the traditional UNIX interface is the command line only.
5. Which of the following is not true about
UNIX?
a) Many people can use a UNIX based computer at the same time; hence UNIX is called as a multiuser system
b) A user can run multiple programs at the same time; hence UNIX is called a multitasking environment
c) UNIX was not written in ‘C’ language
d) Linux is also known as a version of UNIX
View Answer Answer: c Explanation: One of the most attractive features of UNIX is that it supports multi-user
and multitasking environment which makes it so popular among its users. There are many UNIX variants
available in the market. Solaris Unix, AIX, HP Unix, BSD are some of the examples. Linux is also a flavor of
UNIX which is freely available. Unix was developed in 1969 by AT&T employees Ken Thompson, Dennis
Ritchie, Douglas McIlroy, and Joe Ossanna at Bell Labs and was written in ‘C’.
6. POSIX is a set of standards specified for establishing compatibility between
operating systems.
a) True
b) False
View Answer Answer: a Explanation: POSIX- Portable Operating System Interface for Computer
Environment is basically a set of standards specified by IEEE for establishing compatibility between operating
systems, especially which are UNIX based. For example, if we write a program relying on POSIX standards,
we can easily port it among a large family of Unix derivatives (including Linux).
7. Which part of the UNIX operating system interacts with the
hardware?
a) Kernel
b) Shell
c) vi editor
d) application program
View Answer Answer: a Explanation: The kernel is the core of the operating system. It is a collection of
routines written in C which directly communicates with the hardware. User programs that need to interact with
the hardware access the services of the kernel. There is only one kernel running on a system, unlike shells
which can be multiple.
8. What is a superuser?
a) system manager
b) normal user
c) administrator
d) a user with special rights
View Answer Answer: a Explanation: A superuser (root) is the UNIX system manager which can perform
special tasks like killing any executing program, resetting other users passwords, change users permissions and
performing other system management tasks. The administrator can switch to superuser by issuing su command
9. What is the windowing system of UNIX known
as?
a) X Window system
b) LINUX
c) Red Hat
d) DOS
View Answer Answer: a Explanation: The X window system, commonly known as X, is a windowing system
developed at MIT. It is an open-source, network transparent, client-server based system that provides a Graphical
user interface. X is primarily used on UNIX variants but it is also available for other operating systems also.
UNIX/LINUX COMMANDS - basics
10. What are Commands?
a) specific instructions for performing a particular task
b) part of the operating system
c) part of the shell
d) special instructions
View Answer Answer: a Explanation: Commands are basically specific instructions which are given by the users
to perform a particular piece of a task. In UNIX, commands are entered by the user through a command line
interface which further is processed by the command interpreter i.e. Shell.
11. In how many categories, commands of UNIX operating system
classified?
a) 1
b) 2
c) Many
d) 0
View Answer Answer: b Explanation: There are two broad categories in which the classification of commands is
based on UNIX. They are namely—external commands and internal commands. External commands are those
commands that have an independent existence in the /bin directory i.e. these are the executables which are present
in separate files while Internal commands are built-in commands which are built into the shell. Example, ‘ls’ is
an external command while ‘echo’ is an internal command.
12. Which command is used for extracting the details of the operating
system?
a) cd
b) echo
c) uname
d) wc
View Answer Answer: c Explanation: uname command is used for extracting the details like name, version of
the operating system running on the machine. the cd command is used for changing directories and echo
command is used for displaying the contents of a string on to the output stream. wc command is used for counting
words and other details in a file.
13. The sequences of directories that a shell searches while looking for a command is specified in the
PATH variable.
a) True
b) False
View Answer Answer: a Explanation: When we specify a command, the shell searches for that command in
the list of directories specified in the PATH variable and then executes it after locating the command
successfully.
14. Options are also arguments but begin with
a -.
a) True
b) False
View Answer Answer: a Explanation: Arguments are parameters which are specified along with commands so
that the command can perform an operation or take input from that parameter while options are also arguments
but they are predetermined i.e. they perform a particular task. For example, echo hello. In this command hello
is an argument while in ls – l, -l is an option.

15. Which of the following is not a valid option of


uname?
a) -a
b) -s
c) –v
d) -z
View Answer Answer: d Explanation: uname command is used for printing the information about the current
system. -a is used for printing all the information including version name, kernel name, kernel release, machine
hardware name etc. -s is used for printing only the kernel name while -v is used for printing the kernel version.
16. How can we specify more than one command in the command line at the same
time?
a) using ;
b) using >
c) using ==
d) not possible
View Answer Answer: a Explanation: UNIX allows us to specify more than one command at the same time in
the command line. To do so, we have to separate each command from each other using (;). For example, wc file1
; ls -l file1 . The > symbol allows us to redirects the output of the command(s). For example, wc file1 > file2.
Now, file2 will contain the output produced by the wc file1 command. Both ; and > are called metacharacters.
17. Which command is used to display the documentation of commands in
UNIX?
a) help
b) search
c) whatis
d) man
View Answer Answer: d Explanation: UNIX provides us with a facility of man command, which is used for
getting documentation of any command. For example, to seek help on wc command simply type man wc. This
will simply display all the possible operations, options, description, synopsis of wc command. The POSIX
specification requires only one available option with man command i.e. -k, which prints a one-line description of
the command. whatis command is also available on many UNIX systems which also displays a one- line
description of the command. man -f emulates the behavior of whatis command.
18. Which command is used for displaying date and calendar in UNIX?
a) date and cal
b) DATE and CAL
c) date and calendar
d) dt and cl
View Answer Answer: a Explanation: date command is used for displaying the current system date and time
while cal command is used to see the calendar of any specific month/year.
19. What are meta-characters?
a) special characters having predefined meaning to the shell
b) special symbols
c) shell symbols
d) command symbols
View Answer Answer: a Explanation: meta-characters are special characters having a predefined meaning
to the shell. They are used as wild cards for special purposes like pattern matching, output redirecting etc.
*, |, < are meta-characters.
20. Which command is used for displaying date in the format dd/mm/yyyy
?
a) date +%m
b) date +%h
c) date +”%d/%m/%Y”
d) date +”%h %m”
View Answer Answer: c Explanation: Date command can use format specifiers as arguments with each
specifiers preceding with a + , followed by % operator and a single character for describing the format. $
date +%m -display current month $ date +%h -display the name of the month $ date +"%h %m" -display
both month and month name
21. Which command is used as an alternative to echo command?
a) ls
b) printf
c) wc
d) ps
View Answer Answer: b Explanation: printf command is available on most UNIX systems and it behaves
much like a substitution for echo command. It supports many of the formats which are used by C’s printf
function. printf is also an external command.

22. For what purpose bc command is used?


a) as a calculator
b) as an editor
c) as a process table viewer
d) for copying files
View Answer Answer: a Explanation: bc command is used for invoking calculator on UNIX system. It comes
with a wide library for performing calculations. The power of this tool can be derived from the fact, that it can
perform calculations up to and above 900 digits!
23. script command is used for___________
a) recording history
b) recording our session
c) recording passwords
d) recording scripts
View Answer Answer: b Explanation: script command is basically used for recording our login session in a file.
All the keystrokes, output, error messages that are encountered while our session will be stored in a file which
we can view later. The name of the file in which the session is stored is typescript.
24. 7. Which of the following is a valid option with script
command?
a) -b
b) -a
c) -d
d) -x
View Answer Answer: b Explanation: script command overwrites any previous typescript that may exist. -a
option allows us to append our session to the existing typescript file without overwriting to it. For example,
script -a We can also record our session to a different log file by using the following command. script file_one
25. mailx command is used for sending and receiving
emails.
a) True
b) False
View Answer Answer: a Explanation: Since UNIX is a multiuser system, so communication between systems
seems to be natural and important. For this purpose mailx command is used. Through mailx command, we can
send and receive emails to different users on same host network or different network. The addressing scheme
uses a combination of username and machine name. For example, mailx bob (bob is on same host) mailx
bob@saturn (bob is on networked host saturn)
26. Which of the following function cannot be performed by mailx
command?
a) sending and receiving emails
b) reply to the sender
c) forward, delete and print mails
d) un-send mails
View Answer Answer: d Explanation: mailx command can perform various functions apart from sending and
receiving emails such as replying to the sender and all recipients, forward it to others, save it to a different folder,
delete it, print it. To view received emails, simply type mailx command and hit enter.
27. Two or more users can have same login name in the output of who
command.
a) True
b) False
View Answer Answer: a Explanation: Yes, UNIX provides us a feature that two users can login with the
same username at the same time on the same network host.
28. history command displays the log of recently used
commands.
a) True
b) False
View Answer Answer: a Explanation: History command displays the list of recently used commands by the user
which means whatever commands are used by the user in the current session will be displayed on the terminal
using history command.
29. Which command is used by the user to change their login password in
UNIX?
a) man
b) reset
c) passwd
d) cp
View Answer Answer: c Explanation: Since UNIX is a multiuser system, it requires a password from every user
who wants to log in to the system to help ensure that all the data and files of the user are secure from hackers
and errant users. A user can simply change his/her login password by using the passwd command. Simply type
this command on the terminal and then enter the old password, which after successful verification would allow
the user to input a new password for his login.
30. Which command handles a character stream by duplicating its input?
a) tree
b) tee
c) tty
d) ls
View Answer Answer: b Explanation: tee is an external command which handles a stream of characters by
duplicating its input. It saves one copy in a file and writes the other to standard output. tee command can be
placed anywhere in a pipeline. $ who | tee user.txt
The above command displays the output of who command on the terminal and also saves this output in a
file named user.txt. $ uname -a | tee myfile.txt But what about $ cat myfile.txt | head -25 | tee myfile1.txt
31. For interrupting a command, we can use _____
a) ctrl-z
b) esc
c) ctrl-h
d) ctrl-c
View Answer Answer: d Explanation: Sometimes, a program goes on running on for an hour and does not seem
to complete. To interrupt that command we can use the control key, ctrl-c. Ctrl-h is used to erase character by
character when backspace doesn’t work. And ctrl-z is to return at prompt.

FILE
MANAGEMENT
32. A file is a container for storing
information.
a) True
b) False
View Answer Answer: a Explanation: We can define a file as a stream of characters or a container for
storing information. While working in a UNIX environment, we came across three categories of files
which are classified as- ordinary file, directory file and device file.
33. In how many broad categories, files are divided into
UNIX?
a) 2
b) 4
c) 5
d) 3
View Answer Answer: d Explanation: Files are divided into three major categories i.e. ordinary file, directory
file and device file. The characteristics of these three categories of files differ from each other and each category
has a predefined use.
34. In UNIX, the file name and file size are stored in the file
itself.
a) True
b) False
View Answer Answer: b Explanation: A UNIX file’s size is not stored in the file, nor its name. All this
information is stored separately in a separate area of hard disk which is not directly accessible to humans, but
only to the kernel. 35. 7. Device files are used by the kernel for operating the device.
a) True
b) False
View Answer Answer: a Explanation: Device files are nothing but special files which does not contain a stream
of characters but some attributes related to the devices which govern the operation of a device. The kernel reads
this file for the attributes to perform operations on any device.
36. When we log in, the UNIX places us in a directory, called ______
directory
a) home
b) main
c) parent
d) current
View Answer Answer: a Explanation: When we log in, the system automatically places us in a directory called
Home directory. We can change our directory if we want and can also view our home directory using the shell
variable, HOME.
37. UNIX treats everything as a file.
a) True
b) False
View Answer Answer: a Explanation: All physical devices such as printers, hard disk are treated as files by
the UNIX system. Even the kernel, shell and main memory is treated as a file by UNIX operating system.
38. The root directory is represented by ___
a) \
b) /
c) *
d) $
View Answer Answer: b Explanation: The root directory (/) serves as a reference point for all the files. All the
files are hierarchically below it. All files in UNIX are related to one another. The file system in UNIX is a
collection of all these related files (ordinary, directory and device files) organized in a hierarchical manner.
39. UNIX imposes no rule for framing filename extensions.
a) True
b) False
View Answer Answer: a Explanation: UNIX imposes no rules for framing filename extensions. For
example, a shell script doesn’t need to have the .sh implication, even though it helps in identification. In all
cases, it’s the application that imposes the restriction. For example, C compiler expects C program filenames
to end with .c .
40. _____ and _____ cannot be used in a filename.
a) /, NULL
b) $,^
c) ., %
d) NULL, $
View Answer Answer: a Explanation: UNIX imposes no rules in framing filename extensions but there are
some special characters which cannot be used while naming a file. / and NULL are the characters which cannot
be used in a filename.
41. We should avoid filenames starting with a –
(hyphen).
a) True
b) False
View Answer Answer: a Explanation: Those files which have filename starting with a (-) are difficult to
remove and many commands can interpret such filename as an option which could lead to a miserable
situation.
42. Which command is used for printing the current working
directory?
a) HOME
b) cd
c) pwd
d) dir
View Answer Answer: c Explanation: pwd command is used for checking our current directory. Current
directory is the directory in which we are currently working. pwd displays the absolute pathname i.e. with
respect to the root directory. $ pwd /home/stud5005/Stan&Bran
43. Which command is used for changing the current directory?
a) cd
b) cp
c) pwd
d) rm
View Answer Answer: a Explanation: cd (change directory) command is used for moving around the file system.
cd command is usually invoked with a argument. After invocation, it changes the current directory to the directory
specified as argument. Cp command is used for copying files while rm command is used for deleting files. For
example: our current directory is /bin/user06 and we want to change our directory to a directory named dir_one
which is inside the user06 directory. To do so, type the following: $ cd dir_one $pwd /bin/user06/dir_one
44. Which command is used for creating directories?
a) rmdir
b) mkdir
c) cd
d) cp
View Answer Answer: b Explanation: Directories in UNIX are created using mkdir command. The name of
the directory to be created is specified as an argument to the mkdir command. For example, to create a dir
named dir_01 in the current directory we can use the following command, $ mkdir dir_01
45. What does the following command do? $ mkdir dir dir/dir_01/dir_02
a) create dir, dir_01 and dir_02
b) creates dir_02
c) creates dir only
d) throws an error
View Answer Answer: a Explanation: The above command first creates a directory named dir and after that it
creates a subdirectory dir_01 under dir. At last, it creates another subdirectory dir_02 under dir_01. Thus a
directory tree is formed in which directory dir is the parent directory and dir_01, dir_02 are subdirectories.
46. Sometimes we are unable to create a directory because ______________
a) the directory may already exist in the current directory
b) there may be an ordinary file by the same name in the current directory c) the permissions set for the current
directory does not allow the creation
d) the directory may exist, there may be an ordinary file, the permissions set for the current directory does not
allow the creation View Answer Answer: d Explanation: Sometimes we are not able to create directory because
of multiple reasons as stated above.
47. Which command is used for removing an empty
directory?
a) mkdir
b) rmdir
c) del
d) remove
View Answer Answer: b Explanation: rmdir command is used for removing directories provided the directory
should be empty. For example, to remove a directory named dir_001 in the current directory type the following
command on the terminal. $ rmdir dir_001
48. If rmdir dir001 fails, what could be the
reason(s)?
a) dir001 doesn’t exist
b) dir001 is not empty
c) permissions of dir001 doesn’t allow to remove it
d) dir001 doesn’t exist, dir001 is not empty and permissions of dir001 doesn’t allow to remove it
View Answer Answer: d Explanation: There could be multiple reasons which could lead to failure while
removing a directory. Major reasons could be: -> directory doesn’t exists. -> directory is not empty. ->
permissions of directory doesn’t allow to remove it.
49. pwd and echo $HOME will display the same output.
a) True
b) False
View Answer Answer: b Explanation: pwd is used for displaying the absolute pathname of our current
working dircectory while $HOME displays the absolute pathname of our home directory. $ echo $HOME
/home/user08 // displays home directory $ pwd /home/user08/documents/template // displays current
directory
50. What is an absolute pathname?
a) pathname relative to a parent directory
b) pathname relative to the root (/)
c) pathname relative to parent and current directory
d) pathname relative to the current directory
View Answer Answer: b Explanation: When a file’s pathname is determined with respect to the root(/), such a
pathname is called absolute pathname. No two files in a UNIX system can have same absolute pathnames. Two
files can be of same name but in different directories hence their pathname would be different from each other.
For example, /bin/user06/dir_01 is an example of absolute pathname.
51. Which of the following cryptic symbols are used in relative
pathname?
a) ( . )
b) ( . . )
c) $
d) ( . ) and ( . . )
View Answer Answer: d Explanation: Relative pathname uses two
cryptic symbols which are ( . ) and ( . . ) (.) a single dot represent the
current directory. ( . . ) two dots represent the parent directory.
52. $ cp file_01 . copies the file named file_01 in ____
directory
a) current
b) parent
c) root
d) user
View Answer Answer: a Explanation: The ( . ) represents the current directory so the above command will
create a copy of file_01 in the current working directory.
53. The output of $HOME is an example of absolute
pathname.
a) True
b) False
View Answer Answer: a Explanation: HOME is a shell variable which prints our home directory. The
pathname specified by the output of HOME is an example of absolute pathname. $ HOME
/home/users/user_06
54. The output of the
following command
is __________ $ cp
abd/ .user_06
a) copies .user_06 file in current directory
b) copies .user_06 file in parent directory of directory named abd
c) undefined behavior
d) erroneous output
View Answer Answer: a Explanation: ( . ) single dot represents the current directory so the above command will
copy the file in the current directory. (.) is a cryptic symbol which represents current working directory and is
used in absolute pathname.
55. Which command is used for listing files in a directory?
a) ps
b) list
c) ls
d) wc
View Answer Answer: c Explanation: ls command is one of the most powerful commands used in UNIX system.
It comes available with a bunch of options for listing files available in the directory. There are a number of
options like -l, -a which are used for listing files in different manners according to user’s need. $ ls 001.sh FILE2
abc.txt dir08
56. 2. Which option is used with ls command for long listing of files with seven attributes?
a) -a
b) -l
c) -x
d) -i
View Answer Answer: b Explanation: -l is used with ls command for long listing of files in ASCII
collating sequence. The attributes displayed are: -> File type and permissions -> Links -> Ownership -
> Group ownership -> File size -> Last modification time -> Filename $ ls -l drwxr-xr-x 5 abd users
4096 Aug 12 08:30 go drwx------ 3 mash users 4096 Nov 28 10:49 irc drwxr-xr-x 2 ryan users 32768
July 25 09:15 logs drwxr-xr-x 8 anki users 4096 Oct 2 17:13 src

57. 5. Which option is used with ls command to produce multi


columnar output?
a) -x
b) -F
c) -a
d) -v
View Answer Answer: a Explanation: If there are multiple files present in a directory for listing, it is better that
we display these files in multiple columns. For this purpose -x is used. For example, $ ls -x File1 file2 abc.txt
Dir08 res.c txt05 Dep.lst emp.sh udisk
58. 6. What is the collating sequence of ls command for
listing files?
a) Numerals > Uppercase > Lowercase
b) Numerals > Lowercase > Uppercase
c) Lowercase > Uppercase > Numerals
d) Uppercase > Numerals > Lowercase
View Answer Answer: a Explanation: The output of ls commad is arranged in ASCII collating sequence which
is, filenames starting with Numerals first, then Uppercase, then lowercase. $ ls 001_dir //numeral first 09_abc
ABD.txt //uppercase
prog.sh //lowercase
59. 7. How can we identify executables and directories from the output of ls
command?
a) using -F option
b) using -x option
c) using -a option
d) using -i option View Answer Answer: a Explanation: The output of the ls command simply displays filenames
without indicating the file type. For identifying the file type we use -F option. The output of ls -F displays
filenames with two symbols * and /, which are type indicators. The filenames containing * are executables while
those containing / are directories. $ ls -Fx 008abc.txt TOX.sh* calendar* Dept.lst helpdir/ progs/

60. 9. -r option is same as -R option in ls


command.
a) True
b) False
View Answer Answer: b Explanation: Both -r and -R are different options and performs different tasks. -r is
used to sort the filenames in reverse order while sorting while -R is used for recursive listing of files.
61. 14. The output of ls dir* is ___
a) all files in the current directory
b) all files in the directory having a filename starting with dir
c) no filename is displayed
d) erroneous View Answer Answer: b Explanation: The above command displays those files in the directory,
the names of which will be starting with a prefix ‘dir’. Here * is a meta-character which is used for pattern
matching. $ ls dir* dir01 dir02 dir00.txt
62. Which command is used for displaying contents of a
file?
a) cp
b) rm
c) cat
d) mkdir
View Answer Answer: c Explanation: cat command is used to display the contents of a file. For displaying the
contents, simply invoke the cat command with the filename (whose contents are to be displayed) as an argument.
For example, if abd.txt file contains “HELLO WORLD” then, $ cat abd.txt HELLO WORLD
63. 2. Apart from displaying file contents, cat command is also used for _____
files.
a) displaying
b) deleting
c) copying
d) creating View Answer Answer: d Explanation: cat command is one of the most well-known commands of
the UNIX system. It is generally used to display the contents of a file on the terminal but can also be used for
creating files. Suppose to create a file abd.txt, type the following command $ cat > abd.txt Is similar with $
touch abd.txt Now the prompt vanishes. cat command now waits for the input to be entered by the user. After
the input is entered, the user hits the ctrl-D button which marks the end of the file and thus the file and the
contents entered by the user are saved.
64. 5. If we create a file using cat command with the same filename which already exists in the current
directory then,
a) existing file is deleted
b) new file will be created separately
c) existing file will be overwritten
d) an error will be produced
View Answer Answer: c Explanation: As cat command is also used to create files, so if we want to create a file
with the same filename which already exists in the directory then the existing file will be overwritten.
65. 6. Which symbol is used to append an existing file?
a) >
b) <
c) >>
d) $
View Answer Answer: c Explanation: cat command overwrites the existing file if we try to create another file
with a similar filename as an existing file. To avoid this we can use the >> operator. For example, if file01
already exists and we want to append it, then use the following command: $ cat >> file01 Instead of $ cat >
file01 which would overwrite the existed file01 content
66. 8. Which option is used with the cat command for displaying file with line
numbers?
a) -n
b) -v
c) -a
d) -x
View Answer Answer: a Explanation: cat command supports -n option which is used for displaying file contents
along with line number while -v is used for displaying nonprintable ASCII characters in the file.
67. 9. Which of the following cannot be performed by cat
command?
a) displaying files
b) creating files
c) appending files
d) deleting files
View Answer Answer: d Explanation: cat command cannot delete files. It can only be used for viewing file
contents, creating a file or appending to an existing file. With cat we can only delete the content of an
existing file not the file itself (read and execut the above few questions).
68. What does cat file01 file01 file01 display?
a) error
b) blank terminal
c) contents of file01 three times successively
d) contents of file01 single time
View Answer Answer: c Explanation: When multiple filenames are specified as arguments with cat command,
it concatenates the contents of all the files specified as arguments and displays the output on the terminal.
69. 11. Which files will be displayed by the following command: cat *file*
a) all files in the directory
b) all files with filename containing ‘file’
c) no files will be displayed
d) a single file
View Answer Answer: b Explanation: Since * is a meta-character, here it is being used for pattern matching.
So above command will search all the files in the directory having ‘file’ as a part of their filename. After that
it will concatenate the output of all the searched files and display them on the terminal.
70. Which command is used to create empty files?
a) cp
b) cat
c) touch
d) create
View Answer Answer: c Explanation: Touch command changes timestamps. It is also an
easy way to create empty files. The only argument required to be specified with touch
command is the filename of the file to be created. $ touch file01
71. Which option is used with touch command which forces the command not to create file, if it does
exists.
a) -h
b) -c
c) -t
d) -f
View Answer Answer: b Explanation: In case if there is a strict requirement that touch command should not
create a new file, we can use the -c option with it. Else if the file already exists then it will do nothing. $ touch -
c newfile001
72. Which one of the following commands is incorrect?
a) cat file01
b) cat > file01
c) cat >> file1
d) cat -a file01
View Answer Answer: d Explanation: There is no such option as -a available with cat command. cat file01 //
display contents of file01 cat > file01 // create a new file named 'file01' cat >> file1 // append to the file named
'file01' cat -a file01 // invalid command
73. What is the function of cp command in
UNIX?
a) list all the available files in the current directory
b) delete a given file
c) cp is a command used for copying files and directories
d) change the directory
View Answer Answer: c Explanation: cp command is basically used for creating a copy of source file or a group
of files. The syntax of the command requires at least two filenames to be specified. If both the files specified
are ordinary files, the first file will be copied to the second file. The syntax of cp command is cp source_filename
destination_filename. The contents of the source file will be copied to the destination file in the same directory.
$ cp file_01 file_02 // copies file_01 to file_02
74. What happens if the destination file specified in cp command does not
exist?
a) file will not be copied
b) an error will be produced
c) destination file will be automatically created
d) none of the mentioned
View Answer Answer: c Explanation: If the destination file does not exist, then cp command will automatically
create a file with the same name and then it copies the contents of the source file to the file which is created. If
the destination file already exists, then it will be overwritten with the contents of the source file.
75. What is the correct syntax for copying multiple files with a filename starting as ‘file’ into another
file named as
‘directory_one’?
a) cp -i file directory_one
b) cp -R file directory/directory_one
c) cp file* directory_one
d) none of the mentioned
View Answer Answer: c Explanation: For copying multiple files with a common starting name such as (file,
file001, file.txt, fileone.jpg, file-archive.zip) we use (“*”). An asterisk (“*”) is a wildcard – a special character
which expands to match other characters. For example, cp file* directory_one will copy all the files whose
name will be starting with ‘file’ into ‘directory_one’ file.
76. What does the following command do? $ cp -u * ./stud
a) copy all files to directory ./stud
b) update all files
c) delete all files
d) update all files in the current working directory and copy newer ones to directory ./stud
View Answer Answer: d Explanation: (-u) option is used with cp command to update files and copy only when
the source file is newer than destination file. So the above command will update all files in the current working
directory and copy newer ones to directory ./stud.
77. Sometimes it is not possible to copy a
file.
a) True
b) False
View Answer Answer: a Explanation: Sometimes it may happen that we cannot copy a file because of the
permissions associated with it. For example, If the permissions associated with a file are read-protected then we
cannot copy the file.
78. What does -i option do?
a) interactive copying
b) recursively copying
c) updating
d) none of the mentioned
View Answer Answer: a Explanation: (-i) option is used for interactive copying. It means that suppose if we
invoke a command like cp file1 file2 and if file2 already exists then it will be overwritten which can be a
nightmare for many users. To avoid this, we use -i option. It provides us with a warning before overwriting a
file. It asks the user whether to overwrite the file or not. The syntax is cp -i source_file dest_file. $ cp -i file_01
fo_02 cp: overwrites fo_02 (yes/no)? // asks before overwriting
79. xx. Write four (4) different commands to create a new file mywork.txt (hint: you have
to use cat, touch, cp and vi ... because the exercise doesn’t ask for only empty file)
80. Which command is used for removing/deleting files in UNIX?
a) rmdir
b) rm
c) del
d) mv
View Answer Answer: b Explanation: rm command is used in UNIX to remove one or
more files. It operates silently and should be used with caution. The filename of the file to be
deleted is provided as an argument to rm command. For example, following command deletes
abd.txt file. $ rm abd.txt
81. 2. We can delete multiple files using a single rm
command.
a) True
b) False
View Answer Answer: a Explanation: Multiple files can be deleted in a single go using rm command. All we
need to do is, provides multiple filenames as arguments to the rm command. $ rm file1 file2 file3
82. To delete all files in a directory we use
______________
a) rmdir *
b) mv *
c) rm *
d) del *
View Answer Answer: c Explanation: To delete all files in a directory, use (*) with rm command. It acts as
a meta-character and delete all files without displaying any message on the terminal. So use this command
cautiously.
83. Some files cannot be deleted using rm command because of the permissions
associated with it.
a) True
b) False
View Answer Answer: a Explanation: Whether we are able to remove a file depends on the permissions
associated with the file/directory. So sometime it may happen that permissions of a file won’t allow us to delete
it.
84. Which option is used with rm command for interactive
deletion?
a) -i
b) -f
c) -r
d) -R
View Answer Answer: a Explanation: Like in cp command, -i option is also used with rm command for
interactive deletion. The prompts asks the user for confirmation before deleting the files. $ rm file1 file2 file3
rm: remove file1 (yes/no)? ?y rm: remove file1 (yes/no)? ?n rm: remove file1 (yes/no)? [Enter] // any other
response other than y/n leaves the file undeleted
85. Which one of the following command can delete a directory which is
not empty?
a) rm -r
b) rmdir
c) rm *
d) del *
View Answer Answer: a Explanation: rm command normally does not remove directories but when it is
used with -r option it does. So if we invoke a command like, $ rm -r * // deletes all files in the current
directory and all its subdirectories
86. If we wish to delete a remove a file forcefully, we can use ____ option with rm
command.
a) -i
b) -r
c) -R
d) -f
View Answer Answer: d Explanation: If a file is write-protected, we can remove it forcefully
using -f option of rm command. For example, $ rm -f file.txt // removes file.txt forcefully
87. Which command is used for removing file named -
file.txt?
a) rm -file.txt
b) rm file.txtrm
c) rm — -file.txt
d) rm -f file.txt
View Answer Answer: c Explanation: To delete a file with filename beginning with a ” – “, we have to use (
— ) i.e. double-dash. ” — ” is used so that rm command does not misinterpret the filename as an option.
88. Which command is used for renaming files?
a) rename
b) mv
c) cp
d) move
View Answer Answer: b Explanation: mv command is used for renaming files. This command does not create
a copy of the file, it simply renames it. To rename file1 to file2 simply type, $ mv file1 file2
89. If the destination file does not exists, then mv command
creates it.
a) True
b) False
View Answer Answer: a Explanation: If the destination file specified in the mv command does not exists it
will be simply created. For example, if in the command mv file1 file2, if file2 does not exists then it will be
created. Now file1 will be known as filename ‘file2’.
90. What if the destination file specified in mv command already
exists?
a) it will be deleted
b) it will not be affected
c) it will be overwritten
d) an error will be produced
View Answer Answer: c Explanation: If the destination file already exists, then the contents of this file will be
overwritten with the contents of a source file. For example, mv file01 dir01. If there already exists a file named
dir01, then the contents of dir01 will be overwritten with the contents of file01.
91. Which option is used with mv command so that the destination file does not get
overwritten?
a) -n
b) -f
c) -b
d) -i
View Answer Answer: a Explanation: If the destination file already exists in mv command then it will be
overwritten which can be harmful. To avoid this we use -n option with mv so that the destination file does not
get overwritten. -i option displays interactive messages and asks the user before overwriting the destination file.
92. Which command is used for comparing two
files?
a) cmp
b) comp
c) diff
d) comm
View Answer Answer: a Explanation: cmp command is used for comparing two files byte by byte. It displays
the first mismatch and its location on the terminal. It does not bother about subsequent mismatches but displays
only the first mismatch. As soon as the first difference is found, the command terminates and outputs the line
and byte in which there is a difference. For example, $ cmp file01 file02 file01 file02 differ: Byte 20, Line 2
diff command is used for converting one file into another in order to make them identical and comm is used
for displaying the common elements in both the files.
93. What is the exit status of cmp command if both the files are
identical?
a) 0
b) 1
c) 2
d) undefined
View Answer Answer: a Explanation: The exit status of cmp command is 0 if both the files are identical and 1
if both the files are different. The exit status is 2 if the program encounters a problem.
94. Which option is used with cmp command to display a detailed list of
mismatches?
a) -a
b) -b
c) -f
d) -l
View Answer Answer: d Explanation: cmp command by default only displays the first mismatch that
occurs in both files. For a detailed list of all the mismatches, we use the -l option. It prints byte position
and the byte value for all differing bytes.
95. Which command compares two sorted files line by line?
a) cmp
b) diff
c) comm
d) sort
View Answer Answer: c Explanation: comm command is used for comparing two sorted files line by line.
When there is no option specified with comm command it produces three column output. For example, if
we want to compare two files namely file01 and file02 then the first column will contain those entries which
are unique to file01 whereas the second column will contain those entries which are unique to file02. The
third column will contain the actual information i.e. those entries which are common to both fil01 and file02.
$ comm file01 file02 Saintfoundry Project Global Learning UNIX In the above output, ‘Saintfoundry’ and
‘Learning’ are unique in file01 while ‘Global’ and ‘UNIX’ are unique in file02 whereas ‘Project’ is common
to both the file.
96. Which command is used to display the differences between files?
a) comm
b) diff
c) cmp
d) differ
View Answer Answer: b Explanation: diff command is used for comparing files and displaying the
differences between them. diff command uses certain symbols and instructions to indicate the changes that
are required to make two files identical. For example, a – for appending c – for changing d – for deleting
97. When two files are identical, what is the output of diff
command?
a) Files are identical
b) Returns prompt
c) No output
d) Throws an error
View Answer Answer: b Explanation: When two files are identical, diff command does not produce any output.
It simply returns the shell prompt $. However, we can use the -s option to display an informative message on the
terminal if the files are identical.
98. Which option is used to produce multi columnar output in diff command?
a) -y
b) -v
c) -s
d) -e
View Answer Answer: a Explanation: -y option when used with diff command produces
output in multiple columns. For example, $ diff -y file01 file02 Hii Hii Hello | Hell world
world Here ( | ) symbol indicates that the lines are different in both files.
99. Which command is used for counting words, lines and characters in a
file?
a) diff
b) count
c) man
d) wc
View Answer Answer: d Explanation: UNIX provides a universal word counting program that allows us to count
the number of words, lines and characters in a file. It takes a filename as an argument as produces a 4 column
output. $ wc file01 3 9 45 file01 Above output indicates that file01 contains 3 lines, 9 words and 45 characters.
100. wc command cannot take multiple filenames as
arguments.
a) True
b) False
View Answer Answer: b Explanation: wc command can take multiple filenames as arguments. If multiple
filenames are specified with wc command then it will produce a separate line of output for each file along with
an additional line as a total count for all files specified. For example, $ wc file01 file02 file03 12 45 170 file01
8 34 145 file02 10 38 158 file03 30 117 403 total
101. What does the following command do? $ wc sample.txt > newfile
a) reads word count from sample.txt
b) reads word count from newfile
c) reads word count from sample.txt and write it to newfile
d) error is produced
View Answer Answer: c Explanation: > symbol can be used with wc command for redirecting output. For
example, the following command will read the input from sample.txt and redirect its output to newfile. $ wc
sample.txt > newfile
102. Which command is used for knowing the file type?
a) file
b) type
c) filetype
d) type of file
View Answer Answer: a Explanation: UNIX provides the file command for determining the type of file i.e.
whether it is a text file, script file, archive file or any other type of file. $ file file01 file01: Text file
103. UNIX offers a pager named ____ which has replaced the original pager of UNIX called
____
a) more, less
b) less, more
c) more, pg
d) pg, more
View Answer Answer: c Explanation: The man command displays its output one page at a time. This is possible
because it sends its output to a pager program. more pager is extensively used in UNIX system and it has replaced
the original pager of UNIX i.e. pg. The task of a pager program is to simply display pages on the terminal. It can
also be used to display the contents of a file. $ more abd.txt // contents of the file named abd.txt will be displayed.
It is equivalent of $ cat abd.txt
104. 10. Which of the following is an archival
program?
a) arch
b) archive
c) gzip
d) tar
View Answer Answer: d Explanation: For archiving files to the disk we use tar. It can be used to archive a group
of files or an entire directory structure. tar program provides a handful of utilities like creating, maintaining,
modifying and extracting files that are in tar format. Tar stands for ‘tape archival’. Gzip is more compressing
utility than archival: Answer: b Explanation: To conserve disk space we need to compress a file. gzip is a very
popular program used with one or more filenames for compression. $ gzip file01.txt
105. Which of the following key options is used with tar to create an
archive?
a) -c
b) -x
c) -t
d) -f archive name
View Answer Answer: a Explanation: The tar program uses these specified key options where each
key option performs a specific function. -c creates an archive -x extract files from an archive -t
display files in an archive -f arch -- specifies the archive arch.
106. 5. Which option is used by tar to append files to the end of an
archive?
a) -t
b) -c
c) -x
d) -r
View Answer Answer: d Explanation: We can append files to an archive which is
created already using -r option with tar. $ tar -rvf file03 file04 abc.tar // file03 and
file04 will be added to abc.tar
107. An attribute is a specification of an object that defines its
property.
a) True
b) False
View Answer Answer: a Explanation: An attribute defines the property of an object. In UNIX, every file has a
set of attributes which defines the specification of the file.
108. 2. Which command is used to list the attributes
of a file?
a) cp
b) list
c) ls
d) attr
View Answer Answer: c Explanation: ls command is used for listing the attributes of a file or directory. ls
command when used with -l displays all the seven attributes of a file. (which are ... you have to read from the
beginning)

FILE OWNERSHIP AND


PERMISSIONS
109. 2. How many types of permissions a file has in
UNIX?
a) 1
b) 2
c) 3
d) 4
View Answer Answer: c Explanation: In UNIX system, a file can have three types of permissions -read, write
and execute. Read permission means that the file is readable. Write permission means that the file can be edited
while executing permission (for a directory) means that we can “pass through” the directory file for searching
subdirectories.
110. 3. Permissions of a file are represented by which of the following
characters?
a) r,w,x
b) e,w,x
c) x,w,e
d) e,x,w
View Answer Answer: a Explanation: A file can have three types of permissions; read, write and execute
which is represented by characters r, w and x respectively.
111. 4. A file named abd.txt has the following set of
permissions
-rwxrwxrwx All the three operations i.e read, write and execute can be performed on the file by file owner,
group owner and others.
a) True
b) False
View Answer Answer: a Explanation: UNIX provides a three tired file protection system that determines the
file access rights i.e. the permissions are dived into three groups as r w x r w x r w x The first group has all the
three permissions i.e. file is readable, writable and executable by the file owner. The second group also has all
the three permissions i.e. file is readable, writable and executable by the group owner. The third group also has
all the three permissions i.e. file is readable, writable and executable by others who are neither a part of the
group nor they are an owner of the file. Normally this set of permissions is too dangerous!
112. 5. Which of the following symbol is used to indicate the absence of a
permission of a file?
a) $
b) &
c) +
d) –
View Answer Answer: d Explanation: ( – ) is used to indicate the absence of a single or set of permissions of
a file. For example, if a file has all the three permissions for owner but is only readable by group members and
others, then the set of permissions would be, rwx r-- r--
113. 6. When we create a file, we are the owner of
a file.
a) True
b) False
View Answer Answer: a Explanation: In most cases, the user which creates the file is regarded as owner of the
file. The owner of the file can create, delete or edit the file or he can change the permissions associated with it.
114. 8. A file has permissions as rwx r– —. A user other than the owner cannot
edit the file.
a) True
b) False
View Answer Answer: a Explanation: Since the second and third group of permissions of a file are r– and —
respectively. So the file is only readable and that too, only by the members of the group to which the file
belongs.
115. 12. What is execute permission?
a) permission to execute the file
b) permission to delete the file
c) permission to rename the file
d) permission to search or navigate through the directory
View Answer Answer: d Explanation: Executing a directory does not make any sense, execute permission simply
means that a user can “pass through” the directory while searching for subdirectories. When we use pathname
with any command we should have execute permission for each of the directories involved in the complete
pathname. For example, cd users/users06/abd/dir01/file01.txt // all directories should have execute permission.
116. 13. Which of the following is default permission set for
ordinary files?
a) rw-rw-rw-
b) rwxrwxrwx
c) r–r–r–
d) rw-rw-rwx
View Answer Answer: a Explanation: The default permission set for an ordinary file is rw-rw-rw i.e. it is
readable and writable by owner, group member and others.
117. Which command is used to change the permissions of a
file?
a) chmod
b) ch
c) chown
d) chgrp
View Answer Answer: a Explanation: The chmod (change mode) command is used to change the permissions
of files. This command can only be run by the owner of the file or by the super user.
118. 6. Which of the following symbol is used with chmod to assign permission to
a file?
a) –
b) /
c) +
d) *
View Answer Answer: c Explanation: To assign and remove permissions from a file, (+)
and (-) symbols are used respectively. ‘+’ symbol will assign a permission ‘-‘ symbol
will remove a permission
119. 7. To assign execute permission to the user (owner) for a file named file01.txt, which of the following
command
will be used?
a) chmod u+r file01.txt
b) chmod u+w file01.txt
c) chmod u-x file01.txt
d) chmod u+x file01.txt
View Answer Answer: d Explanation: To assign execute permission to the user,
above command is stated as follows: u - for specifying the category of user. + -
for assigning permission. x - to specify execute permission.
120. 8. What does the following command do? $ chmod ugo +w file01.txt
a) assign write permission to users, group and others
b) assign write permission to the user (owner) only
c) assign write permission to group and others
d) command not executable
View Answer Answer: a Explanation: The string ugo combines all the three categories –user, group
and others while (+) is used to assign the permission. ‘w’ specifies the write operation.
121. 9. Which character is used to replace ‘ugo’ string in chmod
command?
a) a
b) v
c) x
d) o
View Answer Answer: a Explanation: UNIX offers a shorthand symbol ‘a’ (all) that acts as a synonym for the
‘ugo’ string which represents all the categories of users. $ chmod a+w file01 // assign write permission to user,
group and others.
122. To remove write permission from group and others, which one of the following commands will be
used?
a) chmod go+w file01
b) chmod go-w file01
c) chmod ug-w file01
d) chmod a-w file01 View Answer
Answer: b Explanation: To remove a certain permission from a category of users we use (-) symbol. So above
command will remove write permission from group and others.
122. While changing permissions in an absolute manner, we explicitly set all the nine bits irrespective of the
previous
permissions of the file.
a) True
b) False
View Answer Answer: a Explanation: The expression used by chmod in an absolute manner is a string of three
octal numbers (base 8). A set of 3 bits represent a single octal digit. -> Read permission –4 (100 in octal) ->
Write permission –2(010 in octal) -> Execute permission –1(001 in octal) For each category, we add up these
numbers. For example, if we have to set read and write permission then an octal number will be 110 (4+2).
123. 2. What are the permission of file01 after executing this command? chmod 777 file01
a) rwxrwxrwx
b) rw-rw-rw
c) r–r–r–
d) r–r—-
View Answer Answer: a Explanation: Since the octal number for the above command is 777 and we know that
7(111) represents all the three sets of permissions (read, write and execute) for a category of user. As we have
777, the file is readable, writable and executable by anyone.
124. 3. A file named file01 should be readable, writable and executable only by the user(owner). Which
one of the
following set of command will be used?
a) chmod 700 file01
b) chmod 000 file01
c) chmod 477 file01
d) chmod 777 file01
View Answer Answer: a Explanation: Since 7(111) represents read, write, execute permission. So 700 will
represent read, write, execute permission only for the user (owner).
125. 6. Which command is used to change the ownership of a
file?
a) chmod
b) change
c) ch
d) chown
View Answer Answer: d Explanation: For changing the file ownership, we use the chown command. chown
transfer the ownership of a file to another user. The command requires the user-ID (UID) of the recipient. To
change the ownership of a file from user01 to user02, use the following commands:
• Change your status to a super user.
• # chown mash file01 // # indicates another shell
• exit
126. 7. Which option is used for the recursive
functioning of chmod command?
a) -R
b) -r
c) -l
d) -i

Answer: a Explanation: Like other UNIX commands, chmod can also descend a directory hierarchy and
apply the expression to every file and subdirectories it finds. This is done using -R option. For example,
chmod -R a+w dir01 This command will make all files and subdirectories found in the tree walk
executable by all users.
127. 11. UNIX allows the system administrator to use the only chown to change both owner
and group.
a) True
b) False
View Answer Answer: a Explanation: UNIX provides a special privilege for the system administrator to
change both the owner and group using chown command only. The syntax requires two arguments to be
separated by a (:). For example, chown abd:grp01 file01.txt // ownership to abd, group to grp01
128. 12. Which symbol is used to change permissions for hidden files
a) .
b) &
c) $
d) *
View Answer Answer: a Explanation: To change permissions for hidden files, use
the (.) symbol with chmod command.

$ chmod 755 . // works on hidden


files

VIM
EDITOR
129. 2. What does the following command do? $ vi file001
a) open file named file001
b) edit file named file001
c) delete a file named file001
d) open file if it exists else creates a new file
View Answer Answer: d Explanation: vi editor can be used for creating and editing files. In the above
command, if file001 already exists, then the contents of the file will be displayed. Otherwise, an empty file
named file001 will be created.
130. 5. What is the default mode of vi
editor?
a) Command mode
b) Input mode
c) Ex mode
d) Insert mode
View Answer Answer: a Explanation: The default mode of vi editor is command mode, where every key which
is pressed is interpreted as a command to run on the text. To perform operations on text like deleting, copying,
the first step you’ll have to follow is to be in the command mode so that you can run commands according to your
suitability.
131. 8. Which one of the following key is used to switch from command mode to input mode?
a) i
b) :
c) esc
d) ;
View Answer Answer: a Explanation: To switch from command mode to input mode press the ‘i’ key.
132. 10. Which of the following key is used to enter in
ex-mode?
a) ESC
b) i
c) :
d) ;
View Answer Answer: c Explanation: To enter into ex-mode press the ‘:’ key. After that, we can press any ex-
mode command followed by [Enter] to perform suitable operations.
133. ex-mode is used to save our
work.
a) True
b) False
View Answer Answer: a Explanation: One of the major functions performed in ex-mode is, saving our
work. For example, to save our file invoke the following command : :w [Enter] "file001", 10 lines, 456
characters
134. 5. While entering text in input mode the data is saved
in _____
a) buffer
b) disk
c) RAM
d) cache
View Answer Answer: a Explanation: If the file has not been saved yet then whatever we are inputting in it is
stored in a temporary storage called buffer. To save the data entered in the buffer, we have to switch to ex-mode.
135. 6. To quit vi editor without saving the buffer we
can use
a) :q
b) :c
c) :w
d) :q!
View Answer Answer: d Explanation: For quitting vi editor, there are numerous ways available in ex-mode as
well as in command mode. One way of which is to type ‘:q!’ in ex-mode.
136. 8. One of the most important features of vi editor is
_______
a) available mostly across all UNIX platforms
b) easy to learn
c) latest editor
d) powerful than other editors
View Answer Answer: a Explanation: vi is a versatile editor which is
now standard on all UNIX systems.
137. Input mode is used for
____________
a) editing text in files
b) invoking commands on files
c) saving files
d) performing substitution
View Answer Answer: a Explanation: To enter text in a file, we have to first switch to input mode. To enter into
input mode, press ‘i’ once. Any key pressed after that will appear on the screen as text input.
138. 2. Pressing ‘:’ in command mode invokes which mode of
vi editor?
a) ex-mode
b) insert mode
c) command mode
d) input mode
View Answer Answer: a Explanation: To invoke ex-mode we’ve to press the ‘:’ key in command mode. After
pressing : , we are in ex-mode. Now simply type any command of ex-mode to perform a suitable function.
139. 8. Which of the following command is a substitute for ‘:x’
command?
a) ‘:x’
b) :wq
c) :q
d) :w
View Answer Answer: b Explanation: We can also use the ‘:wq’ command to save and quit editor but it
requires an additional keystroke and it is not recommended for use.
140. Which of the following symbols are used for searching a pattern
in vi?
a) /
b) ?
c) %
d) / and ?
View Answer Answer: d Explanation: vi is extremely strong in searching for a pattern. Searching can be
made both in forward and in reverse directions using / and ? respectively.
141. 11. Which of the following commands can be used to replace ‘professor’ with ‘director’ throughout the
whole file?
a) 1,$s/professor/director/g
b) %s/professor/director/g
c) 1,$s/professor/director
d) 1,$s/professor/director/g and %s/professor/director/g
View Answer Answer: d Explanation: We can replace 1,$ with %. It will work same as
1,$. ‘g’ flag is used for global replacement.

SHELL BASICS
142. 6. What is the default symbol for command prompt in Bourne
shell?
a) $
b) %
c) #
d) @
View Answer Answer: a Explanation: If we are using bourne shell on our system, then the
default prompt will be represented by $.
143. 7. What is the default symbol for command prompt in C
shell?
a) $
b) %
c) #
d) @
View Answer Answer: b Explanation: If we are using C shell on our system, then the
default prompt will be represented by %.
144. 10. Which command does not terminates unless we log out of the system?
a) history
b) shell
c) echo
d) login
View Answer Answer: b Explanation: When we log on to a UNIX system, we first see a prompt. This prompt
remains there until we key in something. Even when we think the system is idling, a UNIX command is always
running at the terminal. This command is known as the shell. The shell is with us all the time and doesn’t
terminates unless we log out.
145. Which of the following expression is a correct wildcard pattern if we want an expression in which
the last
character is not numeric?
a) *[!0]
b) *[0-9]
c) [0-9]
d) *[!0-9]
View Answer Answer: d Explanation: Wildcards are used for pattern matching. The command *[!0-9] will
match all expression containing any characters except that the last character entered is not numeric. Here ‘!’
is used for NOT. *[!0] // last characters should not be 0 in the expression *[0-9] // any expression where the
last character is a numeric [0-9] // expression should only contains digits *[!0-9] // the last character should
not be numeric in the expression
146. Which of the following is/are true about
Shell?
a) Shell is a multi-faceted program
b) Shell is a command interpreter
c) Shell provides us with an environment to work in
d) Shell is a multi-faceted, command interpreter and provides an environment to work in
View Answer Answer: d Explanation: Shell is the agency that sits between the user and the UNIX system. It is a
unique and multi-faceted program. It is also called command-interpreter because it interprets our command
entered. It is also a programming language. From another point of view, the shell also provides us with an
environment to work in.
147. Wildcards are special characters which are used to replace or represent one or more
characters.
a) True
b) False
View Answer Answer: a Explanation: A wildcard is a special character which can be used as a substitute for
any of a class of characters, which increases the flexibility and efficiency of searching and replacing. For
example, to remove all the files with a filename starting with ‘chap’ prefix, we can use the command rm chap*.
Here * is used as a wildcard for matching all filenames starting with ‘chap’.
148. 2. Which of the following is not a wild-
card?
a) *
b) ?
c) $
d) %
View Answer Answer: c Explanation: The ‘$’ sign represents the shell prompt while all the other
characters belong to a category of shell wildcards. ‘*’ // matches any number of characters ‘?’ // matches
a single character

149. 3. What does the following command


do?
$ echo *
a) error
b) undefined behavior
c) displays “*”
d) lists all filenames in the current directory
View Answer Answer: d Explanation: When we use echo command with only * as the argument we simply see
a list of file. All the filenames in the current directory are displayed on the terminal. Since we know that * is a
wildcard that can match any number of character. Here it is used as solitary to match all filenames.
150. 4. Which command would be most suitable to remove the
following files?
dirx diry dirz dirzw
a) rm dir?
b) rm dirx diry dirz dirzw
c) rm *
d) rm dir*
View Answer Answer: a Explanation: Since we know that ? can be used to match a single character. In the
above scenario, all the filenames are same except that the last character in all filenames is different. So we
can use the ? meta-character.
151. Which of the following command will list all the hidden filenames in our directory having at least three
characters after the dot (.)?
a) ls
b) ls -a
c) ls .???*
d) ls *
View Answer Answer: c Explanation: The * doesn’t match all files beginning with a (.) dot. So if we need to
lists all the hidden filenames in our directory having at least three characters after the dot (.) we can use the
following command, $ ls .???* .bash_pro .chap01 .netspak .profile //list of hidden files
152. * and ? cannot match ____
a) /
b) $
c) .
d) / and .
View Answer Answer: d Explanation: There are two things which * and ? cannot match. First is, they cannot
match filenames starting with a dot (.). Second is, they cannot match / in the pathname. For example, we cannot
use cd /usr?local to switch to /usr/local. It will generate an error.

153. rm chap0[1234] will delete all of the following


files.
chap01 chap02 chap03 chap04
a) True
b) False
View Answer Answer: a Explanation: We can frame restrictive patterns with the character class. The character
class comprises a set of characters enclosed by the rectangular brackets, [ and ], but it matches a single character
in the class. For example, the pattern [abcd] is a character class that can match a single character – an a, b, c or d.
Similarly, we can combine the character class with any string or any other wildcard expression. Hence, the
command rm chap0[1234] will delete chap01 chap02 chap03 chap04.
154. Which of the following symbol is used for negating the character
class?
a) .
b) *
c) !
d) %
View Answer Answer: c Explanation: We can use the ! as the first symbol for
negating the character class. For example, *.[!tx] //matches all filenames with single
character extension but not .t or .x [!a-zA-Z]* // matches all filenames that don’t
begin with a alphabetic character.

155. Which of the following shell doesn’t support ! symbol for negating the character
class?
a) mash
b) bash
c) POSIX
d) C
View Answer Answer: d Explanation: The ! symbol cannot be used to negate a character class in a C shell. In
fact, C shell doesn’t provide any mechanism for doing so.
156. Providing a backslash (\) before the wild card to remove its special meaning is called
_____
a) escaping
b) quoting
c) listing
d) pattern matching
View Answer Answer: a Explanation: We know that shell uses some special characters to match filenames or
perform other search and replace operations. But if the filename itself contains those special characters, then it
could be a great nuisance. For dealing with such files we use escaping and quoting. Escaping means providing a
backslash (\) before the wild card so that its special meaning could be removed. For example, if we want to
remove a file named chap*, then using the command rm chap* will delete all the file beginning with a prefix
’chap’. In this situation, we can use the following command, $ rm chap\*
157. To remove the file named my document.txt (with an empty space between my and document) which
one of the
following commands will be used?
a) rm my\ document.txt
b) rm my document.txt
c) rm *
d) rm my_document.txt
View Answer Answer: a Explanation: Apart from metacharacters, there are other characters that are special like
the space character. The shell uses it to delimit command line arguments. So to remove the file my document.txt
we can use escaping. The backslash will make the shell to ignore the space. Hence file will be removed easily.
158. We can escape the \ itself using
escaping.
a) True
b) False
View Answer Answer: a Explanation: Sometimes we may need to interpret the \ itself literally. To do
so we need another \ before it. For example, $ echo \\ // displays \

159. The output of the following command is ______________ $ echo ‘The special character $ echo hello and |
ls chap*’
a) undefined output
b) erroneous
c) hello
d) The special character $ echo hello and | ls chap*
View Answer Answer: d Explanation: Quoting is another way to turn off the meaning of a meta-character. When
a command argument is enclosed in quotes (‘), the meanings of all enclosed special characters are turned off.

160. Which of the following command will remove the file


named * ?
a) rm *
b) rm ‘*’
c) rm \*
d) rm ‘*’ and rm \*
View Answer Answer: d Explanation: To suppress the nature of wildcard * we can use either escaping or
quoting. The \ symbol will suppress the feature of wildcard and will remove the file named *. Similarly using
quoting we can turn off the meaning of the meta character.

REDIRECTION AND
PIPES

161. How many files are used for representing different standard
streams?
a) 1
b) 2
c) 4
d) 3
View Answer Answer: d Explanation: The shell associates three files with the terminal –two for display and
one for the keyboard. These special files are actually streams of characters which many commands see as input
and output. Each stream is associated with a default device – which is terminal. These three files are:
• Standard Input
• Standard output
• Standard error
162. The command wc < sample.txt will count data from the file
sample.txt.
a) True
b) False
View Answer Answer: a Explanation: When wc is used without any arguments it will read the data from the
default source which is a keyboard. In the above command, redirection symbol < is present. The following steps
are performed: 1. On seeing the <, the shell opens the disk file, sample.txt for reading. 2. wc performs its execution
and displays the output.
163. Which of the following symbol(s) can be used to redirect the output to a file or another
program?
a) |
b) >
c) >>
d) |, > and >>
View Answer Answer: d Explanation: All commands displaying output on the terminal actually write to the
standard output file as a stream of characters and not directly to the terminal as such. The symbol > will replace
the default destination (terminal) with any file by using the > operator, followed by the filename while the symbol
>> is used to append to a file. | is used to give input to another program.
164. The >> symbol is used to overwrite the existing file
if it exists.
a) True
b) False
View Answer Answer: b Explanation: The shell provides the >> symbol (right chevron used twice)
to append to an existing file. For example, //Do a word count program on sample.txt and append the
output to newfile as shown below. $ wc sample.txt >> newfile
165. The category of commands which uses both standard input and standard output are
called ____
a) directory oriented commands
b) standard input commands
c) filters
d) standard output commands
View Answer Answer: c Explanation: UNIX commands can be
grouped into four categories: Directory-oriented (mkdir,rmdir)
Commands like ls, pwd that write to standard output Commands like
lp that read from standard input Filters – commands which use both
standard input and standard output (like bc)
166. The contents of decalculat.txt
are:
1000 20*25 What will be the contents of result.txt
when we would use: $ bc < decalculat.txt > result.txt
a) Undefined
b) Erroneous
c) 1000 500
d) 2
Answer: c Explanation: We can redirect bc’s
standard input to come from file001 and save the
output in another file named result.txt. bc obtained
the expressions from the redirected standard input,
processed them and sent out the results to a
redirected output stream. Here bc command is used
as a filter.
167. Which of the following files are known as special files
in UNIX?
a) sample.txt
b) /dev/null
c) /dev/tty
d) /dev/null and /dev/tty
View Answer Answer: d Explanation: There are two special files named /dev/null and /dev/tty which is used in
UNIX for special purposes. For example, if we want to check whether the program runs successfully without
seeing its output on the screen or may not want to save output in a file either. For this purpose, a special file
/dev/null is used. It accepts any stream without growing in size. The second file /dev/tty is the one used for
indicating one’s terminal.
168. Which symbol is used to redirect error messages to
/dev/null?
a) %
b) $
c) >
d) <
View Answer Answer: c Explanation: As we redirect our output using > symbol to other files in simple
commands, this technique can also be used to redirect error messages to /dev/null file. For example, $ cmp
file01 file02 > /dev/null
169. Which symbol is used to connect different
streams?
a) |
b) >
c) <
d) ~
View Answer Answer: a Explanation: The shell can connect different streams using a special operator called
pipe (|) and avoid creation of disk file. We can connect two commands using this operator so that one command
can take the output of other as its input. For example, $ who | wc -l // count number of lines in the output of who
command.
170. We can use the > symbol along with pipe in a
command.
a) True
b) False
View Answer Answer: a Explanation: There is no restriction on the number of commands we can use in a
pipeline except that we should know the behavioral properties of these commands to place there. For example,
consider this command: $ ls | wc -l > output.txt // number of lines counted by wc command from the output
of ls //are stored in a file named output.txt
171. Which command saves one copy of character stream in a file and store the other to standard
output?
a) who
b) ls
c) tee
d) wc
View Answer Answer: c Explanation: tee command handles a character stream by duplicating its input. It
saves one copy in a file and writes the other to standard output. For example, $ who | tee user.txt
Above command will the save the output of who command in a file named user.txt as well as it will also display
the output of who command on the terminal.
172. Apart from its use in redirection, /dev/tty can also be used as an argument to some
commands.
a) True
b) False
View Answer Answer: a Explanation: /dev/tty can be used as an argument to some UNIX commands. Because
the terminal is also a file we can use the device name /dev/tty as an argument to some commands like tee. For
example, $ who | tee /dev/tty | wc -l // same as who | wc -l In the above command, tee saved the output of who
in /dev/tty, thus effectively showing it on the screen and wc -l counted the number of lines from another
stream.

SHELL VARIABLES & COMMAND


SUBSTITUTION

173. Shell enables one or more arguments to be obtained from the standard output of another command. This
feature
is called _________
a) command substitution
b) argument substitution
c) shell substitution
d) korn
View Answer Answer: a Explanation: Apart from a pipeline, shell enables connecting of two commands in
another way. Shell enables one or more arguments to be obtained from the standard output of another command.
This feature is called command substitution. For example, to display output like: Today’s date is Sat Jan 05
17:25:41 IST 2002 We can use the following command $ echo “Today’s date is `date`” // date is an argument to
echo command
174. Which of the following meta-character is used in command
substitution?
a) `
b) ‘
c) “
d) >
View Answer Answer: a Explanation: When scanning the command line, the shell looks for another
metacharacter i.e. ` (the backquote) usually placed on the top-left of our keyboard, and it should not be confused
with a single quote (‘).

175. POSIX recommends the use of ____ instead of archaic `command ` for command
substitution.
a) |
b) #
c) %
d) $
View Answer Answer: d Explanation: POSIX recommends the use of the form $(command) instead of archaic
` command` for command substitution. For example, to display the date using command substitution use the
following command: $ echo The date is $(date) Output: The date is Sat Jan 05 17:25:41 IST 2017

176. The UNIX shell is both _______ and _______ language.


a) interactive, responsive
b) interpreter, executing
c) scripting, interpreter
d) high level, low level
View Answer Answer: c Explanation: The UNIX shell is both an interpreter and scripting language. We
can also say that shell can be interactive or non- interactive. When we log in to our system, interactive shell
presents a prompt and wait for our requests while a non-interactive shell is managed by an interactive shell while
executing a shell script.
177. Which one of the following is not an environment variable?
a) HOME
b) PATH
c) USER
d) env
View Answer Answer: d Explanation: env is an external command which runs in a child process and it
lists only environment variables which are inherited from its parent, the shell. VARIABLES SIGNIFICANCE
HOME- home directory, the directory where a user is placed on logging in USER- login name of user PATH-
list of directories searched by shell to locate
178. Which environment variable is used to display our username?
a) PATH
b) MAIL
c) LOGNAME
d) HOME
View Answer Answer: c Explanation: LOGNAME is an environment variable which can be used with
echo command as an argument to display our username. We can also know our username using who am i
command. For example, $ echo $LOGNAME Abd // username
179. Which one of the following command will change our primary prompt from $ to C>?
a) PS1=”C> “
b) PS2=”C>”
c) PS1=”>C”
d) PS2=”<C”
View Answer Answer: a Explanation: The primary prompt string PS1 is the one we normally see i.e. $.
But we can change this prompt for our convenience. As we know that the primary prompt string is stored in PS1,
we can use the following command to change our prompt. $ PS1=”C>” C&gt; // new prompt
180. The shell has ____ prompts.
a) 1
b) 4
c) many
d) 2
View Answer Answer: d Explanation: The shell has two prompts (PS1 and PS2). The primary prompt
string PS1 is the one we normally see i.e. ($). The > is the secondary prompt stored in PS2 which is used by the
shell while responding to a multiline command.
181. Environment variables control the behavior of the system.
a) True
b) False
View Answer Answer: a Explanation: Environment variables control the behavior of the system. They
determine the environment in which we work. If they are not set properly, we may not be able to use some of the
commands without a pathname.
182. Which of the following function(s) are performed by an interactive shell?
a) job control
b) history
c) aliases
d) job control, history, aliases
View Answer Answer: d Explanation: When we log in to our system, an interactive shell presents a
prompt and waits for our requests. This type of shell supports functions like job control, history, aliases etc.
183. Every feature used in an interactive shell can also be used by a shell script.
a) True
b) False
View Answer Answer: b Explanation: An interactive shell runs a non-interactive shell while executing a
shell script. Every feature used in a shell script can also be used in an interactive shell but the reverse is not true.
Job control and history have no meaning in a shell script.
184. Which one of the following is arguably the best shell to use?
a) Bash
b) Korn
c) C
d) Bourne
View Answer Answer: a Explanation: Bash was developed by GNU as a bourne again shell. It was a
grand superset in that that contains the features of both C and Korn shells. Bash was developed to ultimately
conform to the POSIX shell specification and is arguably the best shell to use.
185. Which one of the following command is used to create a child shell?
a) fork
b) wait
c) sh
d) env
View Answer Answer: c Explanation: To create a child shell we can use the sh command. sh is basically
the command name of Bourne shell. sh is a command language interpreter that executes commands read from a
command line string. To create a child shell, simply invoke sh command without any argument.
186. Shell variables are of ____ types.
a) 1
b) 3
c) 2
d) 4
View Answer Answer: c Explanation: Shell variables are of two types –local and environment. For
example, PATH, HOME and SHELL are environment variables. They are called so because they are available
in the user’s total environment whereas local variables are more restricted in scope.
187. Suppose ABD_DIR is a local variable. Then it will be accessible to the child process.
a) True
b) False
View Answer Answer: b Explanation: Since ABD_DIR is a local variable and local variables are more
restricted to the scope so it will not be accessible to the child process. For example, $
ABD_DIR=/home/users/abd/doc // local variable in parent process $echo ABD_DIR home/users/abd/doc $ sh //
create a child shell $echo ABD_DIR _ // variable not available in child shell
188. ____ command is used to display the environment variables only.
a) set
b) env
c) sh
d) var
View Answer Answer: b Explanation: env command is used to display environment variables only in the
current shell. For example, invocation of env command will produce an output in the following form: $ env
HOME=/home/abd LOGNAME=abd MAIL=/var/mail/kumar SHELL=/usr/bin/bash TERM=xterm
189. ____ command displays all the variables available in the current shell.
a) env
b) set
c) var
d) sh
View Answer Answer: b Explanation: set command is used to display all the variables available in the
current shell. set is a built-in command. env is an external command and runs in a child process. It thus displays
only those variables that are inherited from its parent, the shell.
190. Environment variable names can be defined only in uppercase.
a) True
b) False
View Answer Answer: b Explanation: We’ve seen that environment variables are generally defined in
uppercase only. But there is nothing which can prevent us from using a different scheme

You might also like