Unix Shell Scripting Interview Questions And Answers
Q1. What is a shell?
Ans: Shell is a point of interaction among client and the part. Despite the fact that there can be just a single bit ; a framework can have many shell running all the while . Whenever a client enters an order through console the shell speaks with the part to execute it and afterward show the result to the client.
Q2. What are the various kinds of generally utilized shells on a normal linux framework?
Ans: csh,ksh,bash,Bourne . The most normally utilized and high level shell utilized today is "Slam" .
Q3. What is what could be compared to a record easy route that we have on window on a Linux framework?
Ans: Shortcuts are made utilizing "joins" on Linux. There are two kinds of connections that can be utilized to be specific "delicate connection" and "hard connection"
Q4. What is the distinction among delicate and hard connections?
Ans: Soft connections are connection to the record name and can dwell on various filesytem also; but hard connections are connection to the inode of the document and must be on the equivalent filesytem as that of the document. Erasing the orginal document makes the delicate connection latent (broken interface) however doesn't influence the hard connection (Hard connection will in any case get to a duplicate of the record)
Q5. How might you pass and access contentions to a content in Linux?
Ans: Arguments can be passed as:
scriptName "Arg1" "Arg2"… ."Argn" and can be gotten to inside the content as $1 , $2 .. $n
Q6. What is the meaning of $#?
Ans: $# shows the count of the contentions passed to the content.
Q7. What is the distinction among $* and $@?
Ans: $@ regards each cited contentions as independent contentions however $* will think about the whole arrangement of positional boundaries as a solitary string.
Q8. Use sed order to supplant the substance of the record (imitate tac order)
Ans:
Eg:
1
2
3
4
if feline file1
ABCD
EFGH
Then, at that point, O/p ought to be
EFGH
ABCD
1
sed '1! G; h;$!d' file1
Here G order affixss to the example space,
h order duplicates design cushion to hold cradle
also, d order erases the ongoing example space.
Q9. Given a document, supplant all event of word "ABC" with "DEF" from fifth line till end in just those lines that contains word "MNO"
Ans:
1
sed - n '5 , $p' file1 |sed '/MNO/s/ABC/DEF/'
Q10. Given a document , compose an order grouping to track down the count of each word.
Ans:
1
2
3
tr - s " (oblique punctuation line )040" <file1 |tr - s " (oblique punctuation line )011" |tr " (oblique punctuation line )040 (oblique punctuation line )011" " (oblique punctuation line )012" |uniq - c
where " (oblique punctuation line )040" is octal likeness "space"
"(backslash)011" is octal likeness "tab character" and
"(backslash)012" is octal likeness newline character.
Q11. How might you find the 99th line of a record utilizing just tail and head order?
Ans: tail +99 file1|head - 1
Q12. Print the tenth line without utilizing tail and head order.
Ans:
1
sed - n '10p' file1
Q13. In my slam shell I maintain that my brief should be of configuration '$"Present working directory":"hostname"> and load a record containing a rundown of client characterized capabilities when I login , how might you mechanize this?
Ans: In slam shell we can make ".profile" document which naturally gets conjured when I login and compose the accompanying punctuation into it.
1
send out PS1 =' $ 'pwd ' : 'hostname ' >' .File1
Here File1 is the document containing the client characterized capabilities and "." summons this record in current shell.
HubSpot Video
Q14. Make sense of about "s" consent bit in a record?
Ans: "s" cycle is classified "set client id" (SUID) bit.
"s" bit on a document makes the cycle have the honors of the proprietor of the record during the occurrence of the program.
Eg: Executing "passwd" order to change current secret key makes the client composes its new secret phrase to shadow document despite the fact that it has "root" as its proprietor.
Q15. I need to make a catalog to such an extent that anybody in the gathering can make a record and access any individual's document in it yet none ought to have the option to erase a document other than the one made without help from anyone else.
Ans: We can make the catalog giving read and execute admittance to everybody in the gathering and setting its tacky piece "t" on as follows:
1
2
3
4
5
mkdir direc1
chmod g +wx direc1
chmod +t direc1
Q16. How might you figure out how long the framework has been running?
Ans: Command "uptime"
Q17. How might any client figure out all data about a particular client like his default shell, genuine name, default directory,when and how lengthy he has been utilizing the sytem?
Ans: finger "loginName" … where loginName is the login name of the
client whose data is normal.
Q18. What is the contrast among $$ and $!?
Ans: $$ gives the interaction id of the right now executing process though $! shows the interaction id of the cycle that as of late went into foundation.
Q19. What are zombie processes?
Ans: These are the cycles which have passed on yet whose leave status is as yet not picked by the parent interaction. These cycles regardless of whether not utilitarian actually have its interaction id passage in the process table.
Q20. How might you duplicate document from one machine to other?
Ans: We can utilize utilities like "ftp" ,"scp" or "rsync" to duplicate document from one machine to other.
Eg: Using ftp:
ftp hostname
>put file1
>bye
Above duplicates record file1 from nearby framework to objective framework whose hostname is indicated.
Q21. I need to screen a constantly refreshing log record, what order can be utilized to most effectively accomplish this?
Ans: We can utilize tail - f filename. This will cause just the default last 10 lines to be shown on sexually transmitted disease o/p which consistently shows the refreshing piece of the record.
Q22. I need to interface with a far off server and execute a few orders, how might I accomplish this?
Ans: We can utilize telnet to do this:
telnet hostname - l client
>Enter secret phrase
>Compose the order to execute
stop
Q23. I have 2 documents and I need to print the records which are normal to both.
Ans: We can utilize "comm" order as follows:
comm - 12 file1 file2 … 12 will stifle the substance which are
remarkable to first and second document individually.
Q24. Compose a content to print the initial 10 elemenst of Fibonacci series.
Ans:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# ! /canister/sh
a =1
b =1
reverberation $a
reverberation $b
for I in 1 2 3 4 5 6 7 8
do
c =a
b = $a
b = $ ( ( $a + $c ) )
reverberation $b
done

