ABHIONLINUX
Site useful for linux administration and web hosting

2009/11/01

Linux Interview Questions

How to change the modification time of a file use the following command:
touch -m

What is the default link count for files and directories in Linux?
The default link count:
files - 1
directory - 2

How to find only the number of lines in a files?
$ cat > f1

$ wc -l f1
4 f1

What is the difference between echo "$SHELL" and echo '$SHELL'?

$ echo "$SHELL"
/bin/bash


Code:
$ echo '$SHELL'
$SHELL

To check/list the attribute set for a file use the " lsattr " command.
# chattr +i my-file
# lsattr my-file
----i-------- my-file

How to set an append only attribute to a file in linux?
#chattr +a

How to lock the password for a user in linux?
# passwd -l
Password changed.


How to check the kernel version in linux?
$ uname -r
2.6.27-7-generic


How to check the used and free memory in linux?
$ free -m
total used free shared buffers cached
Mem: 1769 757 1011 0 20 302
-/+ buffers/cache: 434 1334
Swap: 7632 0 7632

How to set an immutable attribute to a file in linux?
#chattr +i

How to compare 2 files in linux?
Code:
#cmp

The -l option gives the detailed list of byte number.
Code:
#cmp -l


How to sort a file?
The command "sort" is used for alphabetically or numerically sort a file.

For eg: see the content of the file test
$ cat test
z
a
w
l
c

Inorder to sort the file we can use he sort command

$ sort test
a
c
l
w
z

One more ex: for a file containing numbers:

$ cat num
9
3
6
4

$ sort num
3
4
6
9
_________________



How to read the contents of a zip file without unzipping it?

Code:
zcat < file.gz >


How to suspend a running job and place it in the background?

Key combination " ctrl + z " will suspend a job and put it in the background.

Code:
ctrl+z


How to determine which shell you are using?

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.

Code:
echo $SHELL


What are the process states in Linux?

As a process executes it changes state according to its circumstances.
Linux processes have the following states:

Running : The process is either running or it is ready to run .
Waiting : The process is waiting for an event or for a resource.
Stopped : The process has been stopped, usually by receiving a signal.
Zombie : The process is dead but have not been removed from the process table.



Which command is used to check and repair the file system?

fsck is used to check the file system and repair damaged files.

Code:
# /etc/fsck /dev/file-system



What is LILO?

LILO - Linux Loader

Definition:
The first- and second-stage boot loaders combined are called Linux Loader (LILO). It loads the kernel into the memory and helps the system to boot.


What is a PID?

PID - Process Indentification number

Definition:
It is a number used by Unix/Linux kernels to identify a process.

Use ps command to see PID.


What is a zombie process?

Zombies are dead processes. You cannot kill the Zombie process as they are already dead. A process state becomes zombie when the child process dies before the parent process. The only way to remove all the zombie process is by killing its parent process.


How to list/display the last 5 lines of a file " myfile.txt "?

Lets create a file " myfile.txt "

Example:
Code:
:~/test$ cat > myfile.txt
1
2
3
4
5
6
7
8
9
Ctrl+d

To list the last 5 lines, use the following command.
tail -5 myfile.txt

The tail utility displays the end of a file. The -5 option tells the tail command to display the last 5 lines.

Example:
Code:
:~/test$ tail -5 myfile.txt
5
6
7
8
9



How to delete a file which starts with " - "? Eg: -foo

Let try creating a new file " -foo ".

Example:
Code:
:~/test$ echo "Testing" > -foo
:~/test$ ls -l
-rw-r--r-- 1 telson telson 8 2009-05-21 22:28 -foo


In the above example we create a new file " -foo ".
Now lets try deleting it.

Code:
:~/test$ rm -foo
rm: invalid option -- 'o'
Try `rm --help' for more information.


It seems we are unable to remove the file " -foo ", with the above given command.

How to remove the file " -foo "?

There is 2 ways to remove this file.

rm ./-foo
rm -- -foo

You may use any of the above commands.

Example:
Code:
:~/test$ rm -- -foo
:~/test$ ls -l
total 0


What is the difference between Hard Link and Soft Link in Linux?

Hard Link is a mirror copy of the original file. Hard links share the same inode.
Any changes made to the original or Hard linked file will reflect the other.
Even if you delete any one of the files, nothing will happen to the other.
Hard links can't cross file systems.

Soft Link is a symbolic link to the original file. Soft Links will have a different Inode value.
A soft link points to the original file. If you delete the original file, the soft link fails. If you delete the soft link, nothing will happen.
Soft links can cross file systems.



What is the difference between Telnet and SSH?

Both Telnet and SSH is used for remote Log-In and to trasnfer data.

Telnet -> Telecommunication network
It is not secure and anyone can use it. It uses ASCII format.
Information sent and received can be easily read by anyone (Hackers) in that network.

SSH -> Secure Shell
It is highly secure.
Information passed accross the network is encrypted.
Hackers will not be able to read your data.

So its highly recommended to use SSH to transafer data's securly.



What is Raid? What are the different Raid types and different Raid Levels?

RAID stands for Redundant Array of Independent (or Inexpensive) Disks. It is a set of Technology standards to improve Performence and Fault tolerance.
There are two types of raid :
Software Raid
Hardware Raid

Hardware Raid is most commenly used.

Raid Levels:
Raid 0 - stripping
Raid 1 - Mirroring
Raid 2 - Stripping and Mirroring
Raid 3 - Officially Not Defined
Raid 4 - Striping with Differential Parity
Raid 5 - Striping with Distributional Parity
Raid 10 - A mix of RAID 1 and RAID 0

No comments:

Post a Comment