Wednesday, August 8, 2012

Basics of UNIX In Detail


What is UNIX?

UNIX is an operating system which was first developed in the 1960s, and has been under constant development ever since. By operating system, we mean the suite of programs which make the computer work. It is a stable, multi-user, multi-tasking system for servers, desktops and laptops.
UNIX systems also have a graphical user interface (GUI) similar to Microsoft Windows which provides an easy to use environment. However, knowledge of UNIX is required for operations which aren't covered by a graphical program, or for when there is no windows interface available, for example, in a telnet session.

Types of UNIX

There are many different versions of UNIX, although they share common similarities. The most popular varieties of UNIX are Sun Solaris, GNU/Linux, and MacOS X.
Here in the School, we use Solaris on our servers and workstations, and Fedora Core Linux on the servers and desktop PCs.

The UNIX operating system

The UNIX operating system is made up of three parts; the kernel, the shell and the programs.
The kernel
The kernel of UNIX is the hub of the operating system: it allocates time and memory to programs and handles the filestore and communications in response to system calls.
As an illustration of the way that the shell and the kernel work together, suppose a user types rm myfile (which has the effect of removing the file myfile). The shell searches the filestore for the file containing the program rm, and then requests the kernel, through system calls, to execute the program rm on myfile. When the process rm myfile has finished running, the shell then returns the UNIX prompt % to the user, indicating that it is waiting for further commands.

The shell

The shell acts as an interface between the user and the kernel. When a user logs in, the login program checks the username and password, and then starts another program called the shell. The shell is a command line interpreter (CLI). It interprets the commands the user types in and arranges for them to be carried out. The commands are themselves programs: when they terminate, the shell gives the user another prompt (% on our systems).
The adept user can customise his/her own shell, and users can use different shells on the same machine. Staff and students in the school have the tcsh shell by default.
The tcsh shell has certain features to help the user inputting commands.
Filename Completion - By typing part of the name of a command, filename or directory and pressing the [Tab] key, the tcsh shell will complete the rest of the name automatically. If the shell finds more than one name beginning with those letters you have typed, it will beep, prompting you to type a few more letters before pressing the tab key again.
History - The shell keeps a list of the commands you have typed in. If you need to repeat a command, use the cursor keys to scroll up and down the list or type history for a list of previous commands.

Files and Processes

Everything in UNIX is either a file or a process.
A process is an executing program identified by a unique PID (process identifier).
A file is a collection of data. They are created by users using text editors, running compilers etc.
Examples of files:
a document (report, essay etc.)
the text of a program written in some high-level programming language
instructions comprehensible directly to the machine and incomprehensible to a casual user, for example, a collection of binary digits (an executable or binary file);
a directory, containing information about its contents, which may be a mixture of other directories (subdirectories) and ordinary files.

The Directory Structure

All the files are grouped together in the directory structure. The file-system is arranged in a hierarchical structure, like an inverted tree. The top of the hierarchy is traditionally called root (written as a slash / )



In the diagram above, we see that the home directory of the undergraduate student "ee51vn" contains two sub-directories (docs and pics) and a file called report.doc.
The full path to the file report.doc is "/home/its/ug1/ee51vn/report.doc"

Starting an UNIX terminal

To open an UNIX terminal window, click on the "Terminal" icon from the drop-down menus.



An UNIX Terminal window will then appear with a % prompt, waiting for you to start entering commands.



Commands

  • % ls (list), ls –l, ls –aà lists files and directories.
  • % mkdir unixstuffà make directory.
  • % rmdir unixstuffà remove directory.
·         % cd unixstuffà change directory. cd ..
·         % pwdà present working directory.
·         % ls ~à home directory.
·         % cp file1 file2à copies file.
·         % mv file1 file2à moves (or) renames file.
·         % rm file1à removes a file.
·         % clearà clears the screen.
·         % cat(concatenate) unix.txtà display contents of a file on the screen.
·         % less unix.txtà writes contents of a file onto the screen.
·         % head unix.txtà writes first ten lines of a file to the screen.
·         % tail unix.txtà writes last ten lines of a file to the screen.
·         % grep unix unix.txtà searches for specified words or pattern.
·         % wc unix.txtà word count.
·         % >à redirect o/p to a file.
·         % >>à append a existing file.
·         % sort < biglist > slistà redirect i/p of a command.
·         % who | sortà who is on the system.
·         % wildcardà % & *.
·         % man (or) whatis wcà online help and manuals.
·         % -rwxrwxrwxà user, group & other for read, write & execute.
·         % chmodà change a file mode.
·         % psà process is an executing program identified by a unique PID(process identifier).
·         % sleep 10à waits a given number of seconds.
·         % ^z & bgà suspends current process and background.
·         % jobsà job number. Example is suspended sleep 1000
  • % fg %jobnumber (or) %1à restart a suspended processes.
  • % kill %jobnumberà kill (or) suspend background process.
  • % psà process status.
  • % quota –và check your current quota. user allocated a certain amount of disk space, usually 100mb.
  • % dfà space left on the file system
  • % du –s *à o/p’s number of kb used by each subdirectory.
  • % gzip unix.txtà compress the file. & gunzip unix.txt.gzà expand the file.
  • % tar –cvf sample.tar sampleà compress sample directory & tar –xvf sample.tar
  • % zcatà used to read gzip w/o uncompress.
  • % file *à classifies the named files according to the type of data.
  • % diff file1 file2à compares contents of two files.
  • % find . –name “*.txt” –printà searches thru’ the directories for files and directories with a given name.
  • % historyà shows the history of commands.
  • % strip unitsà strip unnecessary code.
  • % echo $OSTYPEà environment variable, OSTYPE, USER, HOME, HOST, PATH, ARCH,PRINTER.
  • % echo $historyà shell variable, history, cwd, home, path, prompt.
  • % set | lessà shell variables are both set and displayed using the set command.
  • % .cshrcà used to set conditions and perform actions to the shell.
  • % nedit ~/.cshrcà opens cshrc in a text editor.
  • % set path=($path ~/units/bin)
% makeà The make command allows programmers to manage large programs or groups of programs. It aids in developing large programs by keeping track of which portions of the entire program have been changed, compiling only those parts of the program which have changed since the last compile.
The make program gets its set of compile rules from a text file called Makefile which resides in the same directory as the source files. It contains information on how to compile the software, e.g. the optimisation level, whether to include debugging info in the executable. It also contains information on where to install the finished compiled binaries (executables), manual pages, data files, dependent library files, configuration files, etc.

ftpàThe FTP (File Transfer Protocol) utility program is commonly used for copying files to and from other computers. These computers may be at the same site or at different sites thousands of miles apart. FTP is a general protocol that works on UNIX systems as well as a variety of other (non-UNIX) systems.

?
to request help or information about the FTP commands
ascii
to set the mode of file transfer to ASCII
(this is the default and transmits seven bits per character)
binary
to set the mode of file transfer to binary
(the binary mode transmits all eight bits per byte and thus provides less chance of a transmission error and must be used to transmit files other than ASCII files)
bye
to exit the FTP environment (same as quit)
cd
to change directory on the remote machine
close
to terminate a connection with another computer
 
close brubeck
closes the current FTP connection with brubeck,
  but still leaves you within the FTP environment.
delete
to delete (remove) a file in the current remote directory (same as rm in UNIX)
get
to copy one file from the remote machine to the local machine
 
get ABC DEF
copies file ABC in the current remote directory to (or on top of) a file named DEF in your current local directory.
 
get ABC
copies file ABC in the current remote directory to (or on top of) a file with the same name, ABC, in your current local directory.
help
to request a list of all available FTP commands
lcd
to change directory on your local machine (same as UNIX cd)
ls
to list the names of the files in the current remote directory
mkdir
to make a new directory within the current remote directory
mget
to copy multiple files from the remote machine to the local machine;
  you are prompted for a y/n answer before transferring each file
 
mget *
copies all the files in the current remote directory to your current local directory, using the same filenames. Notice the use of the wild card character, *.
mput
to copy multiple files from the local machine to the remote machine;
  you are prompted for a y/n answer before transferring each file
open
to open a connection with another computer
 
open brubeck
opens a new FTP connection with brubeck;
  you must enter a username and password for a brubeck account
      (unless it is to be an anonymous connection).
put
to copy one file from the local machine to the remote machine
pwd
to find out the pathname of the current directory on the remote machine
quit
to exit the FTP environment (same as bye)
rmdir
to to remove (delete) a directory in the current remote directory.

telnetà telnet protocol to connect to another remote computer.

-8
Specifies an 8-bit data path. Negotiating the TELNET BINARY option is attempted for both input and output.
-E
Stops any character from being recognized as an escape character.
-L
Specifies an 8-bit data path on output. This causes the BINARY option to be negotiated on output.
-c
Disables the reading of the user's telnetrc file.
-d
Sets the initial value of the debug toggle to
TRUE.
-r
Specifies a user interface similar to rlogin . In this mode, the escape character is set to the
tilde (~) character, unless modified by the -e option. The rlogin escape character is only recognized when it is preceded by a carriage return. In this mode, the telnet escape
character, normally '^]', must still precede a telnet command. The rlogin escape character
can also be followed by '.\r' or '^Z', and, like rlogin, closes or suspends the connection, respectively. This option is an uncommitted inter- face and may change in the future.
-e escape_char
Sets the initial escape character to escape_char. escape_char may also be a two character sequence consisting of '^' followed by one character. If the second character is '?', the DEL character is selected. Otherwise, the second character is converted to a control character and used as the escape character. If the escape character is the null string (that is, -e ''), it is disabled.
-l user
When connecting to a remote system that understands the ENVIRON option, then user will be sent to the remote system as the value for the ENVIRON variable USER.
-n file
Opens tracefile for recording trace information


/etc/services

ftpà 21/tcp  # File Transfer Protocol
telnetà 23/tcp # Telnet
smtpà 25/tcp # Simple Mail Transfer Protocol
tftpà 69/udp   # Trivial File Transfer Protocol
wwwà 80/tcp # World Wide Web
ntpà 123/tcp  # N/W Time Protocol
ntpà 123/udp  # N/W Time Protocol

                                                         

0 comments:

Powered by Blogger.