Friday, October 31, 2014

rpm interview questions and answers

Q: How to install packages with all the dependency packages if all the packages are available at a common repository?
Ans : rpm –ivh  –aid packagename.

Q: How to check, where a particular package installed it’s configuration files.
Ans : rpm –qc packagename.

Q: How to check the change log of the installed package.
Ans : rpm -q –changelog packagename.

Q: How to check, where a particular package installed it’s doc files.
Ans : rpm -qd packagenme

Q: How to check all the files installed by package?
Ans : rpm -q –filesbypkg packagename

Q: How to check the version of files installed by a package
Ans : rpm -qi packagename

Q: How to check the dependencies for a particular packages i.e. Required libraries packages etc.
Ans : rpm -q -R packagename.

Q: How to upgrade the packages which are already installed on to the linux box.
Ans : rpm -F install options packagename.

Q: What is the command to update only the rpm database.
Ans : rpm -i –justdb packagename

Q: What is the command to check whether a particular package installation would be successful but would not actually install the package.
Ans : rpm -ivh –test packagename

Q: How to check that a particular file belong to which package
Ans : rpm -qf filename

Q: How to list files in  a package
Ans : rpm -ql packagename

Q: How to verify whether the files installed by package are intact or been tampered/corrupted.
Ans : rpm -qs packagename

Q: What is the command to create a new RPM Database
Ans : rpm –initdb

Q: What is the command to rebuild the RPM Database
Ans : rpm –rebuilddb

What is the RPM switch for only installing packages?
The command line switch for installing an RPM is -i.

What is the command used to install an RPM package named demofilename2.2-2.i386.rpm?
The most common command used to install an RPM package is rpm -ivh. Following command will install the given package
#rpm -ivh demofilename2.2-2.i386.rpm

What is the command used to remove an RPM package named demofilename2.2-2.i386.rpm?
The most common command used to remove an RPM package is rpm -evh. Following command will remove the given package
#rpm -evh demofilename2.2-2.i386.rpm

What is the command used to update an RPM package named demofilename2.2-2.i386.rpm?
The most common command used to update an RPM package is rpm -Uvh. Following command will update the given package and remove the old.
#rpm -Uvh demofilename2.2-2.i386.rpm

Which command is used to see which RPM version of gzip was installed on the system?
#rpm -q gzip

Where are the automatically mounted file systems listed?
The automatically mounted file systems are listed in the file /etc/fstab.

While installing the new RPM what common steps should take ?
You should follow these common steps
  • Use RPM tools should be used to query or verify the installed packages to
  • confirm the installation of any previous packages.
  • Check the signature of new package
  • RPM should be installed or upgraded by first using the test mode to verify that it works, and then it should be installed
  • At the end query the RPM and verify the installation of RPM

Shell Scripting Interview Questions And Answers

Q: - What is Shell's Responsibilities ?
ANS:The shell is responsible for the execution of all programs that you request from your terminal. Each time you type in a line to the shell, the shell analyzes the line and then determines what to do.The line that is typed to the shell is known more formally as the command line. The shell scans this command line and determines the name of the program to be executed and what arguments to pass to the program.

Q: - What is "$#" Variable ?

The $# Variable
Whenever you execute a shell program, the special shell variable $# gets set to the number of arguments that were typed on the command line. 

Q: - Explain "Exit Status" for a shell script ?
Whenever any program completes execution under the Unix system, it returns an exit status back to the system. This status is a number that usually indicates whether the program successfully ran. By convention, an exit status of zero indicates that a program succeeded, and nonzero indicates that it failed. Failures can be caused by invalid arguments passed to the program, or by an error condition detected by the program. For example, the cp command returns a nonzero exit status if the copy fails for some reason (for example, if it can't create the destination file), or if the arguments aren't correctly specified (for example, wrong number of arguments, or more than two arguments and the last one isn't a directory). In the case of grep, an exit status of zero (success) is returned if it finds the specified pattern in at least one of the files; a nonzero value is returned if it can't find the pattern or if an error occurs (the arguments aren't correctly specified, or it can't open one of the files).

Q: - What is "Command Substitution" ?

Command substitution is the process by which the shell runs a command and replaces the command substitution with the output of the executed command. That sounds like a mouthful, but it's pretty straightforward in practice.
Q: - What is " eval" command ?

The eval command exists to supersede the normal command-line substitution and evaluation order, making it possible for a shell script to build up commands dynamically. This is a powerful facility, but it must be used carefully. Because the shell does so many different kinds of substitutions, it pays to understand the order in which the shell evaluates input lines. 

Q: - What is awk ?

An awk invocation can define variables, supply the program, and name the input files.

Q: - What is "grep" programe ?

The grep program is the primary tool for extracting interesting lines of text from input datafiles. POSIX mandates a single version with different options to provide the behavior traditionally obtained from the three grep variants: grep, egrep, and fgrep.

Q: - explain "read" command ?

The read command is one of the most important ways to get information into a shell program:
$ x=abc ; printf "x is now '%s'. Enter new value: " $x ; read x
x is now 'abc'. Enter new value: PDQ
$ echo $x

Q: - What are the two files used by the shell to initialize itself?

Q: - What is Interactive mode?
Interactive mode means that the shell expects to read input from you and execute the commands that you specify. This mode is called interactive because the shell is interacting with a user. This is usually the mode of the shell that most users are familiar with: you log in, execute some commands, and log out. When you log out using the exit command, the shell exits.

Q: - What is noninteractive mode?
In this mode, the shell does not interact with you; instead it reads commands stored in a file and executes them. When it reaches the end of the file, the shell exits.

Q: - what is local variable?
A local variable is a variable that is present within the current instance of the shell. It is not available to programs that are started by the shell. The variables that you looked at previously have all been local variables.

Q: - What is environment variable?
An environment variable is a variable that is available to any child process of the shell. Some programs need environment variables in order to function correctly. Usually a shell script defines only those environment variables that are needed by the programs that it runs.

Q: - What is shell variable?
A shell variable is a special variable that is set by the shell and is required by the shell in order to function correctly. Some of these variables are environment variables whereas others are local variables.

Q: - Explain the “Exit” command?
Every program whether on UNIX or Linux should end at a certain point of time and successful completion of a program is denoted by the output 0. If the program gives an output other than 0 it defines that there has been some problem with the execution or termination of the problem. Whenever you are calling other function, exit command gets displayed.

Q: - How do you find out what’s your shell?
echo $SHELL

Q: - How you will run a process in the background?
./ProcessName &

Q: - How do you write a while loop in shell?
Use While Loop
while [ condition ]


while [ $x -le 5 ]
  echo "Welcome $x times"
  x=$(( $x + 1 ))

Q: - How do you read keyboard input in shell scripts?
Use read command

Q: - What is GUI Scripting?
Graphical user interface provided the much needed thrust for controlling a computer and its applications. This form of language simplified repetitive actions. Support for different applications mostly depends upon the operating system. These interact with menus, buttons, etc.

Q: - Explain the term “loops”?
Loops enable you to execute a series of commands multiple times. Two main types of loops are the while and for loops.

Q: - What is “Nested Loops”?
When a loop is located inside the body of another loop it is said to be nested within another loop.

Q: - What is “Infinite Loops”?
Loops that execute forever without terminating.

Q: - What is “File Descriptor”?
An integer that is associated with a file. Enables you to read and write from a file using the integer instead of the file's name.

Q: - Explain “STDIN”?
STDIN Standard Input. User input is read from STDIN. The file descriptor for STDIN is 0.

Q: - Explain “STDOUT”?
STDOUT Standard Output. The output of scripts is usually to STDOUT. The file descriptor for STDOUT is 1.

Q: - Explain “STDERR”?
STDERR Standard Error. A special type of output used for error messages. The file descriptor for STDERR is 2.

Q: - Explain “Escape Sequence”?
An escape sequence is special sequence of characters that represents another

Q: - Explain “Output Redirection” in shell scripting?
In UNIX or Linux, the process of capturing the output of a command and storing it in a file is called output redirection because it redirects the output of a command into a file instead of the screen.

Q: Explain “Input Redirection” in shell scripting?
In UNIX or Linux the process of sending input to a command from a file is called input redirection.

Q: - What is “Field separator”?
The field separator controls the manner in which an input line is broken into fields. In the shell, the field separator is stored in the variable IFS. In awk, the field separator is stored in the awk variable FS.

Q: - What is “Library”?
A file that contains only functions is called a library. Usually libraries contain no main code.

Monday, October 27, 2014

difference between soft links and hard links in linux

Hard Link acts like a mirror copy of the original file. These links share the same inodes. Changes made to the original or hard linked file will reflect the other. When you delete hard link nothing will happen to the other. Hard links can't cross file systems.

Soft Link is actual link to the original file. These Links will have a different Inodes value. Soft link points to the original file so If original file is deleted the soft link fails. If you delete the soft link, nothing will happen to file. The reason for this is, the actual file or directory’s inode is different from the "soft link" created file's inode, Hard links can cross file systems.
What are Hard Links

1. Hard Links have same inodes number.
2. ls -l command shows all the links with the link column shows number of links.
3. Links have actual file contents
4. Removing any link, just reduces the link count, but doesn't affect other links.
5. You cannot create a hard link for a directory.
6 If original file is removed then the link will still show you the content of the file.

What are Soft Links

1. Soft Links have different inodes numbers.
2. ls -l command shows all links with second column value 1 and the link points to original file.
3. Soft Link contains the path for original file and not the contents.
4. Removing soft link doesn't affect anything but removing original file, the link becomes "dangling" link which points to nonexistent file.
5. A soft link can link to a directory.

Let us try to see some experimental differences. Make a new directory called hard and then move into it and create new file. Simply follow below steps.

Hard links

$ mkdir hard
$ cd hard
$ touch file1

Now, create a hard link to file1. Name the hard link file2.

$ ln file1 file2

Display inodes for both files using ‘I’ argument of the ls command.

$ ls -il file1 file2

This is what you get:
1482256 -rw-r--r-- 2 bruno bruno 21 May 5 15:55 file1
1482256 -rw-r--r-- 2 bruno bruno 21 May 5 15:55 file2

From the output you can notice that both file1 and file2 have the same inode number (1482256). Also both files have the same file permissions and the same size.

Now Remove the original file1

$ rm file1

After removing hard link just have a look at the content of the "link" file2.

$ cat file2

You will still be able to see the content of the file.

Symbolic links

Create soft link for the file file2.
$ ln -s file2 file3

Display inodes for both using i argument of ls command.

$ ls -il file2 file3

This is what you'll get:
1482256 -rw-r--r-- 1 bruno bruno 21 May 5 15:55 FileB
1482226 lrwxrwxrwx 1 bruno bruno 5 May 5 16:22 FileC -> FileB

From the output you can notice that the inodes are different and the symbolic link got a "l" before the rwxrwxrwx. The permissions are different for the link and the original file because it is just a symbolic link.

Now list the contents:

$ cat file2
$ cat file3

Now remove the original file:

$ rm file2

And then check the Test directory:

$ ls 

It will still display symbolic link file3 but if you try to list the contents It will tell you that there is no such file or directory.

$ cat file3

Now you know about some of the key differences between hard links and soft links to make it easier to access files and run programs.