Wednesday, 23 November 2011

Interview Linux Question & Answers-PART 1

  1. How do you find out all processes that are currently running? 

    1. ps -f (-f does full-format listing.)

  1. How do you kill a process?  

    1. 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)

  1. 3. How do you log in to a remote Unix box? 

    1. Using telnet server_name or ssh -l ( ssh - OpenSSH SSH client (remote login program))

  1. How do you get help on a UNIX terminal?

    1. man command_name
info command_name (more information)

  1. How do you list contents of a directory including all of its subdirectories, providing full details and sorted by modification time? 

    1. ls -lac
a all entries
c by time

  1. What is a filesystem?   

    1. 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.

  1. How do you check the sizes of all users home directories (one command)?

    1. du -s
The du command summarizes disk usage by directory. It recurses through all subdirectories and shows disk usage by each subdirectory with a final total at the end.

  1. How do you check for processes started by user 'pat'?

A. ps -fu pat   (-f -full_format u -user_name )

  1.  Explain iostat, vmstat and netstat. 

iostat reports on terminal, disk and tape I/O activity.
vmstat reports on virtual memory statistics for processes, disk, tape and CPU activity. netstat reports on the contents of network data structures.

  1. How do you list the files in an UNIX directory while also showing hidden files?

ls -ltra

  1. How do you execute a UNIX command in the background?  

Use the “&”.

  1. What UNIX command will control the default file permissions when files are created?  


  1. Explain the read, write, and execute permissions on a UNIX directory.

Read allows you to see and list the directory contents. Write allows you to create, edit and delete files and subdirectories in the directory. Execute gives you the permissions to run programs or shells from the directory.

  1. What is the difference between a soft link and a hard link? 

A symbolic (soft) linked file and the targeted file can be located on the same or different file system while for a hard link they must be located on the same file system.

  1. Give the command to display space usage on the UNIX file system.

df -lk

  1.  What’s in the file /etc/ttys?

Configuration for virtual consoles for the startup. By default FreeBSD has 8 virtual consoles.

  1. You’re told that the permissions of a file are 645. Quick, how do you calculate what it means?

The permissions value are always 4 for read, 2 for write, 1 for execute. The three numbers are always for owner, group, and everybody on the system. Therefore 645 means: owner - read and write, group - read only, everybody - read and execute.

  1. Explain what each column means in the top command:)

48630 techinterviews        2   0 29816K  9148K select   3:18  0.00%  0.00% navigator-linu
175 root                              2   0   924K   252K select   1:41  0.00%  0.00% syslogd
7059 techinterviews           2   0  7260K  4644K poll     1:38  0.00%  0.00% mutt
The first column is the process id, followed by the username, followed by priority…

  1. How do you change your shell to bash?  

% chsh -s /usr/local/bin/bash

  1.  What’s the command to stop Apache?  

kill the specific process that httpd is running under, or killall httpd. If you have apachectl installed, use apachectl stop.

  1. In Unix OS, what is the file server?  

Answer: The file server is a machine that shares its disk storage and files with other machines on the network.

  1. What is NFS? What is its job?

Answer: NFS stands for Network File System. NFS enables filesystems physically residing on one computer system to be used by other computers in the network, appearing to users on the remote host as just another local disk.

  1.  How do you check for the httpd.conf consistency and any errors in it? 

apachectl configtest

  1. When I do ps -aux, why do I have one copy of httpd running as root and the rest as nouser? 

You need to be a root to attach yourself to any Unix port below 1024, and we need 80.

  1.  What is LILO?

LILO stands for Linux boot loader. It will load the MBR, master boot record, into the memory, and tell the system which partition and hard drive to boot from.

26.   How do you log in to a remote Unix box? 
   Using telnet server_name or ssh -l ( ssh - OpenSSH SSH client (remote login program))
27.   What utility would you use to cut off the first column in a text file? 
         awk, kde
  1. How do you find out what’s your shell?  

echo $SHELL

  1. What’s the command to find out today’s date?  


  1. What’s the command to find out users on the system?  


  1. How do you find out the current directory you’re in?


  1. How do you remove a file?  

  1. How do you find out your own username?
  1. How do you count words, lines and characters in a file?  

  1. How do you search for a string inside a given file?  

grep string filename

  1. How do you search for a string inside a directory?  

grep string *

  1. How do you search for a string in a directory with the subdirectories recursed?  

grep -r string *

  1. What are PIDs? 

They are process IDs given to processes. A PID can vary from 0 to 65535.

  1. How do you list currently running process?  


  1. How do you stop a process?

kill pid

  1. How do you find out about all running processes?  

ps -ag

  1. How do you stop all the processes, except the shell window?  

kill 0

  1. How do you fire a process in the background?

/process-name &

  1. How do you refer to the arguments passed to a shell script?  

$1, $2 and so on. $0 is your script name.

  1. What’s the conditional statement in shell scripting?  

if {condition} then … fi

46.   What is 'inode'?  
All UNIX files have its description stored in a structure called 'inode'. The inode contains info about the file-size, its location, time of last access, time of last modification, permission and so on.
47.   What is a FIFO?
FIFO are otherwise called as 'named pipes'. FIFO (first-in-first-out) is a special file which I   s said to be data transient. Once data is read from named pipe, it cannot be read again.
48.   What is a shell?  
A shell is an interactive user interface to an operating system services that allows an user to enter commands as character strings or through a graphical user interface
49.   What is a zombie?
When a program forks and the child finishes before the parent, the kernel still keeps some of its information about the child in case the parent might need it - for example, the parent may need to check the child's exit status.

50.   How do you kill zombie process?

You cannot kill zombies, as they are already dead. But if you have too many zombies then kill parent process or restart service.

You can kill zombie process using PID obtained from any one of the above command. For example kill zombie proces having PID 4104:

kill -9 4104

51.   What are the process states in Unix?  
As a process executes it changes state according to its circumstances. Unix 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.

52.   What is Sticky bit ?

If the sticky bit is set for a directory, only the owner of the directory or the owner of a file can delete or rename a file within that directory

The sticky bit is an access-right flag that can be assigned to files and directories on Unix systems.

The most common use of the sticky bit today is on directories, where, when set, items inside the directory can be renamed or deleted only by the item's owner, the directory's owner, or the superuser (Without the sticky bit set, a user with write and execute permissions for the directory can rename or delete any file inside, regardless of the file's owner.)
  1. What is inode ?

Data structures that contain information about files in Unix file systems that are created when a file system is created. Each file has an inode and is identified by an inode number (i-number) in the file system where it resides. inodes provide important information on files such as user and group ownership, access mode (read, write, execute permissions) and type.
A file's inode number can be found using the ls -i command, while the ls -l command will retrieve inode information.

54.   How to see the free memory in Linux? 

/proc/meminfo   / free

55.   How you will see a port is opened or not? 

         netstat –an |grep LISTEN   (or)  nmap ipaddress

No comments:

Post a Comment