100+ LINUX Shell Scripting MCQ's




1. What is the output of the following command for bash shell:
echo linux $0
a) linux echo
b) linux linux
c) linux bash
d) linux
View Answer
Answer:c
2. What would be the current working directory at the end of the following command sequence?
 $ pwd
/home/user1/proj
$ cd src
$ cd generic
$ cd .
$ pwd
a) /home/user1/proj
b) /home/user1/proj/src
c) /home/user1
d) /home/user1/proj/src/generic
View Answer
Answer:d

3. How do you print the lines between 5 and 10, both inclusive
a) cat filename | head | tail -6
b) cat filename | head | tail -5
c) cat filename | tail +5 | head
d) cat filename | tail -5 | head -10
View Answer

Answer:a
4. Create a new file “new.txt” that is a concatenation of “file1.txt” and “file2.txt”
a) cp file.txt file2.txt new.txt
b) cat file1.txt file2.txt > new.txt
c) mv file[12].txt new.txt
d) ls file1.txt file2.txt | new.txt
View Answer

Answer:b
5. which of these is NOT a valid variable in bash
a) __ (double underscore)
b) _1var (underscore 1 var )
c) _var_ (underscore var underscore)
d) some-var (some hyphen var)
View Answer

Answer:d
6. What is the output of the following code:
os=Unix
echo 1.$os 2."$os" 3.'$os' 4.$os
 
a) 1.Unix 2.Unix 3.Unix 4.Unix
b) 1.Unix 2.Unix 3.$os 4.Unix
c) 1.Unix 2.Unix 3.Unix 4.$os
d) 1.Unix 2.$os 3.$os 4.$os
View Answer

Answer:b
7. What is the return value ($?) of this code:
os = Unix
[$osName = UnixName] && exit 2
[${os}Name = UnixName] && exit 3
 
a) 0
b) 1
c) 2
d) 3
View Answer

Answer:d
8. What is the output of the following program?
x = 3; y = 5; z = 10;
if [( $x -eq 3 ) -a ( $y -eq 5 -o $z -eq 10 )]
then
echo $x
else
echo $y
fi
a) 1
b) 3
c) 5
d) Error
View Answer

Answer:b
9. What is the output of the following program?
[ -n $HOME ]
echo $?
[ -z $HOME ]
echo $?
a) 0
1
b) 1
0
c) 0
0
d) 1
1
View Answer

Answer:a
10. What is the output of the following program?
b = 
[ -n $b ]
echo $?
[ -z $b ]
echo $?
a) 1
1
b) 2
2
c) 0
0
d) 0
1
View Answer

Answer:c
11. The expression expr -9 % 2 evaluates to:
a) 0
b) 1
c) -1
d) 2
View Answer

Answer:c
12. The statement z = ‘expr 5 / 2’ would store which of the following values in z?
a) 0
b) 1
c) 2
d) 2.5
e) 3
View Answer

Answer:c
13. Solaris is the name of a flavor of UNIX from
a) HP
b) IBM
c) Digital Equipment Corp
d) Sun Microsystems
View Answer
Answer:d

14. Which of the following is “NOT” a UNIX variant ?
a) Solaris
b) AIX
c) IRIX
d) AS400
View Answer
Answer:d

15. The system calls in UNIX is written using which language
a) C
b) C++
c) Assembly Language
d) Fortran
View Answer
Answer:a


 16. Which of the following enables multi-tasking in UNIX?
a) Time Sharing
b) Multi programming
c) Multi user
d) Modularity
View Answer
Answer:a

17. Which of the following is considered as the super daemon in Unix?
a) sysinit
b) init
c) inetd
d) proc
View Answer
Answer:b

18. Unix is which kind of Operating System?
a) Multi User
b) Multi Processes
c) Multi Tasking
d) All the above
View Answer
Answer:d

 19. SVR4 stands for?
a) Standard Version Release 4
b) System Version Release 4
c) Standard Five Release 4
d) System Five Release 4
View Answer
Answer:d

20. Lp0 device file is used to access:
a) Floppy
b) Cdrom
c) Printer
d) Tape drive
View Answer
Answer:c

21. Syntax of any Unix command is:
a) command [options] [arguments] b) command options [arguments] c) command [options] [arguments] d) command options arguments
View Answer
Answer:a

22. SVR4 was developed by
a) Sun Microsystems
b) AT&T
c) University of Berkeley
d) Sun and AT&T jointly
View Answer
Answer:d

23. Which of these is not a Unix Flavor?
a) BSD
b) MAC
c) AIX
d) IRIX
View Answer
Answer:b

24. Which of the following statement is FALSE ?
a) Unix supports multiple users
b) Linux is an open source operating system and the source code is shared
c) Shell takes care of inter process communication
d) Shell provides the feature of I/O Redirection
View Answer
Answer:c

25. Which of the following UNIX flavor is from IBM?
a) BSD
b) Solaris
c) HP-UX
d) AIX
View Answer
Answer:d

26. x86-32 uses which programming model?
a) IP16
b) IP32
c) ILP16
d) ILP32
View Answer
Answer:d

27. What are the sizes of (Integer/Long/Pointer) in LP64 programming model?
a) 8/8/8
b) 4/4/8
c) 4/8/8
d) 4/8/4
View Answer
Answer:c

28. Which among the following is used to write small programs to control Unix functionalities?
a) Shell Commands
b) Shell Script
c) Filters
d) C Language
View Answer
Answer:b

29. What control character signals the end of the input file?
a) ctrl + a
b) ctrl + b
c) ctrl + c
d) ctrl + d
View Answer
Answer:d

30. How do you get help about the command “cp”?
a) help cp
b) man cp
c) cd ?
View Answer
Answer:b

31. The redirection 2> abc implies
a) Write file 2 to file abc
b) Write standard output to abc
c) Write standard error to abc
d) none of the mentioned
View Answer
Answer:c

32. cmd 2>&1 > abc will
a) Write file2 to file1
b) Write standard output and standard error to abc
c) Write standard error to abc
d) Write standard output to abc & standard error to monitor
View Answer
Answer:d

33. cmd > abc 2>&1 will
a) Write file2 to file1
b) Write standard output and standard error to abc
c) Write standard error to abc
d) Write standard output to abc & standard error to monitor
View Answer
Answer:b

34. Which of these is the correct method for appending “foo” in /tmp/bar file?
a) echo foo > /tmp/bar
b) echo foo >> /tmp/bar
c) echo foo | /tmp/var
d) /tmp/bar < echo foo
View Answer
Answer:b

35. Syntax to suppress the display of command error to monitor?
a) command > &2
b) command 2> &1
c) command 2> &2
d) command 2> /dev/null
View Answer
Answer:d

36. The following commands gives the output like this
#cat file1 file2
#cat: file1: No such file or directory
hello
If we execute the command “cat file1 file2 1>2 2>&1” the output would be
a) cat: file1: No such file or directory hello
b) No output is displayed
c) Cat: 1>2: No such file or directory
d) hello
View Answer
Answer:b

37. cat < file1 >> file2 | file3
a) file1 content will be appended to file2 and finally stored in file3
b) file1 content will be appended to file2 and file3 will be ignored
c) file2 and file3 will have same content
d) syntax error
View Answer
Answer:d

38. Executing cat /etc/password > /dev/sda as superuser will
a) Write data into a regular file called /dev/sda
b) Write data to the physical device sda
c) Create a temporary file /dev/sda and write data to it
d) None of the above
View Answer
Answer:b

39. From where would the read statement read if the following statements were executed?
exec < file1
exec < file2
exec < file3
read line
a) It would read all the files
b) It would not read any files
c) It would read all the files in reverse order
d) It would read only file3
View Answer
Answer:b

40. Which option of grep displays the line number as well?
a) -v
b) -l
c) -n
d) -E
View Answer
Answer:c

41. How can you search for blank line in a file?
a) $ grep “ “ file
b) $ grep “^$” file
c) $ grep [“ “] file
d) $ grep [^$] file
View Answer
Answer:b

42. Assuming the files fileA, fileB, fileAB, fileBC and fileABC, exist in a directory, which files match with the pattern file[ABC]?
a) fileA, fileB and fileABC
b) fileABC
c) fileA and fileB
d) fileAB, fileBC and fileABC
View Answer
Answer:c

43. What will be printed for the command below?
$ grep –c “^echo” abc
a) The count of lines that do not contain the pattern echo in file abc
b) The count of lines which begin with the pattern echo in file abc
c) The count of lines that ends with the pattern echo in file abc
d) None of the above
View Answer
Answer:b

44. Which one is used to select only one copy of the repeated lines?
a) uniq -u
b) uniq -d
c) uniq -c
d) uniq –I
View Answer
Answer:a

45. Indicate the right option to search for BOB, Bob, BOb or BoB?
a) grep –i Bob files
b) grep ‘B[oO][bB]’ files
c) grep ‘[BOB]’ files
d) grep -v ‘Bob’ files
View Answer
Answer:b

46. Indicate the right option to search for anything not a letter or number
a) grep ‘^[a-zA-Z0-9]’
b) grep ‘[^a-zA-Z0-9]’
c) grep ‘[a-zA-Z0-9]’
d) None of the above
View Answer
Answer:b

47. How do you remove duplicate lines from the file foo using uniq?
a) sort foo | uniq –u
b) sort -u foo | uniq -d
c) sort foo | uniq –c
d) sort foo | uniq –I
View Answer
Answer:a

48. One of the entry of /etc/passwd file is shown below:
user1:x:1111:2222:Sanfoundry:/home/user1:/bin/bash
Which among the following will print userid and home dir in the following pattern “user1:/home/user1”
a) awk `{print $1 “:” $6}` /etc/passwd
b) awk `{print $1 “:” $7}` /etc/passwd
c) awk `{print $2 “:” $6}` /etc/passwd
d) awk `{print $2 “:” $7}` /etc/passwd
View Answer
Answer:a

49. who | cut –d ” ” -f1
what is the ouput if the who command displays like this
user1 tty 0 1234
a) user1
b) user1 tty 0 1234
c) tty
d) tty 0 1234
View Answer
Answer:a

50. What is the command that can print lines of first file matching with second file?
a) printline
b) cmp
c) com
d) comm
View Answer
Answer:d

51. Which character to use to escape meaning of special characters in search operations?
a) [] b) ^
c) .
d)#
View Answer
Answer:d

52. Which built-in command performs integer arithmetic in bash shell?
a) let
b) get
c) set
d) none of the mentioned
View Answer
Answer:a
Explanation:None.

53. Which expression use the value of the enclosed arithmetic expression?
a) $(())
b) $()
c) ${}
d) $[] View Answer
Answer:a
Explanation:None.




























Comments

  1. I really appreciate the information shared above. It’s of great help. If someone want to learn Online (Virtual) instructor lead live training in #IBM #QRadar, kindly Contact MaxMunus
    MaxMunus Offer World Class Virtual Instructor-led training on #IBM #QRadar. We have industry expert trainer. We provide Training Material and Software Support. MaxMunus has successfully conducted 1,00,000 + training in India, USA, UK, Australia, Switzerland, Qatar, Saudi Arabia, Bangladesh, Bahrain, and UAE etc.
    Avishek Priyadarshi
    MaxMunus
    E-mail: avishek@maxmunus.com
    Skype id: avishek_2.
    Ph:(0) 8553177744 / 080 - 41103383
    www.MaxMunus.com

    ReplyDelete

Post a Comment

Popular posts from this blog

Top 16 Mobile App Development Companies in India | App Developers 2017

CCEE CDAC Exam Questions

CDAC CCEE EXAM Prepration Link/PDF [Syllabus Topic Wise ] C++ & DS