2.
What 3 letter command will show you the values set by the /etc/profile script file forthe entire system?
Explanation
env command is used to display the all environmentall variables as
well as values. Where /etc/profile file is used to set the value into the environmental
variable.
3.
Type just the name of the file in a normal user's home directory that will set theirlocal user environment and startup programs on a default Linux system.
Explanation
~/bash_profile and ~/bashrc file for user specific settings, common to
place variable settings, aliases, commands that places output to the screen, such as
date command, should go in .bash_profile not .bashrc.
4.
You wish to turn off the shell option that stops you overwriting exisiting files. Typethe command in that will do this including switches.
Explanation
noclobber global option controls the file overwriting to an existing file.
set -o : Lists all options with on/off status
set -o noclobber : Set on the noclobber and restrict to use the redirect (>) symbol.
set +o noclobber : Set off the noclobber and allow to use the redirect (>) symbol.
5.
What 3 letter command will show you the values set by the /etc/bashrc script file forthe entire system?
Explanation
set command is used to display the all shell as well as environmental
variables as well as variables values. env command is used to display the all
environmentall variables as well as values.
6.
What three letter command in Bash will display all environment variables?
Explanation
env command displays all environmental variables as well as it's value. Where set is another command displays all shell variables.
7.
What is the name and full path of the file that contains the system wide aliases andfunctions for the default Linux shell?
Explanation
/etc/bashrc file sets the system wide aliases, functions as well as default
permission umask value for root as well as non-root user.
8.
What is the name of the file that runs on user logout, usually set to clear the screen?
Explanation
~/bash_logout file execute when exiting a login shell, Useful for
running programs automatically at logout ie, clear the screen, make backup files,
delete temporary files, display date and time etc
9.
You wish to set your shell options so that the output from a redirect will NOToverwrite an existing file. Type the command including switches.
Explanation
noclobber global option controls the file overwriting to an existing file.
set -o : Lists all options with on/off status
set -o noclobber : Set on the noclobber and restrict to use the redirect (>) symbol.
set +o noclobber : Set off the noclobber and allow to use the redirect (>) symbol.
10.
What is the name and full path of the file that contains the system wideEnvironment variables and Startup programs?
Explanation
The /etc/profile shell scrpt is first startup script run when a login shell
is started. It only runs for the login shells, non-login shells do not invoke this script.
This script will set a series of variables including PATH, USER, LOGNAME, MAIL,
HOSTNAME, HISTSIZE, INPUTRC as well calls the startup programs to execute.
11.
You want to repeat the last command you entered. How would you do this?
Explanation
!! re-excutes the last entered command.
!n : executes the command from history n numbered in history list. You can use the
history command to list all history commands.
12.
Type in the command line that will execute cmd2 regardless of exit status of cmd1.Assume these commands are on the systems PATH and the command names arecmd1 and cmd2.
Correct Answer
cmd1;cmd2
cmd1 ; cmd2
cmd1; cmd2
cmd1 ;cmd2
Explanation
symbol helps to separate the multiple commands. It never checks the
retrun value so not like the logical operator.
Example: cat a;ls;date : three commands are combined first executes cat command then ls
and then date.
13.
You want to repeat a command that began with the letters 'ab'. How would you dothis?
Explanation
bash shell stores the history commands later we can re-execute the
commands from the history.
!! : To repeat the last entered command
!n : To execute the command from history having n numbered.
!-n : To execute the command entered n command back
!c : To execute the command started from history started by c character.
14.
Type in just the name of the command that allows you to edit the command history,and will execute the contents of the buffer when exited.
Correct Answer
fc
Explanation
fc command allows the history command to edit as well as when you
exit from the edit mode, It will executes the command.
15.
What command on an rpm-based system will upgrade any existing packages on asystem, but not add any packages? Type just the command and switch(es).
Correct Answer
rpm -F
Explanation
-U or -F both option is used to upgrade the package. -U option upgrade if
lower version is installed otherwise install the new version package but -F option only
upgrade if lower version package installed. As well as it doesn't add(install) any other
packages.
16.
You wish to find out more information on a file e.g. Last accessed, Modifiedchanged, Inode. What is the simplest command that would show this informationfor a file called certkiller?
Correct Answer
stat certkiller
Explanation
stat command displays the meta information of file.
Example:
stat file1
File: file1
Size: 5 Blocks:8 IO Block: 409 regular file
Device: 30ch/780d Inode: 16217 Links: 2
Access: (0644/-rw-r-r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2006-04-16 12:50:44.000000000
Modify: 2006-04-16 12:50:44.000000000
Change: 2006-04-16 12:50:44.000000000
17.
Type in just the name of the default file that the command line history is stored infor a logged in user.
Correct Answer
.bash_history
Explanation
One environmental variable named HISTFILE carrying the name of
file to store the history command. By default the history commands stores in
~/bash_histroy.
You can displays using the variable:
echo $HISTFILE
18.
On a default Linux system, what is the name of the file that sets users aliases andfunctions?
Correct Answer
.bashrc
Explanation
~/bash_profile and ~/bashrc file for user specific settings, common to
place variable settings, aliases, commands that places output to the screen, such as
date command, should go in .bash_profile not .bashrc.
19.
You want to run three commands one after the other, but don't care what exit theyhad. What command line would do this?
Correct Answer
A. Cmd1; cmd2; cmd3
Explanation
; symbol helps to separate the multiple commands. It never checks the
retrun value so not like the logical operator.
Example: cat a;ls;date : three commands are combined first executes cat command then ls
and then date.
20.
You want to view a listing of previously entered commands. What command wouldyou use?
Correct Answer
A. History
Explanation
history command lists all commands in history. All history commands
stored in ~/.bash_history file.
21.
You want to search the file myfile for all occurrences of a string containing at leastfive characters, where character number 2 and 5 are "a" and character number 3 isNOT "b". Which command would you use?
Correct Answer
A. Grep .a[^b].a myfile
Explanation
String Processing Tools like grep, sed, awk uses wildcard characters.
. à Any Single character from the range
[abc] à Any Single Character from the set
[a-c] à Any Single Character from the Range
[^abc] à Any Single Character except from the set.
[^a-c] àAny Single Character except from the range.
According to QUESTION, in 2nd and 5th position must be a and in 3rd position not b.
B. . means any single character in first postion., a means a must be in second postions,
[^b] means b must not be in third postion, . means any single character in fourth position
and a in fifth position.
22.
You are in your home directory. You have made changes to your .bash_profile andincorporated a modified PATH variable. Type in the command that will reread the .bash_profile and set the changes you have made.
Correct Answer
source .bash_profile
.bash_profile
Explanation
~/.bash_profile executes when loggin shell provided users login. So, to
bring the changes made on ~/bash_login either user should re-login or manually
executest the shell scripts file ~/.bash_profile.
23.
In order to append the output of ls to a file called bazz, which of the followingcommand lines would you use?
Correct Answer
A. Ls >> bazz
Explanation
Common Redirection Operator:
Command >file à Redirect the Standard Output of command into file.
Command >>file à Append the Standard Output of command into file.
Command file à Redirect the error message to file.
Command 2>>file à Append the error message to file.
24.
What command would execute cmd1 followed by cmd2, regardless of the exit statusof cmd1?
Correct Answer
A. Cmd1 ; cmd2
Explanation
; symbol helps to separate the multiple commands. It never checks the
retrun value so not like the logical operator.
Example: cat a;ls;date : three commands are combined first executes cat command then ls
and then date.
25.
You see following output while trying to install an updated package:[root@example pub]# rpm -i gthumb-2.2.0.i386.rpm package gthumb-1.0.1.i386.rpm is already installed.Which command will allow you to install the updated version?
Correct Answer
A. Rpm -U gthumb-2.2.0.i3S6.rpm
Explanation
Syntax of rpm command
rpm [options] package
-i à Install
-U àUpgrade package if lower version is installed otherwise install the new package.
-F à Upgrade package if only lower version is installed.
26.
Type the command line to check the installed package mypackage for anyconfiguration file changes since install?
Correct Answer
rpm -V mypackage
Explanation
Verifying a package compares information about the installed files in
the package with information about the files taken from the package metadata
stored in the rpm database. Among other things, verifying compares the size, MD5
sum, permissions, type, owner and group of each file. Any discrepancies are
displayed.
To verify the package:
rpm -Va or -verify -a packagename
27.
You want to repeat command number 3 in your history. How would you do this?
Explanation
bash shell stores the history commands later we can re-execute the
commands from the history.
!! : To repeat the last entered command
!n : To execute the command from history having n numbered.
!-n : To execute the command entered n command back
!c : To execute the command started from history started by c character.
28.
You have just typed the following three commands and got the following output:prompt> echo $PATH/usr/bin:/usr/local/bin:usr/sbin:opt/kde/binprompt> pwd/home/anna/gamespromt> lsgame1 game2 game3You want to run the program game1, but get the response that it is not found.What did you forget to do?
Correct Answer
A. To type ./game1 rather than game1.
Explanation
/home/anna directory is not set on path. So to execute the program
from the directory not set in path, should execute by givin full path or use the ./ .
If you are in /home/anna use ./ means under current directory.
To set the directory on path
PATH=$PATH:/home/anna/
29.
What is the correct format for a proper command in the shell?
Correct Answer
A. Command Option Argument
Explanation
Syntax of executing the command in shell is
command [options] argument
example: ls -l /etc : Where ls is command, -l is option and /etc/ is the parameter or
argument for ls command.
30.
Which command will print to standard out only the lines that do notbegin with # (pound symbol) in the file foobar?
Correct Answer
A. /bin/grep -v ^# foobar
Explanation
rep stands for general regular processor, used to prints all lines
where pattern matched.
Achor symbol used by String Processor tools like sed, awk and grep
^ àLine begins with
$ à Line ends with
\word end with
-v option in grep is non matching.
31.
Which of the following will allow both the commands to execute, regardless of theirindividual exit status?
Correct Answer
A. Command1 ; command2
Explanation
; helps to execute the multiple commands in order.
example: clear;ls : First execute clear then ls.
&& is AND logical Operator
|| is OR logical operator
! is NOT logical Operator
32.
Which keystrokes will move the cursor 3 lines down and 4 characters to the right?
Explanation
Cursor Movement in vi editor:
h : Left
j : down
k : up
l : right
Example: when you press the h key it moves the cursor in left of one character.
3h: moves the cursor in 3 characters left
33.
In Bash, inserting "1>&2" after a command redirects
Correct Answer
A. Standard output to standard error
Explanation
Statndard Input use < symbol and 0 is the integer value
Standard Output use > symbol and 1 is the integer value
Standard Error use 2> symbol and 2 is the integer value
Example:
find / - name passwd >allresult 1>&2 : Redirects all standard output as well as standard
error to allresult file. Where & is the logical operator.
34.
Which shell built-in command can be used to create a shortcut orpseudonym for a longer command? Assume a modern bourne-like shell,such as bash.
Explanation
Alias command is used to create like shortcut of long command.
Example: alias back="tar -cvf mytar.tar /root/*", here back will be the alias (shortcut) of
complete "tar -cvf mytar.tar /root/*" command.
35.
What switch is used with the usermod command to change a user's secondary groups?
Explanation
Explanation: When we create the user, by default user belongs to it's private group
as a primary group. After adding the user into the system, if you want to change:
usermod -g groupname username
To make user belongs to secondary group:
usermod -G groupname username
36.
Your Linux machine has 2 monitors. Your second monitor is configures as thesecond screen of the first display. If you want the "netscape" program to bedisplayed on your second monitor, what command should you use before startingnetscape?
Correct Answer
A. Export set DISPLAY=:0:1; netscape
Explanation
Answer C is correct because:
export set DISPLAY=192.168.0.1:0 : means displays on first monitor of 192.168.0.1
host.
export set DISPLAY=192.168.0.1:1 : means on second monitor of 192.168.0.1 host.
37.
Which command will output the exit status of the previous command (a 1 or a 0)?
Correct Answer
A. Echo $?
Explanation
$? is used to displays to catch the return value. When command
executes it returns 0 or other value. 0 means command is executed successfully and
other value means executed with error.
Example:
function test1()
{
echo "From test1 function"
return 1
}
echo "Retrun Value is " $?
38.
You have to test a new kernel version. Which of the following is thebest way to add a new linux kernel in your system?
Correct Answer
A. Rpm -Uvh kernel_package
Explanation
Syntax of rpm command
rpm [options] package
-i à Install
-U àUpgrade package if lower version is installed otherwise install the new package.
-F à Upgrade package if only lower version is installed.
39.
Which of the following will cause command2 not to execute if command1 fails?
Correct Answer
A. Command1 && command2
Explanation
&& is the Logical AND operator, whiche means second command
executes if first command excuted successfully.
Example: cat a && ls : if cat a executes successfully then only ls command will execute
other wise exit from the cat command.
40.
You have two shell scripts, foo and bar. You wish to have bar execute if foo returnsan exit status of 0. Select the correct command:
Correct Answer
A. Foo && bar
Explanation
&& à Logical AND Operator
|| à Logical OR Operator
! à Logical NOT Operator
Correct Answer is C because first tried to execute foo. If foo executes without any error
then executes bar. If any error occurs in foo then exit from command.
41.
What option is used with the useradd command to specify the user's home directory?
Explanation
useradd command is used to add the user in the system. By default it
creates the user's home directory in /home if you want to specify the user's home
directory in different location use the -d and name of directory with path.
Example:
useradd -d /var/user1 user1
useradd -s /bin/sh user1 : Sets the sh shell as default shell to user user1
After adding the user use the usermod command to change the user's home directory,
login shell, account lock, account unlock etc.
42.
How can you execute two commands, the second one being executed only if the firstreturns a nonzero (program execution failed) exit status?
Correct Answer
A. Command1 || command2
Explanation
|| is called the Logical OR Operator, which means either in sense eiher
first or second. If first command exited with error then only second executes.
Example: cat a || ls : if cat command return the error code then start to execut the ls
command.
Remember that if command executes successfully then it returns zero value and if
command executes with error it returns the error code.
43.
Which command will print line numbers before each line in a file?
Explanation
cat command is used to display the contents of file in standard output.
Syntax: cat [option] filename.
Options: -n, -b à Display the line number before each line
-A à Show all characters including control characters.
-s à Squeeze multiple adjacent blank lines into one line
44.
You are adding a new user. You want to create the user's home directory only if thedirectory does not exist. Which of the following would accomplish this?
Correct Answer
A. Useradd -m
Explanation
When we issue the useradd command, it creates the user by creating
the user's home directory into /home.
If you create the user's home directory into different location:
useradd -d directory username
If you want to check whether user's directory is already created or not :
useradd -m
45.
You want to preview where the package file,apache- xml.I386.rpm, will install its files before installing it. Whatcommand do you issue?
Correct Answer
A. Rpm -qpl apache-xml.i386.rpm
Explanation
rpm -qpl apache-xml.i386.rpm
46.
You have a dual-head workstation with two monitors. Your secondary monitor isdefined as the second screen of the first display. You want to start Mozilla anddisplay its window on the second display. Which command line would you use toachieve this?
Correct Answer
A. Export SECOND=1; mozilla
Explanation
Answer C is correct because:
export set DISPLAY=192.168.0.1:0 : means displays on first monitor of 192.168.0.1
host.
export set DISPLAY=192.168.0.1:1 : means on second monitor of 192.168.0.1 host.
47.
When a user executes the command "ps ax", what is shown on the console? Chooseall that apply.
Correct Answer(s)
A. Processes without controlling terminals
A. All regular processes
Explanation
Process are running in two different methods: one is terminal
dependent (means controlled by terminal ) and second is terminal independent
(terminal independent).
ps -a: All process not including not controlled by terminal
ps -x : All process including not controlled by terminal
48.
Which command will allow you to find a specific installed package?
Correct Answer
A. Rpm -qv rpmname
Explanation
To query the package whether, package is installed or not :
rpm -qv rpmname
example: rpm -qv ncurses à It shows rpm fullname, version if installed otherwise it will
display package is not installed.
Installed package options:
rpm -qa à Lists all installed packages
rpm -qf filename à Shows owning package
rpm -qi rpmname à General Information of Package
rpm -ql rpmname à Shows all files owning by this package
49.
You have an updated RPM called screensaver-1.1.i386. rpm. Youhave version 1.0 installed. Using RPM, how do you view the changelog ofthis file to see if you should install the update?
Correct Answer
A. Rpm --changelog screensaver-1.1.i386.rpm
Explanation
Syntax of rpm command
rpm [options] package
-i à Install
-U àUpgrade package if lower version is installed otherwise install the new package.
-F à Upgrade package if only lower version is installed.
-l à List all files belongs to package
-p à Package Name
-q à Query
--changelog à Display change information for the package.