1. What are the core components of Unix?

Ans. Unix consists of three components namely, kernel, shell, and file programs. They are explained below:

  • Kernel – kernel is the lowest layer of the Unix operating system. Also known as the heart Unix, the kernel directly interacts with the computer hardware. It is responsible for allocating and managing the resources available to programs. It monitors major processes like memory management, file management, and task scheduling. It also offers an interface to programs where they can access files, the network, and devices.
  • Shell – the shell is also called a command prompt. It is responsible for connecting the user to the operating system. The shell translated the user input into the language understood by the command prompt, and then the corresponding actions are performed.
  • Programs – Unix has a variety of small programs to meet different needs. Each Unix program performs one thing. Due to the modular design, the functionality of small programs to be mixed and matched. This offers flexibility to the users, allowing them to accomplish almost any task. While programs operate on top of the shell, they may also interact directly with the kernel.
  1. How can you create an archive file?

Ans. It can be created by using the tar command.

  1. How to debug the bash script?

Ans. Simply add –xv to #! /bin/bash

  1. What is the difference between Linux and UNIX?

Ans. It is one of the most important Unix interview uestions that you must prepare for your interview.

Linux is the clone of Unix and has some features similar to Unix. However, they do have some key differences as mentioned in the table below:

Linux

Unix

Linux is free to use and open source

Unix is a licensed OS and is not open source

It is used in desktops, servers, mainframes, and smartphones.

It is used on servers, workstations, and PCs.

Bash (Bourne Again SHell) is the default shell.

Bourne Shell is the default shell.

Supported file systems: Ext2, Ext3, Ext4, ReiserFS, Xfs, Jfs, Btrfs, FAT

Supported file systems: hfs, hfs+, fs, gpfs, ufs, xfs, zfs

Different versions of Linux: Redhat, Ubuntu, OpenSuse

Different versions of Unix: HP-UX, AIS, BSD

  1. Give an example of how to write a function?

Ans. Example:

{

Echo “Hi everyone!”

}

  1. What is the difference between cmp and diff commands?

Ans. Cmp is used for binary files, whereas diff is used for files in text format.

  1. Define paging?

Ans. It is a memory management system by which a computer stores and retrieves data from secondary storage.

  1. Which command is used to kill the last background job?

Ans. Kill $!

  1. Define shell?

Ans. It is an environment in which we can run shell scripts, commands, and programs. There are two types of shells:

  • The Bourne shell
  • The C shell
  1. Which command is used to remove the seventh line from a file?

Ans. sed -i ‘7 d’ test.txt

  1. Is UNIX open source?

Ans. No.

  1. Define a hidden file?

Ans. A file starting with a dot is known as a hidden one.

  1. What are the links?

Ans. A link is a pointer to a file. It can be used to assign more than one name to a file, but can’t be used to assign a directory on various computers.

  1. Which programming language is used for UNIX?

Ans. C.

  1. Which command is used to change the password?

Ans. Passwd.

  1. Which switch is used in test expression to determine a file as a regular file?

Ans. -F

  1. Name some system calls used for process management?

Ans. It is one of the most commonly asked Unix interview questions.

Process management uses several system calls. They are explained below:

Unix System calls for Process Management

Description

fork()

create a new process

exec()

execute a new program in a process

wait()

wait until a created process completes its execution

exit()

exit from a process execution

brk()

increase/decrease the data segment size of a process

getpid()

get a process identifier of the current process

getppid()

get parent process identifier

nice()

bias the existing priority of a process

  1. What are the Unix System calls for I/O?

Ans. A system call is a way through which programs interact with the operating system. Unix System calls are used for file management, process control, device management, information management, and communication. Below are some of the commonly used System calls for I/O:

Unix System calls for I/O

Description

open(pathname,flag,mode)

open file

close(filedes)

close an open file

creat(pathname,mode)

create file

write(filedes,buffer,bytes)

write data to an open file

read(filedes,buffer,bytes)

read data from an open file

lseek(filedes,offset,from)

position an open file

dup(filedes)

duplicate an existing file descriptor

dup2(oldfd,newfd)

duplicate to the desired file descriptor

ioctl(filedes,reuest,arg)

change behavior of an open file

fcntl(filedes,cmd,arg)

change properties of an open file

  1. Which command will be used to change the protection mode of files beginning with the string emp and finishing with 1 or 2?

Ans. chmod u+x emp[1-3]

  1. What is the use of the tee command?

Ans. Tee command is used for sending data from the standard point.

  1. What are directory navigation tools?

Ans. Directory navigation tools are performed on directories. For example:

  • rmdir
  • mkdir
  • pwd
  • Is
  • cd
  1. How can you remove a file in UNIX?

Ans. By using rm command.

Eg:

%rm <filename>

  1. Define Kernel?

Ans. The basic center of a computer operating system, it is the kernel job to regulate to access the system hardware.

  1. What are the main responsibilities of a shell?

Ans.

  • Filename and variable substitution
  • Integrated programming language
  • Pipeline hookup
  • Input/output redirection
  • Environment control
  1. What are the five variants of Linux?

Ans.

  • Debian
  • Fedora
  • Redhat
  • Ubuntu
  • Cent
  1. What data structures are used for Demand paging?

Ans.

  • Disk block descriptors
  • Page table entries
  • Swap-use table
  • Page frame data table
  1. What is ‘filters’?

Ans. In Unix, there are a number of Filters which are known as the programs for taking plain text. These plain texts are either stored in files or are produced by some other program. Further, these programs are transformed into a particular format that is designed to return standard outputs. 

Some of the most popular filters are:

Filter

Syntax

cat

cat [path]

head

head [-number_of_lines_to_print] [path]

tail

tail [-number_of_lines_to_print] [path]

sort

sort [-options] [path]

uni

uni [options] [path]

wc

wc [-options] [path]

grep

grep [options] pattern [path]

tac

tac [path]

sed

sed  [path]

nl

nl [-options] [path]

  1. What is the grep command?

Ans. GREP or Global Regular Expression Print is a Unix/Linux command-line tool that is used to locate a string of characters in a given file. Here the text search pattern is known as the regular expressions and as the tool finds the match, it prints the line. Further, this tool is compatible with large log files. Below is the method to use the grep command in Unix:

Grep Syntax – grep [options] pattern [files]

  1. State the description of the following commands.

Ans. 

Options

Description

-c

Prints only lines which is the exact match of the pattern

-i 

The matching case is ignored

-l

Displays a list of filenames only   

-f file 

Considers file patterns one from each line 

-o

Prints the matched parts in the matching line

  1. How to display the number of lines before or after a search string?

Ans. By adding the following operators to the desired lines before or after can help:

Action

Command

Print three lines after the match

grep –A 3 phoenix sample

Print two lines before the match

grep –A 2 phoenix sample

Print two lines before and after the match

grep –C 2 phoenix sample

  1. When to use -w option?

Ans. The -w option is used when one wants to search for a word and avoid it to match the substring. For example, if you want to search the word ‘to’ so the common result that you would get could be:

“To”, stool, too, tools, top, customer, automatic, etc. Thus the option -w helps. 

  1. Define inode.

Ans. An inode is a unique entry which by default gets created on a disk section for a file system. It contains the following information:

  • Location on the disk where the file starts
  • User ID of the file
  • Size of the file
  • Group ID of the file
  • Device ID
  • File size
  • Date of creation
  • Permission
  • Owner of the file
  • File protection flag
  • Link counter
  1. What are shell variables?

Ans. A variable refers to the character string to which a value is assigned and a shell enables the process of creating, assigning, and deleting variables. In Unix, the shell variables are denoted in uppercase. There are three main types of variables that are present in the shell:

  • Local variables
  • Environment variables
  • Shell variables

Syntax to define variable → variable_name=variable_value

  1. Define a Zombie process in UNIX.

Ans. A process is called a Zombie process when it has completed the execution stage (is dead) however, its entry has not vanished. Such entries are still visible in the process table. Usually, a situation like this generally arises when the child completes the process before the parent. Thus the child remains in the zombie state considering the fact that the parent might sometimes need the child even if the child’s execution has already happened. 

  1. What is the Orphan process?

Ans. An orphan process is determined as the process which is still in the execution stage however its parents have died. Once the parents die, init adopts the newly turned orphaned child process. The orphan process may occur intentionally or unintentionally. The intentional orphan process has no support when it runs in the background. However, the unintentional orphan process initiates when the process crashes or terminates.  

  1. State the meaning of following Debug Statement Options.

Ans. 

Debug Statement Options

Meaning

set -x

Print the statement once the interpretation of metacharacters and variables is finished

set -v

Print the statement before interpreting metacharacters and variables is finished

set +x

Stop statement printing

  1. What do you know about Until Loop?

Ans. Unlike the While loop, Until loop performs as long as the command fails, and once the command succeeds, the loop exits. Here is the syntax for:

until control_command 

do

    statement1

    …       

    statementN

Done

  1. Name some of the popular metacharacters (shell special characters)?

Ans. Below are some of the popular special characters used in Unix/Linux:

* ? [ ] ‘ ” \ $ ; & ( ) | ^ < > new-line space tab

  1. In Unix, how can you change Owners and Groups?

Ans. The following two commands help in changing ‘Owners and Groups’:

  1. chown − To “change owner” –  $ chown user filelist
  2. chgrp − – $ chgrp group filelist (To “change group”)
  1. Why does the command ‘cat’ basically do?

Ans. Cat command is used to create files (single or multiple), view contents of file, concatenate files or texts, and redirect output to files or terminal

cat [OPTION] [FILE]…

Function

Command

Display Contents of File

# cat /etc/passwd/  

View Contents of Multiple Files in terminal

# cat test test1

Create a File 

# cat >test2

  1. What is a Process in Unix?

Ans. It is one of the frequently asked Unix interview questions.

A process is a sequence of instructions or an instance of the program that is being executed. Any program executed creates a process. Processes can be manipulated similar to how files can be manipulated.

Process attributes: A process has several properties associated with it:

  • PID: Process-ID
  • PPID: Parent Process Id
  • TTY: Terminal with which the process is associated
  • UID: User Id

Process Control Commands: Many commands are available to review and manipulate processes. Some of them are listed below:

Command

Description

Ps

gives information of all the processes currently running for a user

Kill

terminates running processes

Bg

resumes suspended process while keeping them running in the background

Fg

Resumes a program that was stopped and bring it to the foreground

ps PID

gives status of a particular process

Pidof

gives Process ID of a process

  1. What is the command to view your username in Unix?

Ans. The whoami command is used in Unix Operating System to display the username of the currently logged-in user. It is the concatenation of the strings ‘who’, ‘am’, ’I’.

Syntax:

%whoami

  1. What are the Permissions and User grants available for Unix file system/users?

Ans. There are three access level permissions associated with each file:

  • User permission: level of access given to the user matching the file’s UID.
  • Group permission: level of access given to users in groups matching the file’s GID.
  • Others permission: level of access given to users without a matching UID or GID.

From a File point of view, a user will have three access rights:

  1. Read: The user can read the contents of the file. (denoted by r)
  2. Write: The user can modify the contents of the file. (denoted by w)
  3. Execute: The user can execute the files. (represented by x)

We can view the permissions associated with each of the files in the current folder using the ls -l command.

 

By bpci