UNIX Technical Interview Questions

What is UNIX?

In short, UNIX is a type of operating system. It actually predates most modern operating systems such as Windows, Android, Linux, etc. In fact, operating systems such as BSD, Linuz, and Apple OS have developed from UNIX, or at least have been heavily influenced by it.  UNIX was developed in the 1970s at the Bell Labs research center by Ken Thompson, Dennis Ritchie, and others.

UNIX is primarily known for its multitasking and multiuser compatibility. UNIX was designed to be portable, multi-tasking and multi-user in a time-sharing configuration. It is also characterized by some concepts such as the use of plain text for storing data, as well as a hierarchical file system and the use of a large number of software tools. It is also known for the way it treats devices and certain types of inter-process communication (IPC) as files. In UNIX, small programs can be strung together through a command-line interpreter using pipes, as opposed to using a single monolithic program. These concepts together are collectively known as the "Unix philosophy".

What are filters?

A filter is a specific type of UNIX command. It is primarily used to do some manipulation in the text of the file. It changes plain text into something that can be used together with the other filters and pipes. All of which together form a series of operations that can be utilized to produce highly specific results.

The filter gets most of its data from its standard input, which is main input stream. It then writes its main results to its standard output, i.e. the main output stream. The two most popular UNIX filters are the sed and awk commands. Both are extremely powerful and yet are somewhat complex to use.

What is Kernel?

A kernel is the central module of an operating system (OS). Each and every OS has a kernel. Basically, UNIX is a type of kernel, around which the operating system has been created. It is the kernel that loads first and simultaneously remains in main memory. It is also responsible for providing all the essential services that are required by other parts of the operating system and applications.

The kernel is typically stored in protected memory to avoid it accidently being overwritten. The kernel is responsible for memory management, process and task management, and disk management. It also connects the system hardware to the application software.

What is Shell?

In the simplest terms, a shell is a program. It is responsible for taking commands and setting them up for execution. Basically, it acts as an interface between the user and the system hence allowing the user to input the commands, and for the system to execute them. Once the command is inputted, it is the shell’s job to validate the command and accept it or reject it accordingly. Once it accepts it, it will then send the command to another part of the command processor to be executed.  

The shell is also known as the command interpreter. The shell is the outermost layer of the operating system, whereas the kernel is the innermost. UNIX has various shells, the most popular of them being the Cshell, the Bourne shell, and the Korn shell.

There are multiple shell types of Unix. What are the features of the Bourne and Korn shell?

A shell is a type of user interface that allows the user to input a command. The shell will then set up that command to be executed. UNIX has various shells, the most popular of them being the Cshell, the Bourne shell, and the Korn shell.

The Bourne shell is the standard shell of Unix. Features of the Bourne shell include:

  • Gives the ability of input/output redirection
  • Provides a built in command set for the creation of shell programs
  • Allows the user to control a job
  • Allows the usage of metacharacters for file name abbreviations
  • The environment can be customized using the shell variables

The Korn shell is an extension of the Bourne shell which is backward compatible. Features of the Korn shell include:

  • A history mechanism with built-in editor that simulates emacs or vi
  • A built-in integer arithmetic
  • Provides string manipulation capabilities
  • Has command aliasing
  • Has arrays
  • Allows the user to control a job
What is a typical syntax being followed when issuing commands in shell?

The typical command syntax when issuing commands under the UNIX shell follows the following format:

Command [-argument] [-argument] [–argument] [file]

What do you understand by File modes in Unix?

File modes are basically permissions or access rights. The permissions that are given to the "user", "group" and "others" classes. It indicates to the system the types of files that each person can access, as well as the amount of access each one is allowed.

There are four main classes; each one with its own reference and set of permissions.

Reference

Class

Description

u

user

the owner of the file

g

group

users who are members of the file's group

o

others

users who are not the owner of the file or members of the group

a

all

all three of the above, is the same as ugo

Once assigned, the modes are not permanent. They can be changed. In traditional Unix permissions, modes can be changed with chmod. In Access Control Lists, modes can be changed with setfacl (for).

Is there a way to erase all files in the current directory, including all its sub-directories, using only one command?

Yes. In order to erase all files, the command rn is frequently used. In order to erase all files in the current directory, including all its sub-directories, the command “rm –r *” is used. The * indicates to the system that all entries must be deleted.

For example:

In order to delete all files in the directory donotdelete, one would use

rm -r donotdelete /*

However, this will not delete any hidden file if they exist.

What is the alias mechanism in UNIX?

The alias mechanism allows one to specify or assign another name to a command. Basically, it assigns an alias to the command. This comes in useful as one can assign an alias to a command that would otherwise be difficult to remember.

For example:

alias dir ‘ls -sFC’

This indicated to the system that the command “dir” can now be used instead of ‘ls -sFC’. Using “dir” will have the same effect as using ‘ls -sFC’

What are some common shells and what are their indicators?

Shells are the programming layer that reads, understands and executes the command that is entered by the user. Some common shells and their indicators are:

  • sh – Bourne shell
  • csh – C SHell
  • bash – Bourne Again Shell
  • tcsh – enhanced C Shell
  • zsh – Z SHell
  • ksh – Korn SHell 
What are the key features of the Korn Shell?

Korn shell was developed by David Korn and it includes features similar to C shell and Bourne shell. Some key features of the Korn Shell are :

  • Job control: It can stop jobs with CTRL-Z and is able to put them either to the foreground or background with the fg and bg commands.
  • Aliases: It can define short names for commands or command lines.
  • Functions: It can store the shell code in memory and not in files. Functions increase programming ability and efficiency.
  • Command history: It can recall commands that have been entered earlier or previously.

The Korn shell’s major new features include:

  • Command line editing: User can use vi or Emacs-style editing commands on your command lines.
  • Integrated programming features: Several external Unix commands functionality like test, expr, getopt and echo have been integrated into the shell. This enables more cleanliness in performing common programming tasks and also without creating extra processes.
  • Control structures: Menu is generated easily because of control structures.
  • Debugging primitives: This helps to write tools which are required to debug shell code.
  • Regular expressions: Regular expressions have been added.
  • Advanced I/O features: Many new facilities for controlling the process I/O have been added. 
  • New options and variables: To help customize, new options and variables help user.
  • Increase Speed: Korn shells execute shell programs faster than Bourne shell.
  • Security features: It helps to protect against different types of break-in schemes like “Trojan Horses”

Major new features in the 1993 version include:

  • POSIX compliance: POSIX is an international standard for portable shell programming. POSIX compliance allows one to write and use shell scripts.
  • Built-in integer arithmetic: It allows the use of new built in arithmetic functions and floating-point numbers, thus making it great for use.
  • Structured variable names: Related items can be grouped together in a variable similar to C structures.
  • Associative arrays: It makes programming of tasks more natural. In associative array, array is indexed by string values.
     
Briefly describe the Shell’s responsibilities.

The shell provides an interface through which the user gives input and the programs are executed based upon that. The responsibilities of a Shell are:

  • Program execution: The shell is responsible for the execution of programs that is requested.
  • Variable and file name substitution: The shell allows us to assign values to variables. When a variable is specified on the command line, preceded by a dollar sign, the value that is assigned to that variable at that point is substituted by the shell.
  • I/O redirection: The shell is responsible for taking care of input and output redirection on the command line.
  • Pipeline hookup: The shell scans the command line for pipe character. If it finds such characters, it connects the standard output from the command preceding the | to the standard input of the one following the |. It then initiates execution of both programs. 
  • Environmental control: The shell allows us to customize our environment. Environment includes home directory, the list of directories that is searched when a program is requested to be executed and the characters that is prompted by the shell when the command is typed.
  • Interpreted programming language: The shell has its own built in programming language. The shell analyzes each statement in the language one line at a time and then executes it.
     
What are shell variables?

Shell variables are a combination of name and assigned value which exist within the shell. These variables values are set using proper assignment command. Shell variables are temporary and are deleted when the shell session ends. To make it available everywhere in the system it must be converted into environment variable.

What is Bash Shell?

Bash shell is first shell that was designed to work on UNIX system. Bash allows users of Unix-like systems to control the innermost components of the operating system using text-based commands. It includes features from both the C and Korn shell.

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.