Linux system admin interview questions & answers



1) What is UNIX?

It is a portable operating system that is designed for both efficient multi-tasking and mult-user functions. Its portability allows it to run on different hardware platforms. It was written is C and lets user do processing and control under a shell.
 

2) What are filters?
The term Filter is often used to refer to any program that can take input from standard input, perform some operation on that input, and write the results to standard output. A Filter is also any program that can be used between two other programs in a pipeline.


3) What is a typical syntax being followed when issuing commands in shell?
Typical command syntax under the UNIX shell follows the format:
Command [-argument] [-argument] [--argument] [file]

4) Is there a way to erase all files in the current directory, including all its sub-directories, using only one command?

Yes, that is possible. Use “rm –r *” for this purpose. The rm command is for deleting files. The –r option will erase directories and subdirectories, including files within. The asterisk represents all entries.
 

5) What is the chief difference between the –v and –x option s to set?
The –v option echoes each command before arguments and variables have been substituted for; the –x option echoes the commands after substitution has taken place.

6) What is Kernel?
Kernel is the UNIX operating system. It is the master program that controls the computer’s resources, allotting them to different users and to different tasks. However, the kernel doesn’t deal directly with a user. Instead, it starts up a separate, interactive program, called a shell, for each user when he/she logs on.

7) What is Shell?
A shell acts as an interface between the user and the system. As a command interpreter, the shell takes commands and sets them up for execution.

8 ) What are the key features of the Korn Shell?
- history mechanism with built-in editor that simulates emacs or vi
- built-in integer arithmetic
- string manipulation capabilities
- command aliasing
- arrays
- job control

9) What are some common shells and what are their indicators?
sh – Bourne shell
csh – C SHell
bash – Bourne Again Shell
tcsh – enhanced C Shell
zsh – Z SHell
ksh – Korn SHell


10) Differentiate multiuser from multitask.
Multiuser means that more than one person can use the computer at the same time. Multitask means that even a single user can have the computer work on more than one task or program at the same time.

11) What is command substitution?
Command substitution is one of the steps being performed every time commands are processed by the shell. Commands that are enclosed in backquotes are executed by the shell. This will then replace the standard output of the command and displayed on the command line.
 

12) What is a directory?
Every file is assigned to a directory. A directory is a specialized form of file that maintains a list of all files in it.

13) What is inode?
An inode is an entry created on a section of the disk set aside for a file system. The inode contains nearly all there is to know about a file, which includes the location on the disk where the file starts, the size of the file, when the file was last used, when the file was last changed, what the various read, write and execute permissions are, who owns the file, and other information.

14) You have a file called tonky in the directory honky. Later you add new material to tonky. What changes take place in the directory, inode, and file?
The directory entry is unchanged, since the name and inode number remain unchanged. In the inode file, the file size, time of last access, and time of last modification are updated. In the file itself, the new material is added.

15) Describe file systems in UNIX
Understanding file systems in UNIX has to do with knowing how files and inodes are stored on a system. What happens is that a disk or portion of a disk is set aside to store files and the inode entries. The entire functional unit is referred to as a file system.

16) Differentiate relative path from absolute path.
Relative path refers to the path relative to the current path. Absolute path, on the other hand, refers to the exact path as referenced from the root directory.



17) Explain the importance of directories in a UNIX system
Files in a directory can actually be a directory itself; it would be called a subdirectory of the original. This capability makes it possible to develop a tree-like structure of directories and files, which is crucial in maintaining an organizational scheme.

18) Briefly describe the Shell’s responsibilities
- program execution
- variable and file name substitution
- I/O redirection
- pipeline hookup
- environment control
- interpreted programming language

19) What are shell variables?
Shell variables are a combination of a name ( identifier), and an assigned value, which exist within the shell. These variables may have default values, or whose values can be manually set using the appropriate assignment command. Examples of shell variable are PATH, TERM and HOME.




20) What are the differences among a system call, a library function, and a UNIX command?
A system call is part of the programming for the kernel. A library function is a program that is not part of the kernel but which is available to users of the system. UNIX commands, however, are stand-alone programs; they may incorporate both system calls and library functions in their programming.

21) What is Bash Shell?
It is a free shell designed to work on the UNIX system. Being the default shell for most UNIX-based systems, it combines features that are available both in the C and Korn Shell.

22) Enumerate some of the most commonly used network commands in UNIX
- telnet – used for remote login
- ping – an echo request for testing connectivity
- su – user switching command
- ftp – file transfer protocol used for copying files
- finger – information gathering command

23) Differentiate cmp command from diff command.
The cmp command is used mainly to compare two files byte by byte, after which the first encountered mismatch is shown. On the other hand, the diff command is used to indicate the changes that is to be made in order to make the two files identical to each other.




24) What is the use of -l when listing a directory?
-l, which is normally used in listing command like ls, is used to show files in a long format, one file per line. Long format refers to additional information that is associated with the file, such as ownership, permissions, data and filesize.



25)      How do you write the contents of 3 files into a single file?
cat file1 file2 file3 > file


2    26)  How to display the fields in a text file in reverse order?
awk 'BEGIN {ORS=""} { for(i=NF;i>0;i--) print $i," "; print "\n"}' filename



3    27)       Write a command to find the sum of bytes (size of file) of all files in a directory.
ls -l | grep '^-'| awk 'BEGIN {sum=0} {sum = sum + $5} END {print sum}'



4    28)    Write a command to print the lines which end with the word "end"?
grep 'end$' filename

The '$' symbol specifies the grep command to search for the pattern at the end of the line.



5   29)      Write a command to select only those lines containing "july" as a whole word?
grep -w july filename

The '-w' option makes the grep command to search for exact whole words. If the specified pattern is found in a string, then it is not considered as a whole word. For example: In the string "mikejulymak", the pattern "july" is found. However "july" is not a whole word in that string.



6   30)    How to remove the first 10 lines from a file?
sed '1,10 d' < filename



7   31)     Write a command to duplicate each line in a file?
sed 'p' < filename


8   32)   How to extract the username from 'who am i' comamnd?
who am i | cut -f1 -d' '


9   33)    Write a command to list the files in '/usr' directory that start with 'ch' and then display the number of lines in each file?
wc -l /usr/ch*

Another way is 

find /usr -name 'ch*' -type f -exec wc -l {} \;


3   34)   How to remove blank lines in a file ?
grep -v ‘^$’ filename > new_filename
 




1   35)  Write a command to remove the prefix of the string ending with '/'.
The basename utility deletes any prefix ending in /. The usage is mentioned below:
basename /usr/local/bin/file
This will display only file


1   36)   How to display zero byte size files?
ls -l | grep '^-' | awk '/^-/ {if ($5 !=0 ) print $9 }'



1   37)   How to replace the second occurrence of the word "bat" with "ball" in a file?
sed 's/bat/ball/2' < filename


1   38)   How to remove all the occurrences of the word "jhon" except the first one in a line with in the entire file?
sed 's/jhon//2g' < filename


1   39)   How to replace the word "lite" with "light" from 100th line to last line in a file?
sed '100,$ s/lite/light/' < filename


1   40)   How to list the files that are accessed 5 days ago in the current directory?
find -atime 5 -type f


1   41)   How to list the files that were modified 5 days ago in the current directory?
find -mtime 5 -type f


1   42)   How to list the files whose status is changed 5 days ago in the current directory?
find -ctime 5 -type f


1   43)   How to replace the character '/' with ',' in a file?
sed 's/\//,/' < filename
sed 's|/|,|' < filename
 
4   44)   Write a command to find the number of files in a directory.
ls -l|grep '^-'|wc -l
  





Comments

Popular posts from this blog

Defining Audit Rules

AIX Install packages, upgrade, patching commands

Oracle Database Quick Installation steps 11g Release 2 for Linux x86-64