1.
What switch is used with the useradd command to specify a user's initial group?
Correct Answer
A. -g
Explanation
When we create the user it creates the group same username and
make user belongs to that group as a private group. If you want to chage the private
group at user creating time:
useradd -g groupname username
2.
What option is used with the useradd command to specify the user's user id?
Correct Answer
A. -u
Explanation
By default 0-499 user id reserved for system user and starts to assign
from 500 to normal user. To set the user id at useradd command use the -u option.
Example:
useradd -u 1000 user1 : Which creates the user user1 having user id 1000.
You can display user id as well as group id using the id command
3.
What option is used with the useradd command to specify the user's login shell?
Correct Answer
A. -s
Explanation
When we create the user it assign the bash shell to user, to assign the
different shell use the -s option.
Example:
useradd -s /bin/sh user1 : which creates the user user1 by assigning the /bin/sh shell.
You can check the /etc/passwd file to check the user id, user's private group id, home
directory and login shell.
4.
Which of the following can be used to change a user's home directory?
Correct Answer
A. Usermod -d
Explanation
To change the user's home directory use the -d option in usermod
command.
Example:
usermod -d /var/user1 user1 : Which sets the home directory of user user1 into the
/var/user1.
usermod -s /bin/sh user1 : Which sets the default shell of user user1 sh shell.
usermod -L user1 : Which locks the user account
usermod -U user1 : Which unlocks the user account
5.
You had a contractor come into your company. You originally set his account to expireafter thirty days. You now need to change this. How can you do this?
Correct Answer
A. Usermod -e
Explanation
To set the account expire date:
usermod -e "date" username
Example: usermod -e "May 20 2006" user1
6.
You are logged in as user tux1, but now you want to switch users to tux2 with tux2'senvironment. How would you do this?
Correct Answer
C. Su - tux2
Explanation
su means switch user. To switch from one user to another user with
another user's environment and home directory use - option. Here switching to tux2
, then su - tux2 is answer.
7.
You logged in as user linux1, but now you want to switch users to linux2 with linux'senvironment. How would you do this?
Correct Answer
C. Su - linux2
Explanation
su means switch user. To switch from one user to another user with
another user's environment and home directory use - option. Here switching to
linux2 , then su - linux2 is answer.
8.
Which of these commands would report how many total accounts (including specialaccounts) there are?
Correct Answer
D. Wc --lines /etc/passwd
Explanation
wc command displays the number of lines, words and characters.
wc filename : prints number of lines, words and characters.
wc -l or --lines filename : prints the number of lines in file.
wc -w or --words filename : prints the number of words in file.
wc -c filename : prints the number of characters in file.
9.
What does the following command do? cat '$TEST'
Correct Answer
B. Displays the contents of the file named $TEST if it exists.
Explanation
Varaible is called the memory location containing the value. In linux
we can read the value of variable starting by $ symbol at starting of variable name.
Example: FILENAME=test.txt
echo $FILENAME : Displays the value of variable FILENAME
cat $FILENAME : Displays the contents of file of $FILENAME
10.
file1 and file2 are text files in your local directory. file1 contains this: allan bart ceasar file2 contains this: alicia beatrice Cecilia What would the output of the following command be? tac file1 file2
Correct Answer
E. Ceasar/ bart/ allan/ cecilia/ beatrice/ alicia
Explanation
tac command concatenate and print files in reverse order.
Example:
file1 contains :
a
b
c
and file2 contains
1
2
3
if you use tac file1 file2
Output is like:
c
b
a
3
2
1
11.
Which of the following would copy the file file1.txt to file2.txt?
Correct Answer
C. Cat file1.txt > file2.txt
Explanation
We can redirect the standard output into the file using the redirect (>)
symbol.
Example: ls -l >result : Redirects the standard output of ls -l command into the result file.
Similarly cat redirect the contents of one file into another.
cat file1 >file2 : cat reads the contents of file1 and creates the new file file2, which
contains the text of file1.
Similarly you can append into the existing file using append (>>) symbol.
12.
What command would help you identify the I/O address range being used by thenetwork card?
Correct Answer
E. Cat /proc/ioports
Explanation
/proc is called the virtual file system, which contains the information
about the running kernel.
/proc/ioports file contains the I/O address range being used by the network card.
When you read the file /proc/ioports :
d800-d8ff : 8139too : Where 8139too is the module of Realtek Ethernet card.
13.
Type the command will identify the io address range used by a NIC?
Correct Answer
cat /proc/ioports
Explanation
/proc is called the virtual file system, which contains the information
about the running kernel.
/proc/ioports file contains the I/O address range being used by the network card.
When you read the file /proc/ioports :
d800-d8ff : 8139too : Where 8139too is the module of Realtek Ethernet card.
14.
What is the result of the following command?# cat 'echo "$ Certkiller
Correct Answer
A. A syntax error
Explanation
Varaible is called the memory location containing the value. In linux
we can read the value of variable starting by $ symbol at starting of variable name.
Example: Certkiller =test.txt
echo $ Certkiller : Displays the value of variable Certkiller
cat $ Certkiller : Displays the contents of file of $ Certkiller
In QUESTION ' is started which is incorrect syntax.
15.
To convert all uppercase letters in stream to lowercase, pipe the stream into which
Correct Answer
A. Tr A-Z a-z
Explanation
tr command translate the characters, that is given ranges of
characters, any time a character in range 1 is found, it is translated into the
equivalent character in range 2.
Example:
tr 'a-z' 'A-Z'
16.
Which of the following command would most likely be used to output a file inreverse? Choose TWO correct answers.
Correct Answer(s)
A. Tac
B. Pr
Explanation
file1 contains :
a
b
c
and file2 contains
1
2
3
if you use tac file1 file2
Output is like:
c
b
a
3
2
1
pr command reformat the text for printing.
17.
You have a file with the following contents: A. allan B. bart C. ceasar D. alicia E. beatrice F. ceciliaWhat single command could you use to list the file contents in reverse order? (Includeonly the command without options or arguments)
Correct Answer(s)
tac
Explanation
file1 contains :
a
b
c
and file2 contains
1
2
3
if you use tac file1 file2
Output is like:
c
b
a
3
2
1
18.
You have a file with the following contents: A. allan B. bart C. ceasar D. alicia E. beatrice F. CeciliaWhat single command could you use to list the file contents in reverse order? Pleaseinclude only the command without options or arguments.
Correct Answer(s)
tac
Explanation
tac command concatenate and print files in reverse order.
Example:
file1 contains :
a
b
c
and file2 contains
1
2
3
if you use tac file1 file2
Output is like:
c
b
a
3
2
1
19.
What command will easily convert tabs in files to spaces?
Correct Answer
B. Expand
Explanation
The command "expand" can be used to easily convert tabs in files to spaces.
20.
Which of the following would do the same as the command cat < file1.txt > file2.txt?
Correct Answer
B. Cat file1.txt >file2.txt
Explanation
cat file1.txt >file2.txt cat command takes input from the file file1 and
redirect the output into the file file2 which is similar to cat file2.txt.
21.
Which of the commands will show you only the middle 10 lines of a 30 line text filenamed textfile?
Correct Answer
B. Head -n 20 textfile | tail
Explanation
head command displays default 10 lines from the top of file and tail
displays the default 10 lines from the bottom of file.
To display the custom number of lines:
head -n 20 filename
To displays the contents of file from middle:
head -n 20 a | tail : displays middle 10 lines
head -n 30 a | tail : displays middle 10 lines from 20-30.
22.
What command will show the first 10 lines of a file by default?
Correct Answer
A. Head
Explanation
ead command by default displays 10 lines from the top of file and tail
command by default display 10 lines from the bottom of file.
head -n or --lines 20 filename : Displays 20 lines from the top of file.
23.
What command will show the last 10 lines of a file by default?
Correct Answer
A. Tail
Explanation
head command by default displays 10 lines from the top of file and tail
command by default display 10 lines from the bottom of file.
tail -n or --lines 20 filename : Displays 20 lines from the top of file.
24.
Your lead sysadmin has asked you to add a second NIC to a Linux machine.Which of the following commands would be best to determine which interrupts arecurrently in use on this machine?
Correct Answer
B. Cat /proc/interrupts
Explanation
The Linux /proc Directory is a Virtual Filesystem provided by linux
kernel. /proc contains files and directories that let system administrators and
programmers access system information.
The file /proc/interrupts file contains information on interrupts and IRQs. First Ethernet
card device name is eth0, second Ethernet card device name is eth1 ..., to identify that
dev will conflict or not , see the contains of file. Already eth0 is appeared or not ?
Here is the output of /proc/interrupts
CPU0
0: 380893 XT-PIC timer
1: 843 XT-PIC i8042
2: 0 XT-PIC cascade
5: 0 XT-PIC uhci_hcd
8: 1 XT-PIC rtc
11: 48 XT-PIC Intel 82801AA-ICH, eth0
14: 6086 XT-PIC ide0
NMI: 0
ERR: 0
For a multi-processor machine, this _le may look slightly different:
CPU0 CPU1
0: 1366814704 0 XT-PIC timer
1: 128 340 IO-APIC-edge keyboard
2: 0 0 XT-PIC cascade
8: 0 1 IO-APIC-edge rtc
12: 5323 5793 IO-APIC-edge PS/2 Mouse
13: 1 0 XT-PIC fpu
16: 11184294 15940594 IO-APIC-level Intel EtherExpress Pro
10/100 Ethernet
20: 8450043 11120093 IO-APIC-level megaraid
30: 10432 10722 IO-APIC-level aic7xxx
31: 23 22 IO-APIC-level aic7xxx
NMI: 0
ERR: 0
Appeared Number of CPU, Number of Ethernet card.
25.
Which of the following will copy file1.txt to file2.txt? Choose Two.
Correct Answer(s)
A. Cat file1.txt > file2.txt
D. Cp file1.txt file2.txt
Explanation
We can redirect the standard output into the file using the redirect (>)
symbol.
Example: ls -l >result : Redirects the standard output of ls -l command into the result file.
Similarly cat redirect the contents of one file into another.
cat file1 >file2 : cat reads the contents of file1 and creates the new file file2, which
contains the text of file1. cp (copy) command also copy the file.
Similarly you can append into the existing file using append (>>) symbol.
26.
What utility would use to remove/display columns from each line of a file?
Correct Answer
C. Cut
Explanation
cut command displays the specific column from the text file.
Example: cut -d: -f 1 /etc/passwd : Displays the first column from the file /etc/passwd
where -d means delimeter and -f means field number.
27.
After executing the following command line, what will be the contents of the filemyout.txt?echo \" Certkiller \" | cat > myout.txt
Correct Answer
B. " Certkiller "
Explanation
The contents of myout.txt will be Certkiller .
echo command displays into the standard output and cat command redirects the output of
echo into the file myout.txt
28.
You wish to cut the 3rd and 7th fields from a colon (:) delimited text file called 'my Certkiller ' and display them on the screen. Type the command that would do this?
Correct Answer
cut -d : -f 3,7 my Certkiller
cut -d: -f3,7 my Certkiller
cut -f3,7 -d: my Certkiller
cut -f 3,7 -d : my Certkiller
Explanation
cut command displays the specific column from the text file.
Example: cut -d: -f 1 /etc/passwd : Displays the first column from the file /etc/passwd
where -d means delimeter and -f means field number. To display the contents of multiple
column, comma separator can use.
29.
What command returns the first few lines of a given file?
Correct Answer
head
Explanation
head command displays the few lines from the top of file. By default
displays 10 lines.
Example: head myfile
head -n or --lines 20 myfile
30.
What command is used to display a file in octal format?
Correct Answer
od
Explanation
od filename
31.
You need to replace all instances of the word Certkiller with Certkiller in a file calledfile.txt, and send the output to a file named Certkiller .txt. Type the simplest commandstring to accomplish this.
Correct Answer
sed 's/ Certkiller / Certkiller /g' file.txt > Certkiller.txt
Explanation
sed also called the stream editor, generally use for find and replace.
sed 's/ Certkiller / Certkiller /g' file.txt > Certkiller .txt means search the Certkiller and
replace into Certkiller globally and redirects the replced output into Certkiller .txt file.
32.
You want to redirect the last 30 lines of a file to another file.What single command would best fit your needs?
Correct Answer
tail
Explanation
tail command displays the few lines from the bottom of file. By default
it displays the 10 lines.
Example
tail filename
tail -n 30 filename >anotherfilename : Redirects the last 30 lines into another file.
33.
Which line below would count the total number of lines with the word " Certkiller " in/var/log/maillog?
Correct Answer
D. Cat /var/log/maillog | grep ' Certkiller ' | wc -l
Explanation
grep command displays the lines matching the criteria.
Example: grep root /etc/passwd : displays all lines having root pattern.
Wc command counts the lines, words and characters into the file.
Example: wc filename : displays number of lines, words and characters
wc -l filename : displays only the number of lines from the file.
Were Pipe symbol helps to combine the command, which sends the output of first
command as input to second command.
Answer D is correct because cat reads the contents of /var/log/maillog and sends the
standard output to grep command, g rep command filters the output only the lines having
Certkiller pattern sends to wc which counts the number of lines containing the Certkiller
pattern.
34.
To prevent a command run as root from sending both standard out (stdout) andstandard error (stderr) to any terminal or other file or device, which of thefollowing strings should be appended to the command?
Correct Answer
C. >/dev/null 2>&1
Explanation
Command> file à Redirect the standard Output to file.
Command>>file à Append the standard output to file.
Commandfile à Redirect the standard error to file.
Command 2>>file àAppend the Standard Error to file.
35.
Which of the following sed commands will replace all instances of thestring foo with the string foobar changing the file file1.txt in place?
Correct Answer
A. Sed 's/foo/foobar/g' file1.txt
Explanation
ed called Stream Editor, usually used to search and replace the string pattern in
file.
Syntax: sed 's/whattofind/replacewith/globally' filename
Example: sed 's/cat/dog/g' test àIt will replace all cat occurance to dog fron test file.
36.
What command will print a list of usernames (first column) and theircorresponding user id (uid, third column) from /etc/passwd?
Correct Answer
A. Cut -d: -f 1,3 /etc/passwd
Explanation
Cut command helps to display certain fields value from file. In cut
command -d option is used to specify the filed delimiter and -f specify the filed
number.
37.
What command will remove duplicate lines from a sorted file?
Correct Answer
C. Uniq
Explanation
uniq - remove duplicate lines from a sorted file
38.
Ýou have a text file with tab-separated values, but your application needs themspace-separated. What command would you use from the Bash shell to achieve this?Please fill in the command only, without any options.
Correct Answer
expand
Explanation
The expand command is used to convert from tab to space.
Example: expand -t 2 test à It will convert the tab into two spaces.
39.
Which command is used to dump files in octal format?
Correct Answer
A. Od
Explanation
nswer A is correct. od command dump files in octal and other
formats. Example: od test it will display the all contents of file in octal format.
40.
You enter the command date +%M. Wat does the output show you?
Correct Answer
D. The current minute
Explanation
date command displays the current date and time information as well
as we can set new date and time to system by supplying -s option.
To display time: date +%T
To display Minute: date +%M
To display Month : date +%m
%% a literal %
%a locale's abbreviated weekday name (Sun..Sat)
%A locale's full weekday name, variable length (Sunday..Saturday)
%b locale's abbreviated month name (Jan..Dec)
%B locale's full month name, variable length (January..December)
%c locale's date and time (Sat Nov 04 12:02:33 EST 1989)
%C century (year divided by 100 and truncated to an integer)
[00-99]
%d day of month (01..31)
%D date (mm/dd/yy)
%e day of month, blank padded ( 1..31)
%F same as %Y-%m-%d
%g the 2-digit year corresponding to the %V week number
%G the 4-digit year corresponding to the %V week number
%h same as %b
%H hour (00..23)
%I hour (01..12)
%j day of year (001..366)
%k hour ( 0..23)
%l hour ( 1..12)
%m month (01..12)
%M minute (00..59)
%n a newline
%N nanoseconds (000000000..999999999)
%p locale's upper case AM or PM indicator (blank in many locales)
%P locale's lower case am or pm indicator (blank in many locales)
%r time, 12-hour (hh:mm:ss [AP]M)
%R time, 24-hour (hh:mm)
% seconds since a 00:00:00 1970-01-01 UTCa (a GNU extension)
%S second (00..60); the 60 is necessary to accommodate a leap sec-
ond
%t a horizontal tab
%T time, 24-hour (hh:mm:ss)
%u day of week (1..7); 1 represents Monday
%U week number of year with Sunday as first day of week (00..53)
%V week number of year with Monday as first day of week (01..53)
%w day of week (0..6); 0 represents Sunday
%W week number of year with Monday as first day of week (00..53)
%x locale's date representation (mm/dd/yy)
%X locale's time representation (%H:%M:%S)
%y last two digits of year (00..99)
%Y year (1970...)
%z RFC-2822 style numeric timezone (-0500) (a nonstandard extension)
%Z time zone (e.g., EDT), or nothing if no time zone is determinable
41.
Which of the following commands can you use to rename a file in Linux?
Correct Answer
B. Mv
Explanation
mv file1 file2 : Which renames the file1 to file2.
mv file1 /tmp : Which moves the file file1 into /tmp
mv file1 /tmp/file2 : Which moves as well as rename the file file1
42.
What dose the command cd~foo do?
Correct Answer
C. It will take you to the home directory of the user "foo"
Explanation
~ symbol represents the user's home directory.
Example: cat ~/test.txt : Which reads the file resident in user's home directory.
cd ~/foo : Which enters into the foo directory resident into the user's home directory.
43.
As root you have navigated to directory /B. You wish to move all of the files anddirectories from directory /A to directory /B. Which of the following options wouldbe the most appropriate command line to execute this task?
Correct Answer
B. Mv -f /A/* .
Explanation
mv command is used to move as well as to rename the file.
Example:
mv file1 file2 : Which renames the file1 to file2.
mv file1 /tmp : Which moves the file file1 into /tmp
mv file1 /tmp/file2 : Which moves as well as rename the file file1
-f option of mv command is used for forcely move.
44.
One of the lines in the output from the command 'ls -l/home/pomes' is:drwxrwsr-x 3 devel poms 1024 Oct 22 16:28 fooThe output from the command groups bubba is:bubba : bubba poms actsIf user bubba executes the command touch/home/poms/foo/bar, which TWO of thefollowing must be true?
Correct Answer(s)
A. The group for /home/poms/foo/bar will be poms.
C. The owner for /home/poms/foo/bar will be bubba.
Explanation
See carefully on output that, SGID bit is set on directory and group
owner of that directory is poms. When SGID bit is set on directory, automatically
all new creating files/directories group owner is same as parent directory means
same as foo.
To set the SGID bit:
chmod g+s directory
To Remove the SGID bit:
chmod g-s directory
So, when bubba user executes the touch /home/poms/foo/bar the group owner
automatically poms and owner user is that user who executed the command means
bubba.
45.
Which command removes all subdirectories in /tmp, regardless ofwhether they are non-existent or in use?
Correct Answer
D. Rm -rf /tmp/*
Explanation
rm command removes the files/directorires.
Syntax: rm [options] file/directory
-f : forcely
-r : Recursively
-i : Interactively.
rm -rf /tmp/* : Which removes all files as well as directories forcely from /tmp directory.
46.
A directory contains the following files:#lsratas saran jacaw cabal cabinYou issue the command "ls | grep .a[^b]a.", what files are returned by thecommand? Choose all that apply.
Correct Answer(s)
A. Ratas
B. Jacaw
C. Saran
Explanation
Remember the wildcard Character in string processing
* : Zero or more character
. : Any Single Character
[a-z] : Any single Character from the range
[^a-z] : Any single Character except from the range
ls | grep .a[^b]a. means that word having five characters, starting with any character but a
should be in second position, third position shouldn't be b and fourth character should be
a and any single character in fifth position.
grep command is use to process the string with different pattern.
47.
You need to display all files in the current directory that start with a "a" and endwith a "v", regardless of their length or use of delimiters. Choose the best answer.
Correct Answer
A. Ls a*v
Explanation
Wildcard characters :
* Zero or more character
? Any Single Character
[a-z] Any Single Character from the range
[^a-z] Any Single Character except from the range
ls a*v means list all files/directories starting with a character and ended with v character.
48.
You want to move all files in /dir1 to /dir2 that begin with a and end with v. What isthe correct command to do this?
Correct Answer
A. Mv /dir1/a*v /dir2
Explanation
Wildcard characters :
* Zero or more character
? Any Single Character
[a-z] Any Single Character from the range
[^a-z] Any Single Character except from the range
mv /dir1/a*v /dir2 means all the contents of /dir1 starting name with a character and
ended with v character will move into the /dir2 directory.
49.
You wish to copy the full contents of the /home/jack directory and all subdirectoriesto the /home/bill directory.Type in the simplest command to do this.
Correct Answer
cp -r /home/jack/* /home/bill
Explanation
cp command copies files/directorires.
Syntax: rm [options] file/directory
-f : forcely
-r : Recursively
-i : Interactively.
cp -r /home/jack/* /home/bill : Which copy all the contents of /home/jack into the
/home/bill.
50.
You wish to move all files and directories from within /home/john to the directory/home/certkiller.Type in the command line that would do this?
Correct Answer
mv /home/john/* /home/certkiller
mv /home/john/* /home/certkiller/
Explanation
mv command is used to move as well as to rename the file.
Example:
mv file1 file2 : Which renames the file1 to file2.
mv file1 /tmp : Which moves the file file1 into /tmp
mv file1 /tmp/file2 : Which moves as well as rename the file file1
mv /home/john/* /home/certkiller : Moves all the contents of /home/john into
/home/certkiller.