Linux Interview Questions And Answers
More interview questions and answers |
---|
Because of its four advantages:Freely distributed, functionality, Adaptability and Robustness. |
Linux is a multi-user operating system, like Unix, having GUI environment. |
Linux was developed by LINUS TORVALDS, student of \'University of Helsinki\' in Finland. |
Previous version :version 0.02 in 1991, version 1.0 in 1994. |
It is primarily used as a Server-platform for the client-server environment. |
knoppix is CD version of the Linux. We can also work in Linux without installing it using bootable CD. |
Three types of shell in Linux are:
|
Because it\'s source code is freely available for everyone and it is very easy to install, customize, and use. |
\'Tux\' is the official mascot,Linux Penguine of Linux. |
Linux is pronounced as LIH-nucks. |
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. |
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\". |
Different terminologies used in Linux are: Shell, Process, File, X-windows, Text-terminal, Session. |
Linux utilities are the most important system softwares which enables the user to interact with OS. |
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. |
System calls are predefined function which are defined in the Linux library.Ex- fork(). |
To change the default login shell(bash), we use the \'chsh\' utility. |
echo is for displaying the information and cd is for changing directories. |
It is used for creating the directory. |
Metacharcters are the special charcaters which has the special meaning in every shell. |
ls is used to list out the contents of directory. |
With the help of redirection we can change the input output locations of the process ? |
wildcard is the facility that provides the better selection of files from the file system. |
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. |
When we write some commands separated by semicolons, will execute individually in the given sequence. |
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. |
the shell is called Child-shell of that shell by which it was created. |
Following steps are required to write shell script: |
To define UDV use following syntax |
These utilities or commands are used for the job control. |
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 |
the graphical representation by icons and windows of all the programs that manage and render the conceptual desktop. |
common desktop environment(CDE), GNU network object model environment(GNOME),K development envirnoment(KDE). |
these commands are used for client applications |
Linux distributions include GNU C (gcc) |
The gprof is a GNU profile, utility allows to obtain a program\'s profile. |
it is used to remove the extra code from the executable file ? |
there are three main categories of linux system calls :
|
it is the method of enabling the two or more processes to communicate with each other for sharing the information. |
The kernel facilities may be divided into several subsystems:
|
Basically files are used for the long term storage.
|
main tasks of the system administrator are: |
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 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 $ |
date | cut -c1-10 > file1 |
echo Dear colleague >> file1 |
$ 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 $ |
$ 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 $ |
$ 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 $ |
Add the following lines to your .profile: stty -tabs stty erase stty echoe |
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 |
Linux has two types of variables,local environmental .Both stores data in string format. |
quoting is the method in linux shell which is used to inhibit shell's wildcard-replacement, variable-substitution, and/or command-substitution mechanisms. |
scripts that use << metacharacter to supply the standard input of other commands as inline text, called here documents. |
Job control is to control the current processes according to their behavior to provide the multitasking environment. |
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. |
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. |
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. |
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" $ _ |
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. |
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 |
for this we use unset command ex- $ unset name[index] $ unset teamnames[2] |
we can use following three methods for that- aliases, command history, auto completion |
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. $ _ |
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 $ _ |
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. |
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 $ _ |
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. |
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. |
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 |
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. |
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 |
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 |
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 |
passwd is used to change the password ex- $ passwd |
pwd displays the pathname of current working directory ex- $ pwd /home/glass |