Shell scripting interview question part 1/Shell Scripting Interview Questions and Answers for Freshers & Experienced

Tell me the difference between hard link and soft link?

Deleting the original file does not affect the hard link but Deleting the original file makes the soft link inactive.

Posted Date:- 2021-09-10 01:52:52

How to find an available shell in your system?

Cat /etc/shells command is used to find available shells in your system.

Posted Date:- 2021-09-10 01:52:13

What are the different communication commands available in the Shell?

There are four different communication commands available in Shell.

> mail
> news
> wall
> motd

The total disk space used by Edureka can be found out as shown below.

Posted Date:- 2021-09-10 01:50:58

What are the different commands available to check the disk usage?

There are three different commands available to check the disk usage.

df: It is used to check the free disk space.
du: It is used to check the directory wise disk usage.
dfspace: It is used to check the free disk space in terms of MB.

Posted Date:- 2021-09-10 01:49:16

What command needs to be used to take the backup?

The tar command is used to take the backup. It stands for tape archive. The command is mainly used to save and restore files to and from an archive medium like tape.

Posted Date:- 2021-09-10 01:48:14

What are the two files of crontab command?

The two files of crontab command are:

<> cron.allow which decides the users need to be permitted for using the crontab command.
<> cron.deny which decides the users need to be prevented from using the crontab command.

Posted Date:- 2021-09-10 01:47:19

In what ways, shell script get input values?

a. By reading command: read -p "Destination backup Server: " dest host

b. By parameters: ./script param1 param2

Posted Date:- 2021-09-10 01:44:54

What is the difference between $* and $@?

$@ treats each quoted arguments as separate arguments but $* will consider the entire set of positional parameters as a single string.

Posted Date:- 2021-09-10 01:44:03

Do you need a separate compiler to execute a Shell program?

No, you don’t need a separate compiler to execute a Shell program. Since Shell itself is a command-line in the shell program and executes them.

Posted Date:- 2021-09-10 01:43:27

How many Shells and Kernels are available in a UNIX environment?

Typically, a UNIX environment has only one Kernel. However, there are multiple Shells available.

Posted Date:- 2021-09-10 01:42:27

Explain “Positional Parameters.”

Positional parameters are variables defined by a Shell. They are used to pass information to the program by specifying arguments in the command line.

Posted Date:- 2021-09-10 01:41:42

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.

Posted Date:- 2021-09-10 01:40:30

How will you copy a file from one machine to other?

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

E.g., Using ftp:

FTP hostname

>put file1

>bye

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

Posted Date:- 2021-09-10 01:39:48

What are zombie processes?

These are the processes which have died but whose exit status is still not picked by the parent process. These processes even if not functional still have its process id entry in the process table.

Posted Date:- 2021-09-10 01:38:51

What is the use of head and tell command?

Head command is used for display started 10 lines

Tail command is used for display started 10 lines

Posted Date:- 2021-09-10 01:38:14

How to create multiple text files and directories?

To create multiple text file touch file name {} command is used

eg. suppose we want create 4 files then we type #touch filename{1..4}

To create multiple directory mkdir filename {} command is used

eg. suppose we want to create 4 directory then we type mkdir filename {1..4}

Posted Date:- 2021-09-10 01:37:37

How to create, read and delete files?

touch command is used for creating files. eg. #touch filename

cat command is used for reading files. eg. #cat filename

rm command is used for delete a file eg. #rm –f filename

Posted Date:- 2021-09-10 01:36:01

Which command is used to execute a shell file?

First Set execute permission on your script using chmod command
chmod +x script-name-here.sh

To run your script:
./script-name-here.sh
Another option to execute shell script:
sh script-name-here.sh

Posted Date:- 2021-09-10 01:34:26

What is LILO?

LILO is a boot loader used in Linux .It is used to load the operating system into main memory to start its operation.

Posted Date:- 2021-09-10 01:33:46

Use the echo command to get part of a string variable.

This is how we can get part of string variable using echo command only:

echo ${variable:x:y}

Where X is the starting position and y is the string length.

example:

variable="Her name is Jen, and she is a developer."

echo ${variable:12:6} # will display Jen

Posted Date:- 2021-09-10 01:33:03

How can you print a substring in bash?

Bash does not have a built-in function like other languages. However, a parameter expansion can be used to cut any string value. The three parts defined in parameter expansion are the primary string variable that has to be cut, starting position, and length of the cutting string. The first two are mandatory; the last one is optional. The starting position is counted from 0, and length must be counted from 1 of the main string.

Posted Date:- 2021-09-10 01:32:24

Why is bash a weakly typed language?

Bash is a weakly typed language because it does not require declaring data type at the time of variable declaration. Bash variables are treated as strings, and the type of variable is set based on the current value. Bash variables can be defined by using declare command. However, to define data types, options are limited and do not support all data types. For example: declare command cannot be used for the float data type.

Posted Date:- 2021-09-10 01:31:35

What does it mean by #!/bin/sh or #!/bin/bash at the beginning of every script?

A script may specify #!/bin/bash on the first line, meaning that the script should always be run with bash, rather than another shell. /bin/sh is an executable representing the system shell. Actually, it is usually implemented as a symbolic link pointing to the executable for whichever shell is the system shell.

Posted Date:- 2021-09-10 01:30:52

What is the lifespan of a variable inside a shell script?

The lifespan of a variable inside shell script is only until the end of execution.

Posted Date:- 2021-09-10 01:30:13

What will be the status of a process executed using the exec command in the shell?

All the new forked processes get overlays on executing exec. The command gets executed without any impact on the current process, and no new process is created in the scenario.

Posted Date:- 2021-09-10 01:28:07

How will you debug problems encountered in the shell program?

Some standard methods of debugging the problems in the script are:

1. use of set-x to enable debugging

2. Insert debug statements in a shell script to display information that helps in the identification of the problem.

Posted Date:- 2021-09-10 01:27:28

How to redirect both standard output and standard error to the same location?

The two methods to redirect standard output and standard error to the same location are the following;

1. 2>&1(# ls /usr/share/doc > out.txt 2>&1 )
2. &>(# ls /usr/share/doc &> out.txt )

Posted Date:- 2021-09-10 01:26:35

Can you separate hard and soft links in shell scripting? How?

Shell scripting is a powerful approach that uses links to create shortcuts, just like Windows. Soft links do not have any specific location and can be anywhere on the same file system, and are generally related to the file name. At the same time, hard links remain present on the same file system. Hard links are related to nodes and have a particular fixed location in most cases.

Posted Date:- 2021-09-10 01:25:36

What is the lifespan of a shell variable?

A variable is inside the shell script only until the end of execution.

Posted Date:- 2021-09-10 01:25:03

Explain Crontab.

Crontab means cron table because the tasks are executed using the job scheduler ‘cron.' It is a list of commands that run on a regular schedule, and the name of the command also manages the list. Crontab is the schedule and also the name of the program used to edit the schedule.

Posted Date:- 2021-09-10 01:24:31

In shell scripting, where you will find the login names of all the users on a system and how they can be printed at the same time?

There is a file “etc/shadow file which contains all the information related to the users and the same can be printed or displayed anytime when the need of same is felt. You have no reasons to worry about this and the command awk-F can let you print them all in one go.

Posted Date:- 2021-09-10 01:23:29

Suppose you execute a command using exec, what will be the status of your current process in the shell?

All the forked processes which are new get overlays when the exec is executed. The command simply gets executed without making any impact on the current process. Also, no new process will be created in this scenario.

Posted Date:- 2021-09-10 01:22:39

What do you know about the MBR in the shell scripting? How it is useful for the users?

It stands for Master Boot Record and is basically a small program whose prime function is to make sure that the kernel is loaded during the system boot set up. It is present in the boot block.

It is nothing but the MBR that simply makes sure that the users can perform the boot looping tasks accurately and reliably.

Posted Date:- 2021-09-10 01:22:09

How can you calculate the overall number of arguments that have been passed to a script? Why it is important?

This can easily be done by a command $#. The same is required to know the overall load on a script. Every limit has a limit on handling the same and users have to check it often to make sure the script remains in the running mode and doesn’t get fail.

Posted Date:- 2021-09-10 01:20:46

What is a metacharacter?

Metacharacter is a unique character included in a program or data field of a shell. It offers information about other characters. For example: to list all files beginning with character 's,' use the 'ls s*' command.

Posted Date:- 2021-09-10 01:19:51

Explain what do you know about the term shell when it comes to scripting? Name a few shells that are commonly used.

Basically, it acts as a direct link between the kernel and the user. It is possible for the system to run multiple shells at the same time despite the fact that there is always only one kernel that remains present.

Thus, when the command is given by the user, the shell begins exchanging information with the kernel. The operations are then executed and the information is conveyed to the user.

The shells that are commonly used in the scripting are ksh, bourne, bash, csh

Posted Date:- 2021-09-10 01:19:23

What is the alternative command for echo?

The alternative command for echo is tput. This command allows us to control how the output is displayed on the screen.

Posted Date:- 2021-09-10 01:17:03

How many kernels and shells are available in the UNIX environment?

There can be multiple shells available, but there is only one kernel in the UNIX environment.

Posted Date:- 2021-09-10 01:16:31

Give the purpose of the shebang line.

The shebang line is at the top of each script used to determine the engine's location and is used to execute the script.

Posted Date:- 2021-09-10 01:15:06

How can you connect to a database server?

To connect to a database server from Linux, use the isql utility that comes with the open client driver. Here is how:

isql –S serverName –U username –P password

Posted Date:- 2021-09-10 01:14:42

How would you compare the strings in a Shell Script?

The test command is used to compare the text strings. The test command compares text strings by comparing each character in each string.

Posted Date:- 2021-09-10 01:14:04

What makes C shell a more preferable option than the Bourne Shell?

C is a more preferable option in the following cases:

> All the commands can be aliased simply with the C shell whereas the same is not possible in case of Bourne Shell.

> Lengthy commands can be used again and again in C shell whereas the Bourne doesn’t allow the same in all the cases.

> The command history can be accessed through the C shell but it cannot be accessed through the Bourne.

Posted Date:- 2021-09-10 01:13:36

What is the difference between break and continue commands?

1. Break: It is a simple way to escape out of a loop in progress. We can use the break command to exit out from any loop, including while and until loops.

2. Continue: It causes the present iteration of the loop to exit, instead of the entire loop.

Posted Date:- 2021-09-10 01:12:15

What are the various stages of a Linux process it passes through?

A Linux process generally passes through four stages:

<> Waiting: The Linux process waits for the resource.
<> Running: The Linux process is currently being executed.
<> Stopped: The Linux process is stopped after successful execution.
<> Zombie: The process has stopped but is still active in the process table.

Posted Date:- 2021-09-10 01:11:33

What is GUI scripting?

GUI is used for controlling a computer and its applications. GUI scripting supports different applications. It mostly depends on the operating system.

Posted Date:- 2021-09-10 01:10:26

Tell something about the Super Block in Shell scripting?

A Super Block is essentially a program that contains a record of specific file systems.

Characteristics such as the block size, the empty and the filled blocks and their respective counts, the size and location of the inode tables, the disk block map, and usage information, and the size of the block groups are available in a superblock.

Posted Date:- 2021-09-10 01:10:00

How do you create a shortcut in Linux?

This can be done with the help of links present in Linux OS.

1. Hard Link: Hard links are linked to the inode of the file and have to be on the same file system as of the file. Deleting the original file does not affect the hard link.

2. Soft Link: Soft links are linked to the file name and can reside on a different file system as well. Deleting the original file makes the soft link inactive.

Posted Date:- 2021-09-10 01:09:38

What are the different types of commonly used shells on a typical Linux system?

There are primarily two kinds of shells in Linux OS, namely, Bourne Shell and C-Shell. Examples of derivative from each are as follows;

Bourne Shell: Bourne Shell, Bourne-Again Shell, Korn Shell, POSIX Shell.

C-Shell: C-Shell, TENEX C-Shell, Z-Shell.

Posted Date:- 2021-09-10 01:09:06

What are the different types of variables used in Shell Script?

A shell script has two types of variables :

1. System-defined variables are created/defined by the Operating System(Linux) itself. These variables are generally defined in Capital Letters and can be viewed by “set” command.

2. User-defined variables are created or defined by system users and the values of variables can be viewed by using the command “echo”.

Posted Date:- 2021-09-10 01:08:22

List the types of variables used in Shell Scripting.

Usually, a Shell Script has two types of variables:

<> System-defined variables – They are created by the OS(Linux) and are defined in capital letters. You can view them using the Set command.

<> User-defined variables – These are created and defined by system users. You can view the variable values using the Echo command.

Posted Date:- 2021-09-10 01:07:28

What are Shell variables?

Shell variables form the core part of a Shell program or script. The variables allow Shell to store and manipulate information within a Shell program. Shell variables are generally stored as string variables.

Posted Date:- 2021-09-10 01:06:55

What are the advantages of Shell Scripting?

The greatest benefits of Shell Scripting are:

1. It allows you to create a custom operating system to best suit your requirements.
2. It lets you design software applications based on the platform you’re using.
3. It is time-savvy as it helps automate system administration tasks.

Posted Date:- 2021-09-10 01:06:40

Explain about “s” permission bit in a file?

“s” bit is called “set user id” (SUID) bit.

“s” bit on a file causes the process to have the privileges of the owner of the file during the instance of the program.

For example, executing “passwd” command to change current password causes the user to writes its new password to shadow file even though it has “root” as its owner.

Posted Date:- 2021-09-10 01:05:43

In my bash shell I want my prompt to be of format ‘$”Present working directory”:”hostname”> and load a file containing a list of user-defined functions as soon as I log in, how will you automate this?

In bash shell, we can create “.profile” file which automatically gets invoked as soon as I log in and write the following syntax into it.

export PS1='$ `pwd`:`hostname`>' .File1

Posted Date:- 2021-09-10 01:05:17

What is the main difference between BASH and DOS?

BASH commands are case sensitive but DOS commands are not case sensitive.

Posted Date:- 2021-09-10 01:04:44

How will you pass and access arguments to a script in Linux?

Arguments can be passed as:

scriptName “Arg1” “Arg2″….”Argn” and can be accessed inside the script as $1 , $2 .. $n

Posted Date:- 2021-09-09 23:32:09

What is the difference between soft and hard links?

Soft links are link to the file name and can reside on different filesytem as well; however hard links are link to the inode of the file and have to be on the same filesytem as that of the file. Deleting the original file makes the soft link inactive (broken link) but does not affect the hard link (Hard link will still access a copy of the file)

Posted Date:- 2021-09-09 23:31:50

What is the equivalent of a file shortcut that we have a window on a Linux system?

Shortcuts are created using “links” on Linux. There are two types of links that can be used namely “soft link” and “hard link”.

Posted Date:- 2021-09-09 23:31:27

What are the different types of commonly used shells on a typical Linux system?

csh,ksh,bash,Bourne . The most commonly used and advanced shell used today is “Bash” .

Posted Date:- 2021-09-09 23:30:56

What is a shell?

Shell is an interface between the user and the kernel. Even though there can be only one kernel; a system can have many shell running simultaneously. So, whenever a user enters a command through the keyboard, the shell communicates with the kernel to execute it and then display the output to the user.

Posted Date:- 2021-09-09 23:30:06

Search
R4R Team
R4R provides Shell Scripting Freshers questions and answers (Shell Scripting Interview Questions and Answers) .The questions on R4R.in website is done by expert team! Mock Tests and Practice Papers for prepare yourself.. Mock Tests, Practice Papers,Shell scripting interview question part 1,Shell Scripting Freshers & Experienced Interview Questions and Answers,Shell Scripting Objetive choice questions and answers,Shell Scripting Multiple choice questions and answers,Shell Scripting objective, Shell Scripting questions , Shell Scripting answers,Shell Scripting MCQs questions and answers R4r provides Python,General knowledge(GK),Computer,PHP,SQL,Java,JSP,Android,CSS,Hibernate,Servlets,Spring etc Interview tips for Freshers and Experienced for Shell Scripting fresher interview questions ,Shell Scripting Experienced interview questions,Shell Scripting fresher interview questions and answers ,Shell Scripting Experienced interview questions and answers,tricky Shell Scripting queries for interview pdf,complex Shell Scripting for practice with answers,Shell Scripting for practice with answers You can search job and get offer latters by studing r4r.in .learn in easy ways .