Showing posts with label shell. Show all posts
Showing posts with label shell. Show all posts

February 11, 2021

Top 20 Linux Interview Questions and Answers

Ques. 1): How can Linux be differentiated from other Operating Systems?
Linux is somewhat like other operating systems you might have used before, such as OS X, iOS or the Windows. Like other operating systems, Linux too has a graphical user interface. The types of software just like other operating systems have, such as the word processing applications.
 But Linux is different from other operating systems in many ways. First and foremost, Linux is open source software. The code used to create the OS is always free and available to the public to view, contribute and edit. Secondly, although the core pieces of the Linux OS are generally common, there are quite many distributions of Linux, which include different software options, which implies Linux is incredibly customizable. Linux users can also choose core components, such as the system displays graphics and other UI components.

Ques. 2): What is the basic difference between UNIX and Linux Operating System.
Linux Operating System is Free and Open Source Software, the kernel of which is created by Linus Torvalds and community. Well you cannot say UNIX Operating System doesn’t comes under the category of Free and Open Source Software, BSD, is a variant of UNIX which comes under the category of FOSS. Moreover Big companies like Apple, IBM, Oracle, HP, etc. are contributing to UNIX Kernel.

Ques. 3): What Is Shell Script?
A shell script, as the name suggests, is a script written for the shell. Script here means a programming language used to control the application. The shell script allows different commands entered in the shell to be executed. Shell script is easy to debug, quicker as compared to writing big programs. However, the execution speed is slow because it launches a new process for every shell command executed. Examples of commands are cp, cn, cd.

Ques. 4): What Are Pipes?
A pipe is a chain of processes so that output of one process (stdout) is fed an input (stdin) to another. UNIX shell has a special syntax for creation of pipelines. The commands are written in sequence separated by |. Different filters are used for Pipes like AWK, GREP.
e.g. sort file | lpr ( sort the file and send it to printer)

Ques. 5): What Stateless Linux Server? What Feature It Offers?
A stateless Linux server is a centralized server in which no state exists on the single workstations. There may be scenarios when a state of a partilcuar system is meaningful (A snap shot is taken then) and the user wants all the other machines to be in that state. This is where the stateless Linux server comes into picture.

·       It stores the prototypes of every machine.
·       It stores snapshots taken for those systems.
·       It stores home directories for those system.

Uses LDAP containing information of all systems to assist in finding out which snapshot (of state) should be running on which system.

Ques. 6): What Is Bash Shell?
Bash is a free shell for UNIX. It is the default shell for most UNIX systems. It has a combination of the C and Korn shell features. Bash shell is not portable. any Bash-specific feature will not function on a system using the Bourne shell or one of its replacements, unless bash is installed as a secondary shell and the script begins with #!/bin/bash. It supports regular and expressions. When bash script starts, it executes commands of different scripts.

Ques. 7): What Is A Zombie?
Zombie is a process state when the child dies before the parent process. In this case the structural information of the process is still in the process table. Since this process is not alive, it cannot react to signals. Zombie state can finish when the parent dies. All resources of the zombie state process are cleared by the kernel.

Ques. 8): Explain Each System Calls Used For Process Management In Linux.
System calls used for Process management:
·       Fork () :- Used to create a new process
·       Exec() :- Execute a new program
·       Wait():- wait until the process finishes execution
·       Exit():- Exit from the process
·       Getpid():- get the unique process id of the process
·       Getppid():- get the parent process unique id
·       Nice():- to bias the existing property of process

Ques. 9): How Do You Kill A Process?
kill -9 8 (process_id 8) or kill -9 %7 (job number 7)
kill -9 -1 (Kill all processes you can kill.)
killall - kill processes by name most (useful - killall java)

Ques. 10): What Is A Filesystem?
Sum of all directories called file system. A file system is the primary means of file storage in UNIX. File systems are made of inodes and superblocks.

Ques. 11): What Are Two Subtle Differences In Using The More And The Pg Commands?
With the more command you display another screenful by pressing the spacebar, with pg you press the return key. The more command returns you automatically to the UNIX shell when completed, while pg waits until you press return.

Ques. 12): We Saw the Mention On The Linux Bios Website About One Million Devices Shipped With Linux Bios. Could You Tell Us More About These Devices?
Yes, these are internet terminals that were built in India, based on the [x86 system-on-chip] STPC chip, I am told; also, there evidently is a Turkish-built digital TV that runs Linux BIOS. I have also heard that there are routers and many other embedded devices running Linux BIOS. I think at this point that 1 million is a low number. I am in contact with other set-top box vendors that are talking about numbers in the lOs of millions for their products. These numbers actually make the OLPC numbers seem small, which is in it amazing.

Ques. 13): What's Your Goal For Your Talk At Fosdem?
I’d like to communicate the basic ideas — that Linux is a good BIOS, and why; why Linux BIOS is built the way it is; where we are going; and how people can help. Most importantly, why it all matters — and it really matters a lot. We’re on the verge of losing control of the systems we buy, and we need to make a conscious effort, as a community, to ensure this loss of control does not happen. That effort will not be without some sacrifice, but if we are to maintain our ability to use and program our machines, and have fun with them, we have to act now. Because, if the computing business stops being fun, what’s the point$

Ques. 14): What Command Would You Use To Create An Empty File Without Opening It To Edit It?
You use the touch command to create an empty file without needing to open it. Answers a and e point to invalid commands, though either of these might actually be aliased to point to a real command. Answers b and c utilize editors, and so do not satisfy the requirements of the question. actually touch is used to change the timestamps of a file if its exits, otherwise a new file with current timestamps will be created.

Ques. 15): What Do You Type To Stop A Hung Process That Resists The Standard Attempts To Shut It Down?
The kill command by itself tries to allow a process to exit cleanly. You type kill -9 PID, on the other hand, to abruptly stop a process that will not quit by any other means. Also, pressing CtrI+C works for many programs. Answers b and d are only valid in some contexts, and even in those contexts will not work on a hung process.

Ques. 16): What Are The Techniques That You Use To Handle The Collisions In Hash Tables?
We can use two major techniques to handle the collisions. They are open addressing and separate chaining. In open addressing, data items that hash to a full array cell are placed in another cell in the array. In separate chaining, each array element consists of a linked list. All data items hashing to a given array index are inserted in that list.

Ques. 17): Why You Shouldn't Use The Root Login?
The root login does not restrict you in any way. When you log in as root, you become the system. The root login is also sometimes called the super user login. With one simple command, issued either on purpose or by accident, you can destroy your entire Linux installation. For this reason, use the root login only when necessary. Avoid experimenting with commands when you do log in as root.

Ques. 18): What Can You Type At A Command Line To Determine Which Shell You Are Using?
echo $SHELL-The name and path to the shell you are using is saved to the SHELL environment variable. You can then use the echo command to print out the value of any variable by preceding the variable’s name with $. Therefore, typing echo $SHELL will display the name of your shell.

Ques. 19): Is Linux Operating system Virus free?
No! There doesn’t exist any Operating System on this earth that is virus free. However Linux is known to have least number of Viruses, till date, yes even less than UNIX OS. Linux has had about 60-100 viruses listed till date. None of them actively spreading nowadays. A rough estimate of UNIX viruses is between 85 -120 viruses reported till date.

Ques. 20): How do you change permissions under Linux?
Assuming you are the system administrator or the owner of a file or directory, you can grant permission using the chmod command. Use + symbol to add permission or – symbol to deny permission, along with any of the following letters: u (user), g (group), o (others), a (all), r (read), w (write) and x (execute). For example, the command chmod go+rw FILE1.TXT grants read and write access to the file FILE1.TXT, which is assigned to groups and others.

January 15, 2020

Top 20 Unix interview Questions & Answers

Ques: 1. What is the Importance of writing Shell Scripts?

Ans: The points given below explain the importance of writing shell scripts. Shell script takes input from the user, file and displays it on the screen. Shell scripting is very useful in creating your own commands. It is helpful in automating some tasks of the day to day life. It is useful for automating system administration tasks. Mainly it saves time.

Ques: 2. What are the different Types of Shells available? 

Ans: There are mainly 4 important types of shells that are widely used. And they include:
  1. Bourne Shell (sh)
  2. C Shell (csh)
  3. Korn Shell (ksh)
  4. Bourne Again Shell (bash)

Ques: 3. What are the Advantages of C Shell over Bourne Shell?

Ans: The advantages of C Shell over Bourne Shell are:
  • C shell allows aliasing of commands i.e. a user can give any name of his choice to the command. This feature is mainly useful when a user has to type the lengthy command again and again. At that point of time, instead of typing a lengthy command a user can type the name that he has given.
  • C shell provides command history feature. C shell remembers the previously typed command. Thus, it avoids typing the command again and again.

Ques: 4. What are the two types of Shell Variables? Explain in brief.

Ans: The two types of shell variables are: 

1). Unix Defined Variables or System Variables – These are standard or shell defined variables. Generally, they are defined in CAPITAL letters. 

for example: SHELL – This is a Unix Defined or System Variable, which defines the name of the default working shell. 

2). User Defined Variables – These are defined by users. Generally, they are defined in lower letters. 

For example: $ a=10 –Here the user has defined a variable called ‘a’ and assigned value to it as 10.

Ques:5. What are positional parameters? Explain with an example.

Ans: Positional parameters are the variables defined by a shell. And they are used whenever we need to convey information to the program. And this can be done by specifying arguments at the command line.

There are totally 9 positional parameters present i.e. from $1 to $9.

Example: $ Test Indian IT Industry has grown very much faster

In the above statement, positional parameters are assigned like this.

$0 -> Test (Name of a shell program/script)
$1 ->Indian
$2 -> IT and so on.

Ques: 6. What are the three different security provisions provided by UNIX for a file or data?

Ans: Three different security provisions provided by UNIX for a file or data are:
  1. It provides a unique user id and password to the user, so that unknown or unauthorized person should not be able to access it.
  2. At file level, it provides security by providing read, write & execute permissions for accessing the files.
  3. Lastly, it provides security using file encryption. This method allows encoding a file in an unreadable format. Even if someone succeeds in opening a file, but they cannot read its contents until and unless it is decrypted.

Ques: 7. What are control instructions and how many types of control instructions are available in a shell? Explain in brief.

Ans: Control Instructions are the ones, which enable us to specify the order in which the various instructions in a program/script are to be executed by the computer. Basically, they determine a flow of control in a program.

There are 4 types of control instructions that are available in a shell:
  1. Sequence Control Instruction – This ensures that the instructions are executed in the same order in which they appear in the program.
  2. Selection or Decision Control Instruction – It allows the computer to take a decision as to which instruction is to be executed next. 
  3. Repetition or Loop Control Instruction – It helps a computer to execute a group of statements repeatedly. 
  4. Case-Control Instruction – This is used when we need to select from several alternatives.

Ques: 8. What are the two files of crontab command?

Ans: Two files of crontab command are:
  1. cron.allow – It decides which users need to be permitted from using crontab command. 
  2. cron.deny – It decides which users need to be prevented from using crontab command.

Ques: 9. What are the different commands available to check the disk usage?

Ans: There are three different commands available to check the disk usage. And they are:

  1. df – This command is used to check the free disk space.  
  2. du – This command is used to check the directory wise disk usage.  
  3. dfspace – This command is used to check the free disk space in terms of MB.

Ques: 10. What is Shebang in a shell script?

Ans: Shebang is a # sign followed by an exclamation i.e. !. Generally, this can be seen at the beginning or top of the script/program. Usually, a developer uses this to avoid repetitive work. Shebang mainly determines the location of the engine which is to be used in order to execute the script.

Here ‘#’ symbol is called as hash and ‘!’ is called a bang.

Example: #!/bin/bash

The above line also tells which shell to use.

Ques: 11. What is inode?

Ans. The inode is a data structure in a file system. Each inode is able to store the attributes and the location (s) of the disk block of the object’s data.

Ques: 12. What is the difference between Swapping and Paging?


Swapping: Whole process is moved from the swap device to the main memory for execution. Process size must be less than or equal to the available main memory. It is easier to implementation and overhead to the system. Swapping systems does not handle the memory more flexibly as compared to the paging systems.

Paging: Only the required memory pages are moved to main memory from the swap device for execution. Process size does not matter. Gives the concept of the virtual memory. It provides greater flexibility in mapping the virtual address space into the physical memory of the machine. Allows more number of processes to fit in the main memory simultaneously. Allows the greater process size than the available physical memory. Demand paging systems handle the memory more flexibly.

Ques: 13. What is the difference between $* and $@?

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

Ques: 14. Write down syntax for all loops in shell scripting ?
Ans: The syntax for all loops in unix:

for loop:

for i in $( ls ); do
echo item: $i

while loop:

while [ $COUNTER -lt 10 ]; do
echo The counter is $COUNTER

until loop:

until [ $COUNTER -lt 10 ]; do
let COUNTER-=1

Ques: 15. Can you link directories to hard links?

Ans: You cannot link directories to hard links and the reason behind it is quite technical. For now, you can learn that directories don’t fit into the system and essentially break it. So, in order to protect the file system structure, directories are avoided link with hard links.

Ques: 16. What are the security provisions provided by the Unix to protect the system?

Ans: In order to protect valuable information and files, Unix provides three key security provisions:
  1. It provides a unique ID and password to its every user so; no unauthorized access can be granted to anyone. 
  2. On each file, it offers read, writes and execute permission so, the user can grant permission he or she thinks is necessary to the third party. 
  3. Lastly the Unix offers security through the encryption which is one of the best ways to secure your file and data.

Ques: 17. Write down modes of operations in Vi editors and describe them?

Ans: Three significant modes of operation Vi include:
  • Insert mode: this mode will allow you to insert edit the existing text or add the new text in the command line. 
  • Command mode: in this mode, you can use the keyboard to make all the commands. 
  • The ex-command mode: with this mode, you can enter the command in the command line.

Ques: 18. If one process is inserting data into your MySQL database? How will you check how many rows inserted into every second?

Ans: Purpose of this Unix Command Interview is asking about "watch" command in UNIX which is repeatedly execute command provided with specified delay.

Ques: 19. What is break statement why do we use it?

Ans: The break refers to the command that is used whenever the user wants to directly jump out of the loop rather than following the path which leads back to the control command. Every single time break statement takes place in the program, the control automatically gets passed after the first line of command.

Ques 20: How will you run a process in background? How will you bring that into foreground and how will you kill that process?

Ans: For running a process in background use "&" in command line. For bringing it back in foreground use command "fg jobid" and for getting job id you use command "jobs", for killing that process find PID and use kill -9 PID command. This is indeed a good Unix Command interview questions because many of programmer not familiar with background process in UNIX.