57564-66233-13787-31324 web page maker serial no

Basic Theory Questions
1. What is UNIX?
It may sound as a trivial question but you!d be ama"ed #ust $ow many people
%ail to give a &lear de%inition be&ause simply stating t$at '(ni) is an operating
system* is not likely to impress t$e interviewer+ ,$e &orre&t answer s$ould
look somet$ing like t$is-
(.I/ is a multi-user multitasking-optimi"ed operating system t$at &an run on
various $ardware plat%orms+
2. How is UNIX different from Linu?
0inu) is basi&ally an open-sour&e &lone o% (.I/ so w$ile a lot o% similarities
between t$e two operating systems do e)ist t$ere are also a lot o%
di%%eren&es+ ,$e main advantage o% (.I/ is t$at all t$e &ore &omponents o%
t$e operating system &ome %rom t$e same vendor w$i&$ means greater
overall stability and better so%tware support %rom vendors+ (.I/ releases are
more stable and &onsistent t$an 0inu) releases making (.I/ t$e better
&$oi&e %or enterprise use+
!. What is a "erne#?
,$e kernel is t$e program t$at a&ts as a middle layer between so%tware and
$ardware+ 1$en a program requires a&&ess to &ertain resour&es or
pro&essing power t$e kernel is responsible %or sending t$e &orre&t signals to
t$e 23( and managing all ot$er running programs and servi&es so t$at t$e
resour&es are &orre&tly allo&ated and no &on%li&ts o&&ur+
$. What is the difference %etween mu#ti&user and mu#ti&tas"in'?
4ulti-tasking means t$at a user &an run multiple tasks simultaneously on a
single ma&$ine w$ereas multi-user means t$at multiple users &an operate
simultaneously on a ma&$ine+
(. What is a UNIX she##?
5 (.I/ s$ell is an inter%a&e t$at a&ts as a &ommand interpreter translating
user input into ma&$ine-understandable language and t$en passing it to t$e
kernel %or e)e&ution+
6n&e you a&e t$e basi& stu%% t$e interviewer is most likely to move on to some
questions involving &ommands+ 7eep in mind t$at $is role is not to see $ow
good you are at memori"ing &ommands but rat$er $ow well you understand
w$at t$ose &ommands do and determine your ability to &$oose t$e rig$t
&ommand in a &ertain situation+ In order to su&&ess%ully pass t$is part o% t$e
interview make sure you %ormulate your answers as &lear and as detailed as
possible+ 8ou s$ould &onsider ta"in' a course to im)ro*e your
communication s"i##s prior to t$e interview+
UNIX +ommands
1. What command can you use to dis)#ay the first ! #ines of tet from a
fi#e and how does it wor"?
,$ere are two &ommands t$at &an be used to &omplete t$is task-
head -3 test.txt 9 t$is uses t$e '$ead* &ommand along wit$ t$e '-3*
parameter t$at indi&ates t$e number o% lines to be displayed:
sed ‘4,$ d’ test.txt 9 t$is &ommand uses t$e ;ed te)t editor to per%orm
t$e task+ I% t$e &ommand was simply 'sed test+t)t* t$e w$ole %ile would $ave
been displayed: $owever in our e)ample t$e delete parameter was used <d=
to make ;ed delete everyt$ing between t$e 4t$ and t$e last line <de%ined by
t$e > parameter= leaving only t$e %irst 3 lines o% t$e %ile+ It is important to
mention t$at ;ed does not a&tually delete t$e lines %rom t$e %ile itsel% but #ust
%rom t$e output result+
2. How can you remo*e the ,th #ine from a fi#e?
,$e easiest way is by using t$e %ollowing &ommand- sed -i ‘7 d’ test.txt
(nlike t$e previous ;ed &ommand t$is &ommand also $as t$e '-i* parameter
w$i&$ tells ;ed to make t$e &$ange in t$e a&tual %ile+
!. What is )i)in'?
3iping is a te&$nique t$at &onsists o% entering two or more &onse&utive
&ommands separated by t$e pipe symbol '?*+ 6n&e t$e %irst &ommand is
e)e&uted its output will be used as input %or t$e se&ond &ommand t$e output
o% t$e se&ond &ommand will be used as input %or t$e t$ird and so on until t$e
w$ole &$ain o% &ommands is e)e&uted+
$. How do you re*erse a strin'?
8ou &an reverse a string by using a simple piping o% two &ommands-echo
“Mary” | rev
,$e %irst &ommand will generate t$e output '4ary* w$i&$ will be&ome t$e
input %or t$e rev &ommand making it return t$e reverse- 'yra4*+
(. How can you find out what a command does?
8ou use man <command-name> in order to bring up t$e manual page t$at
des&ribes t$e a&tions o% t$e spe&i%ied &ommand and any ot$er additional
options and parameters t$at &ommand mig$t $ave+
,$ese are some o% t$e (.I/ questions interviewers usually ask during basi&
interviews+ @owever i% t$e interview is %or a more te&$ni&al position you &an
e)pe&t to en&ounter questions t$at are more di%%i&ult: still t$ere is no reason to
pani& as (.I/ itsel% was &reated to be quite logi&al so a good knowledge o%
t$e basi& &ommands and a bit o% imagination &an $elp you get t$e #ob done+
2$e&k out t$is online &ourse to #earn how to use the UNIX command #ine to
'et the most out of -. X 9 yes t$e 6; / t$at runs on your 4a& w$i&$ is
(.I/ based by t$e way+ I% t$is doesn!t &onvin&e you t$at (.I/ &an be simple
and intuitive not$ing else will+
(1) What is a UNIX shell?
The UNIX shell is a program that serves as the interface between the user and the UNIX operating
system. It is not part of the kernel, but communicates directly with the kernel. The shell translates the
commands you type in to a format which the computer can understand. It is essentially a command line
interpreter.
Details:
Visual representation of the UNIX operating system environment:
List of commonly used UNIX shells:
· The Bourne Shell (sh)
· The C Shell (csh or tsch)
· The Bourne Again Shell (bash)
· The Korn Shell (ksh)
(2) What needs to be done before you can run a shell script from the command line prompt?
You need to make the shell script executable using the UNIX chmod command.
Details:
This chmod command makes the shell script fle "example1" executable for the user (owner) only:
$ chmod u+x example1
this syntax makes it executable for all (everyone):
$ chmod a+x example1
You can optionally use octal notation to set UNIX permissions using the chmod command (e.g., $ chmod
755 example1). This topic is beyond the scope of this article, but you can fnd more information by
entering "unix fle permissions chmod numeric notation" in your favorite search engine.
(3) How do you terminate a shell script if statement?
With f, which is "if" spelled backwards.
Details:
The shell script example below uses an if statement to check if a fle assigned to the variable myfle exists
and is a regular fle:
#!/bin/ksh
myfle=$1
if [ -f $myfle ]
then
echo "$myfle exists"
f
exit 0
(See shell scripting interview question #6 below if you do not know what $1 in this example means.)
(4) What UNIX operating system command would you use to display the shell's environment
variables?
Running the "env" command will display the shell environment variables.
Details:
Sample env command output:
$ env
HISTFILE=/home/lf/.history
PATH=/usr/local/bin:/bin:/usr/bin:/usr/X11R6/bin
SHELL=/bin/ksh
HOSTNAME=livefrelabs.com
USER=lf
MAIL=/var/spool/mail/lf
HOME=/home/lf
HISTSIZE=1000
It would also be good to understand the purpose of the common shell environment variables that are
listed in the env command output.
(5) What code would you use in a shell script to determine if a directory exists?
The UNIX test command with the -d option can be used to determine if a directory exists.
Details:
The following test command expression would be used to verify the existence of a specifed directory,
which is stored in the variable $mydir:
if [ -d $mydir ]
then
command(s)
f
If the value stored in the variable mydir exists and is a directory fle, the command(s) located between
then and f will be executed.
You can consult the test command's man page ("$ man test") to see what test command options are
available for use.
(6) How do you access command line arguments from within a shell script?
Arguments passed from the command line to a shell script can be accessed within the shell script by
using a $ (dollar sign) immediately followed with the argument's numeric position on the command line.
Details:
For example, $1 would be used within a script to access the frst argument passed from the command
line, $2 the second, $3 the third and so on. Bonus: $0 contains the name of the script itself.
(7) How would you use AWK to extract the sixth feld from a line of text containing colon (:)
delimited felds that is stored in a variable called passwd_line?
echo $passwd_line | awk -F: '{ print $6 }'
Details:
Consider this line of text stored in the variable $passwd_line -
$ echo $passwd_line
mail:x:8:12:mail:/var/spool/mail:
$
(Background: The lines in the system passwd fle are delimited (separated) by a colon (:)...
$passwd_line contains a single line from the passwd fle.)
The output of the echo command is piped to AWK. The -f option for the awk command informs awk of
what the feld separator is (colon in this example), and print $6 instructs awk to print the 6th feld in the
line.
(8) What does 2>&1 mean and when is it typically used?
The 2>&1 is typically used when running a command with its standard output redirected to a fle. For
example, consider:
command > fle 2>&1
Anything that is sent to command's standard output will be redirected to "fle" in this example.
The 2 (from 2>&1) is the UNIX fle descriptor used by standard error (stderr). Therefore, 2>&1 causes the
shell to send anything headed to standard error to the same place messages to standard output (1) are
sent...which is "fle" in the above example.
To make this a little clearer, the > in between "command" and "fle" in the example is equivalent to 1>.
Before you continue reading... Has this article been helpful to you? Would it beneft others? If you
answered "yes" to either question, kindly share the page.







MORE READERS = MORE FUTURE ARTICLES
Thank you for sharing.
(9) What are some ways to debug a shell script problem?
Although this is somewhat dependent on what the problem is, there are a few commonly used methods
for debugging shell script problems.
One method, which is frequently used across all programming languages, is to insert some debug
statements within the shell script to output information to help pinpoint where and why the problem is
being introduced.
Another method specifc to shell scripting is using "set -x" to enable debugging.
Details:
Consider the following shell script example (notice that "set -x" is commented out at this time):
#!/bin/ksh
#set -x
i=1
while [ $i -lt 6 ]
do
print "in loop iteration: $i"
((i+=1))
done
exit
This script will produce the following output:
$ ./script1
in loop iteration: 1
in loop iteration: 2
in loop iteration: 3
in loop iteration: 4
in loop iteration: 5
$
If we uncomment (remove the #) from the "set -x" line in the script, this is what is displayed when the
script runs:
$ ./script1
+ i=1
+ [ 1 -lt 6 ]
+ print in loop iteration: 1
in loop iteration: 1
+ let i+=1
+ [ 2 -lt 6 ]
+ print in loop iteration: 2
in loop iteration: 2
+ let i+=1
+ [ 3 -lt 6 ]
+ print in loop iteration: 3
in loop iteration: 3
+ let i+=1
+ [ 4 -lt 6 ]
+ print in loop iteration: 4
in loop iteration: 4
+ let i+=1
+ [ 5 -lt 6 ]
+ print in loop iteration: 5
in loop iteration: 5
+ let i+=1
+ [ 6 -lt 6 ]
+ exit
$
In addition to displaying the intended output ("in loop iteration" lines), enabling debugging with "set -x"
also shows each line of execution preceded by a plus sign (+).
Although this can become unwieldly for larger shell scripts, it should be obvious how useful this can be
when debugging a shell script to identify the root cause of a problem.
(10) Within a UNIX shell scripting loop construct, what is the diference between the break and
continue?
Using break within a shell scripting loop construct will cause the entire loop to terminate. A continue will
cause the current iteration to terminate, but the loop will continue on the next iteration.
Do you need to practice writing and executing UNIX shell scripts (on a REAL SERVER) before the
interview? With a highly concentrated efort, either of these online courses can be completed within 24
hours...
UNIX and Linux Operating System Fundamentals contains a very good "Introduction to UNIX Shell
Scripting" module, and should be taken if you are new to the UNIX and Linux operating system
environments or need a refresher on key concepts.
UNIX Shell Scripting is a good option if you are already comfortable with UNIX or Linux and just need to
sharpen your knowledge about shell scripting and the UNIX shell in general.
...or you can optionally select a subset of modules from the course to focus on prior to the interview and
then return to work on the remaining topics as your schedule permits.
Both courses include access to an Internet Lab system for completing the course's hands-on exercises,
which are used to re-enforce the key concepts presented in the course. Any questions you may have
while taking the course are answered by an experienced UNIX technologist.
Thanks for reading, and best of luck with your shell scripting interview questions and your interview in
general!!!