1. Which option of grep displays the line number as well?
a) -v
b) -l
c) -n
d) -E
2. How can you search for blank line in a file?
a) $ grep “ “ file
b) $ grep “^$” file
c) $ grep [“ “] file
d) $ grep [^$] file
3. 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
4. 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
5. 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
6. 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
7. 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
8. 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
9. 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
10. 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
11. What is the command that can print lines of first file matching with second file?
a) printline
b) cmp
c) com
d) comm
12. Which character to use to escape meaning of special characters in search operations?
a) []
b) ^
c) .
d)
This set of Linux / Unix questions and answers focuses on VI Editor.
13. Which one of the following statement is not true?
a) vim editor is the improved version of vi editor
b) vi editor commands are not case sensitive
c) vi editor has two modes of operation: command mode and insert mode
d) vi stands for visual editor
14 In vi editor, the key combination CTRL+f
a) moves screen down one page
b) moves screen up one page
c) moves screen up one line
d) moves screen down one line
15 Which vi editor command copies the current line of the file?
a) yy
b) yw
c) yc
d) none of the mentioned
16. Which command is used to delete the character before the cursor location in vi editor?
a) X
b) x
c) D
d) d
17. Which one of the following statement is true?
a) autoindentation is not possible in vi editor
b) autoindentation can be set using the command ‘:set ai’
c) autoindentation can be set using the command ‘:set noai’
d) autoindentation is set by default in vi editor
18. Which command searches the string in file opened in vi editor?
a) / or ?
b) f or F
c) t or T
d) none of the mentioned
19. In vi editor, which command reads the content of another file?
a) read
b) r
c) ex
d) none of the mentioned
20. Which command shows all the abbreviations in vi editor?
a) ab
b) abb
c) show
d) none of the mentioned
21. Which command sets the number for all lines?
a) :set li
b) :set ln
c) :set nu
d) :set nl
22. In Linux, the static library has the extension of
a) .a
b) .b
c) .c
d) .d
23. The library contains the
a) pre-compiled object files
b) source files
c) header files
d) none of the mentioned
24. Libraries can be linked with ____ to create executables.
a) other libraries
b) other object files
c) both (a) and (b)
d) none of the mentioned
25. In Linux, the static libraries can be created by
a) ar command
b) as command
c) ap command
d) aq command
26 If a program is linked against a static library then
a) machine code of the used function is copied in the executable
b) used function definition is copied into the preprocessd code
c) used function definition is provided at the time of compiling
d) none of the mentioned
27. To use the static library in the program
a) header file must be provided to in the source code
b) path for the library must be specified
c) both (a) and (b)
d) none of the mentioned
28. Which gcc option is used to specify the library?
a) -c
b) -l
c) -a
d) -o
29. In linux, the static libraries are mostly installed in
a) /usr/lib
b) /usr/local/lib
c) both (a) and (b)
d) none of the mentioned
30. Which one of the following command can list the symbols defined in a library?
a) mn
b) nm
c) nn
d) mm
Answers
1-c | 2-d | 3-c | 4-b | 5-a |
6-b | 7-b | 8-a | 9-a | 10-a |
11-d | 12-d | 13-b | 14-a | 15-a |
16-a | 17-b | 18-a | 19-c | 20-a |
21-c | 22-a | 23-a | 24-c | 25-a |
26-a | 27-c | 28-b | 29-c | 30-b |