Unix Primer:Unix File System,Some Useful Unix Commands and Unix Portability.

Unix File System

Unix allows a user to group related files within a directory. Suppose we want to work with two different applications, one involving documents and the other involving images.

May be we group the document related files under one directory and image related files in another directory. Sometimes it helps to further subdivide files. Unix allows creation of sub-directories to help organise files hierarchically. Such a file organisation creates a tree of directories with files as leaves.

When you log into a Unix system you always do so in your login directory. You may create files as well as subdirectories starting from the login directory.

An example of file hierarchy: When I created course notes for web browsing, I first created a directory COURSES under my home directory. Under this directory I created directories called OS, SE, COMPILERS respectively for operating systems, software engineering and compiler courses. You may browse the course pages at the URL http://www.iiitb.ac.in/bhatt. If you browse these files, you will notice that each course has files organized around topics grouped as Modules. In fact, there is an organizational hierarchy. The COURSES directory has subdirectories like OS, SE and COMPILERS within each of which there are modules. At the bottom most level within the modules subdirectory there are individual page files. The links, which help you navigate, lead you to image files or postscript files of the course pages.

It is important to know how one may reach a particular file in such a file hierarchy. The home directory is usually denoted in Unix by tilde (~). Suppose we wish to reach a particular module in OS course in my organisation of files as described above. This would require that we traverse down from the home to COURSES to OS to the particular module. This is called traversing a path. Our path would be /COURSES/OS/moduleX. Note how each step in the path hierarchy is separated by a forward slash.

We say that directory COURSES has a subdirectory (or a child directory) OS. We may also say that COURSES is the parent of directory OS. In Unix, all paths emanate from a directory called root. The root directory has no parent. A user's login directory is usually a child of a directory named home which is a child of “/”(i.e. root). Under home user's home directories are created with the user's login name. My home directory is named bhatt.

The directory where you may be currently located is denoted by a period (.) symbol. The parent of current directory is denoted by two periods (..). These two are special symbols. These symbols are used when the user has to make a reference relative to the present

position in the file system. An absolute path name would trace the file path starting with root as in /home/bhatt/COURSES/OS/module5. Suppose we are in directory COURSES then the same path shall be denoted as ./OS/module5. Note that the file path name has no spaces. In fact, no spaces are permitted within file path names.

Unix commands for files: The general command structure for Unix has the following structure:

< UnixCommand >< Options >< arguments >

A user may choose one or more options and one or more arguments.

It is important to be well versed with the commands that support the identification of files and navigation on the directory tree. Here is a brief list of relevant Unix commands34.

ls: Lists all the files within a directory.

cd: By itself it brings you back to home directory.

cd pathname: Takes you to the directory described by the pathname.

rm filename:: Removes file filename from the current directory.

pwd: Prints the name of the current working directory.

mkdir subdirname: Creates a subdirectory under the current directory with the name subdirname.

rmdir subdirname: Removes a subdirectory under the current directory with the name subdirname.

touch filename: Creates a file in the current directory with the name filename.

This file, on creation has 0 characters and 0 lines.

For now you should use the above listed commands to create files and directories. You should basically learn to navigate the directory tree. Later, we shall learn more commands applicable to files. You should also consult the online manual for options available on ls and rm commands.

In general, files have three basic operations associated with them. These are read, write,

and execute.

Unix supports four types of files.

  • Ordinary files: These are usually text files. Programs written in specific programming languages may have specific extensions. For instance, programs written in C have a .c extension. Files prepared for TeX documentation have a .tex extension. These are usually the files users create most often using an editor.
  • Directories: Subdirectories are treated as files by Unix.
  • Binary files: These are executables.
  • Special files: Special files provide input/output capability for Unix environment. Unix treats the device IO as file communication. In fact, these gives the look and feel of a file read or write whenever a user communicates with an IO device.

Some Useful Unix Commands

We give here a list of some commonly used Unix commands:

bc: Gives you a basic calculator. Try simple arithmetic to get a feel for its operation.

cal: Shows the calendar for the current month. A variation of cal will allow you to

• view calendar for any month or year.

clear: Clears the screen.

cp filename1 filename2: Creates a copy of file filename1 in filename2.

date: Shows the current time and date.

echo sometext: Echos back sometext on the terminal.

history: Shows the previously given command history. This may be customised.

more( filename: Shows the file filename one page at a time. less does the same

• except that it gives scrolling additionally.

cat filename: Displays the file filename on the screen.

cat filename(s) > newfile: Combines all the files in filename(s) and outputs to create a file newfile.

manAUnixCmd: Shows the description of the command AUnixCmd from the online help manual. It describes the use of a command with all its possible options and arguments.

exit: Exits the current shell.

Unix Portability

In Section 10.1 we described why Unix may be regarded as an open system. One of the main outcomes of such an open system, as Unix has been, is that there are many versions of Unix with mutual incompatibility. This led to problems in communication and

interoperability. Fortunately, there are some standards now. Two of the better known standards are X/open and POSIX. In developing the POSIX, professional organizations like IEEE (URL: http://standards.ieee.org) have been involved. Now-a-days most developers ensure that their products are POSIX compliant. POSIX compliant software adheres to some interface protocols. This ensures interoperability. A very good URL which describes both X/Open and POSIX is http://www.starlink.rl.ac.uk/star/docs/sun121.htx/node9.html.

Finally: We discussed some Unix commands in this module. This description is far from complete. For instance, Unix allows the use of regular expressions in arguments. We have not discussed that in this module. This is because in the next module we shall be discussing tools for pattern matching which requires extensive use of regular expressions. However, some exercises in this chapter may contain regular expressions. It is expected that the users of Unix are motivated to learn a few such details on the fly.

Comments

Popular posts from this blog

Data Structure Visualization:Introduction and Value of Data Structure Rendering

Binary Space Partitioning Trees:BSP Tree as a Hierarchy of Regions.

Drawing Trees:HV-Layout