Most Asked Shell Scripting Interview Questions and Answers

Shell Scripting Interview Questions and Answers most commonly asked for Experienced PDF, Freshers candidates for Employment.

How will you copy file from one machine to other?

We can use utilities like “ftp” ,”scp” or “rsync” to copy file from one machine to other.

Eg: Using ftp:

ftp hostname

>put file1


Above copies file file1 from local system to destination system whose hostname is specified.

I want to monitor a continuously updating log file, what command can be used to most efficiently achieve this?

We can use tail –f filename     . This will cause only the default last 10 lines to be displayed on std o/p which continuously shows  the updating part of the file.

I want to connect to a remote server and execute some commands, how can I achieve this?

We can use telnet to do this:

telnet hostname –l user

>Enter password

>Write the command to execute


I have 2 files and I want to print the records which are common to both.

We can use “comm” command as follows:

comm -12 file1 file2               … 12 will suppress the content which are

unique to 1st and 2nd  file respectively.

Write a script to print the first 10 elemenst of Fibonacci series.




echo $a

echo $b

for I in 1 2 3 4 5 6 7 8





echo $b


How will you connect to a database server from linux?

We can use isql utility that comes with open client driver  as follows:

isql –S serverName –U username –P password

What are the 3 standard streams in Linux?

0 – Standard Input
1 – Standard Output
2 – Standard Error

I want to read all input to the command from file1 direct all output to file2 and error to file 3, how can I achieve this?

command <file1 1>file2 2>file3

What will happen to my current process when I execute a command using exec?

“exec” overlays the newly forked process on the current  process ; so when I execute the command using exec, the command gets executed on the current shell without creating any new processes.

Eg: Executing “exec  ls”  on command prompt will execute ls and once ls exits, the process will shut down

How will you emulate wc –l using awk?

awk ‘END {print NR} fileName’

Given a file find the count of lines containing word “ABC”.

grep –c  “ABC” file1

What is the difference between grep and egrep?

egrep is Extended grep that supports added grep features like “+” (1 or more occurrence of previous character),”?”(0 or 1 occurrence of previous character) and “|” (alternate matching)

How will you print the login names of all users on a system?

/etc/shadow file has all the users listed.

awk –F ‘:’ ‘{print $1} /etc/shadow’|uniq -u

How to set an array in Linux?

Syntax in ksh:

Set –A arrayname= (element1 element2 ….. element)

In bash

A=(element1 element2 element3 …. elementn)

Write down the syntax of “for “ loop


for  iterator in (elements)


execute commands



Popular posts from this blog

TOP Agile Testing Interview Questions and Answers

Latest Agile Testing Interview Questions and Answers

Most Asked ADO.NET Interview Questions and Answers