Monday, March 2, 2015

Basic Unix Stuffs



1) What is a shell?  Name the different types of shell

Shell is a command line interpreter. It's an interface that sits between the user and the hardware.

The different types of shells are

a) C shell ( csh) ---> Linux
b) Bash shell ( bash) -------> Linux
c)  Bourne shell ( sh) -------> Unix/Solaris
d) T Shell (Tcsh)
e) Korn Shell (ksh) ----------> AIX
f) Z shell ( zsh)




2) What is the command to know your current shell?

Echo $SHELL




3) How do you locate a unix command's executable i.e how do you locate a command?

"TYPE" command.
If you have to find the executable or location to see where is 'ls' command located, then give the below command

type 'ls'
result is : ls is /bin/ls



4) Where are most of the unix commands stored?

/bin and /usr/bin directories




5) When you give a command on a shell prompt, where all places does the shell usually searches to find the location of the command?

/bin/  
/usr/bin
/usr/local/bin
/usr/local/java/bin




6) What is a PATH and how to find it?

The sequence of directories that a shell searches to look for a command.
The command to find the PATH is  echo $PATH




7) What is an Internal command?

They are shell-built in commands.
Internal command are not present in /bin or /usr/bin directory. Even if they are present in these directories, they won't be executed.
Example : Echo, PWD, CD




8) What is a External command?

External commands are not shell built-in.
They are executed by /bin and /usr/bin

Example : LS, DATE, MV, CP




9) Is shell an external command or Internal command?

Shell is an external command with its own set of internal commands. ie Shell has its executable shown up when you give echo $PATH. However, it does have specific internal commands within it as well.




10) Does Internal command have more precedence than external command?

Yes. Internal command has more precedence( more priority).  Example : Echo command is both internal and external command.
When a user gives echo command on the prompt, the shell executes "ECHO" from its own internal commands rather than executing the "ECHO" from /bin directory.





11) When you give ls -Z "filename", what happens? Explain

When a user gives ls -Z "filename", the shell interprets and sees that the command is incorrect.
The command then displays an error that ls : illegal option -Z. 
This message comes from the command and not the shell. The command LS recognizes that -Z is not one of it's valid options.

Another example is

$ ls-l
bash:  ls-l: command not found.

when giving options, we need to make sure that space is given between ls and -l



12) What is a command line?

Command line is a command with arguments and options

example :   ls -ltr filename

ls -ltr filename ------> The whole command
ltr ---------------------> option
filename --------------> argument


Example 2

 ls --all   -------------------->>> you can also two hypens(--)

The options can also be (-) or (+) or (=!)

The difference between an argument and option is that an option is also an argument but used with (-) hyphen.


13) List one command that doesn't accept any arguments and options?

PWD ( Print working Directory)




14) How can one combine two or more unix commands and redirect the output to a file?

Combining two commands can be done by piping and output can be redirected via tee command or redirection operator

Example

( ls -ltr filename.txt | wc -l ) > output.txt


Explaination

Filename.txt is the input file which is listed in the latest modified time. i.e ls -ltr filename.txt.  
The output of this file is given as an input to the command wc -l. 
This is possible by using the pipe operator (|). The pipe operator combines two commands. This command gives the number of lines from the filename.txt.
The final output is then redirected to a new fresh file which gets created by name "output.txt".

The overall advantage is that you don't have to type three commands one by one and instead can get the task done in one line command.




15) What is MAN Command?

Man command stands for manual documentation in Unix system. UNIX OS has thousands of commands and there is a manual for each and every command with detailed description.

If you want to know what is the manual for Date command. Give " $ man date".

It will list out

NAME  -----> One line description of the command
SYNOPSIS ----->> Syntax of the command
DESCRIPTION ------>>> Detailed information of the command.
Options
OPERANDS
USAGE
EXIT Status




16)  How does MAN Command work internally?

When user gives man wc, the output is displayed to the console. This is possible by sending the output of WC manual pages to a program called "PAGER".

PAGER is a program is also a command. MAN always works with either one of the below PAGER programs

a) MORE
b) LESS  ----- >  Its more powerful than "MORE" command.


Inorder to navigate through MAN pages, press "f" or spacebar to move forward one page at a time.
Use "b" key to move pages backward.

To search for keyword within Man pages output, use the "/" followed by search string and press enter
i.e  /searchpattern

To repeat the search, use 'n'

To quit Man pages, press 'q'


17) How to know the default PAGER value and how to set it to a different value?

$ echo $PAGER.  -------> Command to know the default value of your PAGER

To set a pager to your desired settings,

$ PAGER = less/more -----> Choose if you want less or more
$ export PAGER ;     --------->  This is only temporary for the session

Now type $PAGER and see if it shows the set value


18) I have given $ echo PAGER, but it doesn't show any value.  Why is it?

It means the man page on your system is using default pager i.e /etc/default/man.


19) What is MAN -K command ? 

Man doesn't use any options. The only exception is the -k option. When a user gives man -k, the man searches the summary and prints a one-line description of the command.

Example :

$ man -k awk

awk       awk (1)    -  pattern scanning and processing language




20)  What is APROPOS command?

Apropos command lists the files and commands associated with a command.

Example

$ apropos FTP

ftp                             ftp(1)             --------file transfer program
ftpd                           ftpd  ------------------- FTP daemon


The alternate to APROPOS command is "whatis" command.

example $whatis FTP

ftp                             ftp(1)             --------file transfer program



21) What is the command to erase text from your terminal?

[cntrl-h] or [cntrl-w]


22) What is the command to interrupt a command ?

[cntrl-c] or DELETE


23) What is the command to terminate a login session or a programme that expects a input?

[cntrl-d]


24) What is the command to stop scrolling the screen & lock the keyboard and how to resume it?

[cntrl-s]   ------------------------------->  Stop Scrolling

[cntrl-q] ---------------------------------> Resumes scrolling


25) What is the command to kill a command without executing it ?

[cntrl-u]


26) How do you kill a running command? What happens after you execute the command?

[cntrl-\].  You will get a core file created.


27) How do you suspend a process and return to shell prompt?

[cntrl-z] ------     Suspend a process

fg           ------>   to return to shell prompt



28) How to restore the computer terminal?

Enter the command "stty sane"




No comments:

Post a Comment