WPF

Linux Interview Questions And Answers

More interview questions and answers

Why should we use Linux ?

Because of its four advantages:Freely distributed, functionality, Adaptability and Robustness.

What is Linux ?

Linux is a multi-user operating system, like Unix, having GUI environment.

Who developed the Linux ?

Linux was developed by LINUS TORVALDS, student of \'University of Helsinki\' in Finland.

Write about the versions of Linux ?

Previous version :version 0.02 in 1991, version 1.0 in 1994.
Current version  :version 2.6 in 2003.

What is the main use of Linux ?

It is primarily used as a Server-platform for the client-server environment.

what is knoppix ?

knoppix is CD version of the Linux. We can also work in Linux without installing it using bootable CD.

What are the different types of shell in Linux ?

Three types of shell in Linux are:
  •  Bourne again shell(bash),
  •  korn shell(ksh),
  •  c shell(csh).

What makes Linux so popular ?

Because it\'s source code is freely available for everyone and it is very easy to install, customize, and use.

What is \'tux\' ?

\'Tux\' is the official mascot,Linux Penguine of Linux.

How Linux is pronounced ?

Linux is pronounced as LIH-nucks.

What is the difference between Linux and Unix ?

Linux is an Operating system which use unix as its base and gives further more facilities and applications.Means, GUI is made in linux having unix as its core.

What is Kernel ?

It is the central component of the OS, which manages the system resources.We can say\"the system which provides the lowest-level abstraction layer for the resources\".

What terminology is used in the Linux ?

Different terminologies used in Linux are: Shell, Process, File, X-windows, Text-terminal, Session.

What do you mean by Linux utilities ?

Linux utilities are the most important system softwares which enables the user to interact with OS.

What do you mean by Shell and Shell command ?

Shell is the program for communication media between user and Linux OS.Shell commands that are part of command which are executed by shell.Ex- History.

What is System call ?

System calls are predefined function which are defined in the Linux library.Ex- fork().

How can we select the shell ?

To change the default login shell(bash), we use the \'chsh\' utility. 

What the following do ? echo, cd.

echo is for displaying the information and cd is for  changing directories.

What is the use of mkdir ?

It is used for creating the directory.

What do you mean by Metacharacters ?

Metacharcters are the special charcaters which has the special meaning in every shell.
EX- <, >, >>, ?, *.

Why we use ls ?

ls is used to list out the contents of directory.

What do you mean by redirection ?

With the help of redirection we can change the input output locations of the process ?

What are wildcards ?

wildcard is the facility that provides the better selection of files from the file system.

what do you understand by \'pipes\' ?

pipe is the method of using two or more than two commands to get the desired output.In this the output of the previous command becomes the input for the next command.

What do you mean by sequence ?

When we write some commands separated by semicolons, will execute individually in the given sequence. 

What are the shell scripts ? How we work on them ?

Normally shells are interactive. It means shell accept command from you (via keyboard) and execute them. But if you use command one by one (sequence of \'n\' number of commands) , the you can store this sequence of command to text file and tell the shell to execute this text file instead of entering the commands. This is know as shell script.
Before you can run a script, you must give it execute permission by using the chmod utility. Then, to run it, you only need to type its name.

What is the concept of Sub-shell or child-shell ?

the shell is called Child-shell of that shell by which it was created.

Write the steps for creating the shell scripts ?

Following steps are required to write shell script:
(1) Use any editor like vi or mcedit to write shell script.
(2) After writing shell script set execute permission for script.
(3) Execute the script

How to define \'user defined variables\' ?

To define UDV use following syntax
Syntax: variable name=value
Ex-$ no=10

What about ps, kill, wait ?Explain each.

These utilities or commands are used for the job control.
(1) ps: which generates a list of processes and their attributes, including their name, process ID number, controlling terminal, and owner
(2) kill: which allows you to terminate a process based on its ID number
(3) wait: which allows a shell to wait for one of its child processes to terminate.

Describe the following commands. eval, exec, shift, umask

The eval shell command executes the output of command as a regular shell command. The exec shell command causes the shell\'s image to be replaced with command in the process\' memory space.The shift shell command causes all of the positional parameters $2..$n to be renamed $1..$(n-1), and $1 to be lost.The umask shell command sets the shell\'s umask value to the specified octal number, or displays the current umask value if the argument is omitted. 

What are the different types of utilities which used to exchange the information over the internet ?

(1) Identifying network user:
    users, who, w, hostname, finger

(2) communicating with the network user
    write, talk, wall, mail

(3) distributing data
    rcp, scp, ftp, sftp, uucp

(4) distributed processing
    rlogin, slogin, rsh, ssh, telnet

What is desktop environment ?write its components also.

the graphical representation by icons and windows of all the programs that manage and render the conceptual desktop. 
components: Menus, icons ,status bar and a cursor.

What are the different desktop environments of linux ?

common desktop environment(CDE), GNU network object model environment(GNOME),K development envirnoment(KDE).

What is xclock and xterm ?

these commands are used for client applications

The xclock command provides a simple clock on your desktop.
The xterm command starts a terminal window on the desktop.

What is the C compiler in Linux ?

Linux distributions include GNU C (gcc) 

The gcc utility compiles C program code in one or more files and produces object modules or an executable file.

What is gprof and gdb ?

The gprof is a GNU profile, utility allows to obtain a program\'s profile.
The GNU debugger gdb allows to symbolically debug a program.

What is the use of strip utility ?

it is used to remove the extra code from the executable file ?

What are the main categories of linux system calls ?

there are three main categories of linux system calls :
  • file management
  • process management
  • error handling.

What do you mean by Interprocess communication ?

it is the method of enabling the two or more processes to communicate with each other for sharing the information.

which facilities are provided by the kernel ?

The kernel facilities may be divided into several subsystems:

  • memory management
  • process management
  • interprocess communication (IPC)
  • input/output
  • file management


Define file for Linux.

Basically files are used  for the long term storage.
Linux files are organized by a hierarchy of labels, commonly known as a directory structure. The files referenced by these labels may be of three kinds:

  • regular files
  • directory files
  • special files.

what are the main tasks of the system administrator ?

main  tasks of the system administrator are:
(1) starting and stopping Linux
(2) maintaining the file system
(3) maintaining the user a/cs
(4) maintaining the devices
(5) providing the secure environment

Create a shell program called time from the following command line: banner `date | cut -c12-19`

$ cat time 
banner `date | cut -c12-19` 
$ 
$ chmod u+x time 

Write a shell program that gives only the date in a banner display. Be careful not to give your program the same name as a UNIX system command.

   $ cat mydate
   banner `date | cut -c1-10`
   $

Write a shell program that sends a note to several people on your system.

$ cat tofriends
   echo Type in the name of the file containing the note.
   read note
   mail janice marylou bryan < $note
   $

Redirect the date command without the time into a file.

date | cut -c1-10 > file1 

Echo the phrase ``Dear colleague'' in the same file as the previous exercise, without erasing the date.

echo Dear colleague >> file1 

Using the above exercises, write a shell program that sends a memo to the same people on your system mentioned in Exercise 2-3. Include in your memo: • lines at the top that include the current date and the words ``Dear colleague'' • the body of the memo (stored in an existing file) • a closing statement

$ cat send.memo 
date | cut -c1-10 > memo1 
echo Dear colleague >> memo1 
cat memo >> memo1 
echo A memo from M. L. Kelly >> memo1 
mail janice marylou bryan < memo1 
$ 

How can you read variables into the mv.file program?

$ cat mv.file 
echo type in the directory path 
read path 
echo type in filenames, end with CTRL-d 
while 
read file 
do 
mv $file $path/$file 
done 
echo all done 
$ 

Use a for loop to move a list of files in the current directory to another directory. How can you move all your files to another directory?

$ cat mv.file 
echo Please type in directory path 
read path 
for file in $* 
do 
mv $file $path/$file 
done 
$ 
The command line for moving all files in the current directory is: 
   $ mv.file *

How can you change the program search, so that it searches through several files?

$ cat search 
for file 
in $* 
do 
if grep $word $file >/dev/null 
then echo $word is in $file 
else echo $word is NOT in $file 
fi 
done 
$ 

Set the stty options for your environment.

Add the following lines to your .profile: 
   stty -tabs
   stty erase
   stty echoe

Change your prompt to the word Hello

Add the following command lines to your .profile: 
   PS1=Hello
   export PS1

Check the settings of the variables $HOME, $TERM, and $PATH in your environment.

Enter the following commands to check the values of the HOME, TERM, and PATH variables in your home environment: 
•	$ echo $HOME 
•	$ echo $TERM 
•	$ echo $PATH 

State the variables in Linux shell.

Linux has two types of variables,local environmental    .Both stores data in string format.

What is quoting ?

quoting is the method in linux shell which is used to inhibit shell's wildcard-replacement, variable-substitution, and/or command-substitution mechanisms. 

what are 'Here documents ?

scripts that use << metacharacter to supply the standard input of other commands as inline text, called here documents.

what is job control in linux shell ?

Job control is to control the current processes according to their behavior to provide the multitasking environment.

what are the steps to find the command followed by linux ?

If it isn't a built-in command, the shell looks to see if the command begins with a / character. If it does, it assumes that the first token is the absolute pathname of a command, and tries to execute the file with the stated name. If the file doesn't exist or isn't an executable, an error occurs:

$ /bin/ls           ...full pathname of the ls utility.
script.csh  script.ksh
$ /bin/nsx          ...a nonexistent filename.
bash: /bin/nsx: not found
$ /etc/passwd       ...the name of the password file.
bash: /etc/passwd: Permission denied     ...it's not executable.
$ _



If it isn't a built-in command or a full pathname, the shell searches the directories whose names are stored in the PATH environment variable. Each directory in the PATH variable (from left to right) is searched for an executable matching the command name. If a match is found, the file is executed. If a match isn't found in any of the directories, or the file that matches is not executable, an error occurs.

why we supersede the standard utilities ?

when any user created a \"bin\" subdirectory in their home directory and place this subdirectory before the traditional \"bin\" directories in their PATH setting,
 it makes a problem as scripts run from a shell expect to use standard utilities and might be confused by the nonstandard utilities that actually get executed.
 So to handle this problem we use the superseding of standard utilities.

what do you mean by 'exit codes' ?

every linux process terminates with an exit value either 0 or any other value.these values are called exit codes.whether a process completes successfully returns 0 or becomes failure return other value.

What does the set command do ?

The set built-in command is used to set and display shell settings and to display the value of shell variables 
ex-
   $ set
gameslost=3
gameswon=12
teamname="Denver Broncos"
$ _

can bourne shell scripts run under bash ? if yes,explain.

yes, because bash is compatible with Unix's bourne shell.
Bash is installed as /bin/bash, but /bin/sh is a pointer to /bin/bash, since any script expecting Bourne shell functionality will run properly under Bash.

How to make bash as login shell ?

we have to add ".bashrc" file to our ".bash_profile" file:

how can we create and access a simple variable in bourne shell ?

there is an example to illustrate this:

$ verb=sing
$ echo I like $verbing
$ I like
$ echo I like ${verb}ing
$ I like singingq

How to create and assign a list variable ?Illustrate with example.

we create a list variable with declare keyword:

$ declare -a teamnames
$ teamnames[0]="india"
$ teamnames[1]="australia"
$ teamnames[2]="england"

$ echo there are "${#teamnames[*]} teams in the          IPL
$ there are 3 teams in the IPL

how to destroy the list variable ?

for this we use unset command
ex-
$ unset name[index]
$ unset teamnames[2]

how can we cerate the shortcut of commands ?

we can use following three methods for that-
aliases, command history, auto completion

what does the trap command do ?

The trap command allows you to specify a command that should be executed when the shell receives a signal of a particular value.
ex-

$ cat trap.sh                    ...list the script.
trap 'echo Control-C; exit 1' 2  # trap Ctl-C (signal #2)
while test 1
do
 echo infinite loop
 sleep 2                         # sleep for two seconds.

done
$ bash trap.sh                   ...execute the script.
infinite loop
infinite loop
^C                    ...I typed a Control-C here.
Control-C             ...displayed by the echo command.
$ _

how we make functions in bash ?

syntax:
function name
{
 list of commands
} or

name()
{
 list of commands
}

ex-

$ cat func2.sh               ...list the script.
f ()
{
 echo parameter 1 = $1      # display first parameter.
 echo parameter list = $*   # display entire list.
}
# main program.
f 1                          # call with 1 parameter.
f cat dog goat               # call with 3 parameters.
$ sh func2.sh                   ...execute the script.
parameter 1 = 1
parameter list = 1
parameter 1 = cat
parameter list = cat dog goat
$ _

can functions be exported to subshells ?if yes,how ?

yes,with help of export command.
ex-

export -f functionname 
 
The export built-in command used with the -f option exports a function to a subshell the same way exported shell variable values are exported to subshells.
 

how can we create menus in bash ?

the select command is used to create menus

ex-
$ cat newmenu.sh        ...list the script.
echo menu test program
select reply in "date" "pwd" "pwd" "exit"
do
 case $reply in
   "date")
     date
     ;;
   "pwd")
     pwd
     ;;
   "exit")
     break
     ;;
   *)
     echo illegal choice
     ;;
 esac
done
$ sh newmenu.sh            ...execute the script.
menu test program
1) date
2) pwd
3) pwd
4) exit
#? 1
Fri May    6 21:49:33 CST 2005
#? 5
illegal choice
#? 4
$ _

what does the following commands do ? cd, pushd ,popd ,dirs

Shell Command: cd { name }
               cd oldName newName
ex-
$ CDPATH=.:/usr  ...set my CDPATH.
$ cd dir1        ...move to "dir1", located under ".".
$ pwd
/home/glass/dir1
$ cd include     ...move to "include", located in "/usr".
$ pwd            ...display the current working dir.
/usr/include
$ cd -           ...move to my previous directory.
$ pwd            ...display the current working dir.
/home/glass/dir1
$ _

If the second form of cd is used, the shell replaces the first occurrence of the token oldName by the token newName in the current directory's full pathname, and then attempts to change to the new pathname.

Shell command: pushd [-n] [dir]
 
pushd saves the current directory as the most recent addition to (i.e., on top of) the directory stack.
 
Shell command: popd [-n]
 
popd retrieves the last directory that was pushed onto the stack and changes directory to that location.
 
Shell command: dirs [-cp]
 
If no arguments are given, dirs simply prints out the contents of the directory stack. The -p option causes the directories to be printed one per line. The -c option causes the directory stack to be cleared.
 



 

what does the following do ?jobs, bg, fg, kill.

shell command jobs:
 jobs displays a list of all the shell's jobs.
shell command bg:
 it resumes the specified job as the background process.

shell command fg:
 it resumes the specified job as the foreground process.

shell command kill:
 kill sends the specified signal to the specified process. Either jobspec (e.g., "%1") or a process ID is required. If the -s option is used, signame is a valid signal name (e.g., SIGINT). If the -n option is used, signum is the signal number. If neither -s nor -n is used, a SIGTERM signal is sent to the process.

what do you mean by pathnames ?explain.

A pathname is a sequence of directory names that lead you through the hierarchy from a starting directory to a target file.
ex-
File   Absolute PathName
 
A      /home/glass/myFile
 
B      /home/myFile
 
C      /bin/myFile
 

what are GNU utilities ?

GNU utilities are the software packages which are combined with linux kernel to make the linux very powerful and user interactive.
ex-
text editors, a C/C++ compiler, a sorting utility, a graphical user interface, several command shells, and text-processing tools. 

How can we run a GNU utility ?

To run a utility, simply enter its name and press the Enter key.
ex-date, 
which displays the current date and time:

$ date      ... run the date utility.
Mon Sep  6 11:25:51 CDT 2004

what are input, output and error channels ?

when we use linux for i/o operations we input something from keyboard and get the result on the screen.if we want to change in input and output, we can use following three channels:
 standard input:- stdin 
 standard output:- stdout
 standard error:- stderr  

what is the use of man utility ?

it is used to know about the utility which i want to         describe.
ex-
 man [ section ] word
 man -k keyword

 

 

which utility we use to list out the special characters of terminal ?

we use stty util. 
ex-
 $ stty -a      ...obtain a list of terminal
                   metacharacters

why we use passwd ?

passwd is used to change the password 
ex-
 $ passwd

why we use pwd ?

pwd displays the pathname of current working directory
ex-
 $ pwd
/home/glass

Linux Interview Questions And Answers