Blog

Unix Shell Scripting Interview Questions

  • (4.0)
  •   |   9285 Ratings

Unix Shell Scripting Interview Questions

Last Updated: 24.04.2018

If you're looking for Unix Shell Scripting Interview Questions for Experienced or Freshers, you are at right place. There are lot of opportunities from many reputed companies in the world. According to research Unix Shell Scripting has a market share of about 17%. So, You still have opportunity to move ahead in your career in Unix Shell Scripting. Mindmajix offers Advanced Unix Shell Scripting Interview Questions 2018 that helps you in cracking your interview & acquire dream career as Unix Shell Scripting Developer.

Are you interested in taking up for Unix Shell Scripting Certification Training? Enroll Now Unix Shell Scripting Training!

ps -f command in unix

Column Names of result obtained by ps -f command in unix
UID User ID
PID ID of the process
PPID Process ID of Parent
C Process's CPU Utilization
STIME Start Time of the Process
TTY Process Terminal Type
TIME Process CPU Time lapsed
CMD To start the process

Q: What is Unix Shell?

A Unix shell is a command-line interpreter that provides a Unix-like command line user interface.

Q. List some Unix Shells.

  • The Bourne Shell (sh)
  • The Bourne Again Shell (bash)
  • The C Shell (csh or tsch)
  • The Korn Shell (ksh)

Q: When should we use “if” condition (before)?

When running several commands "if" condition meets.

Q: How do I print all arguments submitted on a command line?

echo $@ or echo $*

Q: Which is the best Way To Pretty Print JSON On The Command-Line

It can handle very large JSON structures, including streams.

Ex:

$ jq . <<< '{ "foo": "lorem", "bar": "ipsum" }'
{
  "bar": "ipsum",
  "foo": "lorem"
}

Q: What command can be used to test if $a greater than 12?

The following command is used: [ $a -gt 12 ]

Q: What are the advantages and disadvantages of shell scripting?

Advantages of shell scripting:

  1. Can design applications (software) according to their platform.
  2. To run a sequence of commands as a single command.
  3. Portable (It can be executed in any Unix-like operating systems without any modifications)

Disadvantages of shell scripting:

  1. Slow execution speed compared to any programming languages
  2. When a tying error occurs during the creation then it will delete the entire data as well as partition data.

Q: What are the difference between &/&&?

& - "Bitwise AND", evaluates both sides of the operation.
&& - "Logical AND Operator", evaluates at the left side of the operation (If it is True) it continues at the right side.

Check Out Unix Shell Scripting Tutorials

Q: How to get end line from a file?

tail -1

Q. In a program, how to get/set an environment variable?

Getenv() and putenv()

Q. Which command helpful to forward errors to a file?

The command that used for forwarding error to a file is 2> filename

Q. Which command helps in getting all files on the 3rd place an r, g or i?

Command with on the 3rd place an r, g or i is Ls ??[rgi]*

Q. What Is The Difference Between $* And $@?

  • $* - It treats the whole set of positional parameters as Single String
  • $@ - This considers every quoted argument as independent or separate arguments.

Q. Name the Command that used for Displaying the list of files in a directory

$ ls -lrt | grep ^-? command used for displaying the list of files in a directory.

Q. What is Shell Scripting?

Shell Scripting is collection of commands put together into a file. Script is a command or an instruction given to process and these set of instructions put together in a file to perform some task.

Note: In order to save time from manually providing one instruction at a time to process it, shell scripting is made available that can accept all the commands put together into a file and process them one after the other.

Q. What is unix shell scripting?

Unix Commands put together into one text file to execute one after the other.

Q. What are Shell Variables? Mention types of Shell Variables?

Shell variables provide information to execute scripts/commands. There are two types of shell variables: Unix defined and User Defined.

Unix defined variables are by default set by UNIX, to define properties. For example, SHELL is Unix variable that stored information about working shell set to default.

User-defined variables are defined by a developer to store/manage information. For example, $ mm = 2018 defined by used means, the value of 2018 is assigned to variable mm.

Q. Command to wipe out variables defined.

If we consider $ mm = 2018 as variable defined by the user, then in order to wipe out the variable, the unset command is used.

Syntax: $ unset mm

Q. List out few unix commands used very often.

Following are the list of basic unix commands one should aware of:

  • ls - To list available files and folders in the current directory.
  • cd - is to change the current working directory.
  • mkdir - is to create new folder/directory.
  • rmdir - is to remove directory/file.
  • cp - is to copy files.
  • mv - is to move files.
  • touch - creates empty file

Q. Syntax for ls command.

Syntax: $ ls

Q. Syntax for cd command.

Syntax:

  • $ cd - current directory is changed to HOME directory.
  • $ cd mindmajix : current directory is changed to mindmajix directory.
  • $ cd .. : Moves to parent directory of current working directory.

Q. Syntax for mkdir and rmdir.

Syntax:

  • $ mkdir mindmajix - Creates new folder with name “mindmajix”
  • $ rmdir mindmajix_temp - Removes folder with name “mindmajix_temp”

Q. Difference between process and thread

To put it in simple words, a thread is a small piece of code/instruction that needs to be executed in a process, whereas a process is a collection of one or more thread executions to complete one complete task.

Note: A process consists of multiple threads can share resources among them as they belong to the same process. And threads belong to different processes cannot share their resources.

Q. Without restarting the machine, how can we remove all the running processes?

All the running processes in the current shell can be removed using Linux command.

Q. What are Vi Editor modes available?

While working with Vi Editor, different operations we perform are done in different modes. 

  1. Command Mode - Launching Vi automatically starts command mode.
  2. Edit Mode - This mode provides an environment to edit text.
  3. Ex Mode - Vi editor interaction is made available with file processing instructions.

Q. Why do we use “$?” in shell scripting?

This command returns the exit status of the previously executed command.

0 for successful execution, and non-zero for failure.

Q. What is “$*” in shell scripting?

Arguments list passed in the current process.

Q. What is the command for number of arguments passed in command line arguments?

$#” is the command.

Q. How can you get the PID of the current process?

$$” is used.

Q. Command to work with file permissions?

umask is the command to modify file permissions.

Q. Explain structure of File Permissions.

Each permission is assigned with weight to represent in command lines.

In the command line,

  • if we mention 7, it includes all the three permissions r,w and x (i.e., 4+2+1)
  • if we mention 6, it includes two permissions r and w (i.e., 4+2)
  • if we mention 5, it includes two permissions r and x (i.e., 4+1) and so on.

Consider below example command for file permissions:

$ chmod 754 mindmajix.txt

Here in 754, each digit indicates permissions for three different people.

  • Owner - 7
  • People in the same group - 5
  • Others - 4

Q. Types of File Permissions.

  • Read as r with weight 4
  • Write as w with weight 2
  • Execute as x with weight 1

Q. Command to delete any file?

 If we suppose file name as “mindmajix_temp_files.txt”, then

$rm mindmajix_temp_files.txt” is the command to remove the file.

Q. Command to append output to a file.

>>” is used to append output to file mentioned.

For example, if we want to append Date to today.txt, the following is the command

$ date >> today.txt

Explore Unix Shell Scripting Sample Resumes! Download & Edit, Get Noticed by Top Employers!Download Now!

Popular Courses in 2018

Get Updates on Tech posts, Interview & Certification questions and training schedules