Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Unix seminar

  • Login to see the comments

  • Be the first to like this

Unix seminar

  1. 1. Unix The Operating SystemUNIX (THE OS) Page 1Introduction to UNIXUNIX is an operating system which was first developed in the 1960s, at AT&TBell Laboratories and at the University of California, and has been underconstant development ever since. By operating system, we mean the suite ofprograms which make the computer work. It is a stable, multi-user, multi-taskingsystem for servers, desktops and laptops.UNIX systems also have a graphical user interface (GUI) similar to MicrosoftWindows which provides an easy to use environment. However, knowledge ofUNIX is required for operations which arent covered by a graphical program, orfor when there is no windows interface available, for example, in a telnetsession.Unix is also part of the underlying technology of the Internet. Although nooperating systems has any exclusive claim to the Internet, many of the standardtechnologies, protocols and applications that make up the Internet were firstdeveloped on Unix systems.Multi-user:- Multi-user is a term that defines an operatingsystem or application software that allows access by multiple users ofa computer. Time-sharing systems are multi-user systems. Most batchprocessing systems for mainframe computers may also be considered "multi-user", to avoid leaving the CPU idle while it waits for I/O operations to complete.Multi tasking:- multitasking is a method where multiple tasks, alsoknown as processes, are performed during the same period of time. The tasksshare common processing resources, such as a CPU and main memory. In thecase of a computer with a single CPU, only one task is said to be running at anypoint in time, meaning that the CPU is actively executing instructions for thattask. Multitasking solves the problem by scheduling which task may be the onerunning at any given time, and when another waiting task gets a turn.
  2. 2. Unix The Operating SystemUNIX (THE OS) Page 2Graphical User Interface:- graphical user interface (GUI) is atype of user interface that allows users to interact with electronic devices usingimages rather than text commands. GUIs can be used in computers, hand-helddevices such as MP3 players, portable media players or gaming devices,household appliances, office and industry equipment.UNIX importanceUNIX, as it is implemented in its many variants, serves as the operatingsystem for all types of computers, including personal computers andengineering workstations, multiuser microcomputers, minicomputers,mainframes, and supercomputers, as well as special-purpose devices. Thenumber of computers running a variant of UNIX has grown explosively withmore than 40 million computers now running a variant of UNIX and more than300 million people using these systems. This rapid growth, especially forcomputers running Linux, is expected to continue, according to most computerindustry experts. The success of UNIX is due to many factors, including itsportability to a wide range of machines, its adaptability and simplicity, the widerange of tasks that it can perform, its multiuser and multitasking nature, and itssuitability for networking, which has become increasingly important as theInternet has blossomed. What follows is a description of the features that havemade UNIX so popular.Open Source Code:- The source code for key variants of UNIX, andnot just the executable code, has been made available to users andprogrammers. Because of this, many people have been able to adapt UNIX indifferent ways. This openness has led to the introduction of a wide range of newfeatures and versions customized to meet special needs. It has been easy fordevelopers to adapt to UNIX, because the computer code for UNIX isstraightforward, modular, and compact.
  3. 3. Unix The Operating SystemUNIX (THE OS) Page 3Cooperative Tools and Utilities:- The UNIX System provides userswith many different tools and utilities that can be leveraged to perform an amazingvariety of jobs. Some of these tools are simple commands that you can use to carryout specific tasks. Other tools and utilities are really small programming languagesthat you can use to build scripts to solve your own problems.Multiuser and Multitasking Abilities:- The UNIX operating systemcan be used for computers with many users or a single user, because it is amultiuser system. It is also a multitasking operating system, because a single usercan carry out more than one task at once. For instance, you can run a program thatchecks the spelling of words in a text file while you simultaneously read yourelectronic mail.Excellent Networking Environment:- The UNIX operating systemprovides an excellent environment for networking. It offers programs and utilities thatprovide the services needed to build networked applications-the basis for distributed,networked computing. With networked computing, information and processing isshared among different computers in a network. The UNIX system has proved to beuseful in client/server computing where machines on a network can be both clientsand servers at the same time. UNIX also has been the base system for thedevelopment of Internet services and for the growth of the Internet.Portability:- It is far easier to port UNIX to new machines than otheroperating systems-that is, far less work is needed to adapt it to run on a newhardware platform. The portability of UNIX results from its being written almostentirely in the C programming language. The portability to a wide range of computersmakes it possible to move applications from one system to another.
  4. 4. Unix The Operating SystemUNIX (THE OS) Page 4The Structure of UNIX Operating SystemTo understand how UNIX works, you need to understand its structure. The UNIXoperating system is made up of several major components. These componentsinclude the kernel, the shell, the file system, and the commands (or user programs).The relationship among the user, the shell, the kernel, and the underlying hardwareis displayed in Figure.The Kernel:- The kernel is the part of the operating system that interactsdirectly with the hardware of a computer, through device drivers that are built into thekernel. It provides sets of services that can be used by programs, insulating theseprograms from the underlying hardware. The major functions of the kernel are to
  5. 5. Unix The Operating SystemUNIX (THE OS) Page 5manage computer memory, to control access to the computer, to maintain the filesystem, to handle interrupts (signals to terminate execution), to handle errors, toperform input and output services (which allow computers to interact with terminals,storage devices, and printers), and to allocate the resources of the computer (suchas the CPU or input/output devices) among users.Utilities:- The UNIX System contains several hundred utilities or userprograms. Commands are also known as tools, because they can be usedseparately or put together in various ways to carry out useful tasks. You executethese utilities by invoking them by name through the shell; this is why they are calledcommands.A critical difference between UNIX and earlier operating systems is the ease withwhich new programs can be installed-the shell need only be told where to look forcommands, and this is user-definable.The File System:- The basic unit used to organize information in UNIX iscalled a file. The UNIX file system provides a logical method for organizing, storing,retrieving, manipulating, and managing information. Files are organized into ahierarchical file system, with files grouped together into directories. An importantsimplifying feature of UNIX is the general way it treats files. For example, physicaldevices are treated as files; this permits the same commands to work for ordinaryfiles and for physical devices; for instance, printing a file (on a printer) is treatedsimilarly to displaying it on the terminal screen.The Shell:- The shell reads your commands and interprets them asrequests to execute a program or programs, which it then arranges to have carriedout. Because the shell plays this role, it is called a command interpreter. Besidesbeing a command interpreter, the shell is also a programming language. As aprogramming language, it permits you to control how and when commands arecarried out.
  6. 6. Unix The Operating SystemUNIX (THE OS) Page 6Applications Of UNIXThere are many applications of UNIX discussed as below: You can use applications built using UNIX commands, tools, and programs. horizontal applications like as government, industry, and education. Others are industry-specific and are known as vertical applications web browsers and web server application Another important class of applications deals with multimedia. Suchapplications let users create and view multimedia files, including audio,images, and video.UNIX PhilosphyUNIX has developed a characteristic, consistent approach that is sometimes referredto as the UNIX philosophy. This philosophy has deeply influenced the structure ofthe system and the way it works. Keeping this philosophy in mind helps youunderstand the way UNIX treats files and programs, the kinds of commands andprograms it provides, and the way you use it to accomplish a task.The UNIX philosophy is based on the idea that a powerful and complex computersystem should still be simple, general, and extensible, and that making it so providesimportant benefits for both users and program developers. Another way to expressthe basic goals of the UNIX philosophy is to note that, for all its size and complexity,UNIX still reflects the idea that “small is beautiful.” This approach is especiallyreflected in the way UNIX treats files and in its focus on software tools.
  7. 7. Unix The Operating SystemUNIX (THE OS) Page 7The Birth Of The Unix SystemThe history of the UNIX System dates back to the late 1960s when MIT, AT&T BellLabs, and then-computer manufacturer GE (General Electric) worked on anexperimental operating system called Multics. Multics, from Multiplexed Informationand Computing System, was designed to be an interactive operating system for theGE 645 mainframe computer, allowing information sharing while providing securityDevelopment met with many delays, and production versions turned out to be slowand required extensive memory For a variety of reasons, Bell Labs dropped out ofthe project. However, the Multics system implemented many innovative features andproduced an excellent computing environment.1969 The Beginning The history of UNIX starts back in 1969, when KenThompson, Dennis Ritchie and others started working onthe "little-used PDP-7 in a corner" at Bell Labs and whatwas to become UNIX.1971 First Edition It had a assembler for a PDP-11/20, file system, fork(), roffand ed. It was used for text processing of patentdocuments.1973 Fourth Edition It was rewritten in C. This made it portable and changedthe history of OSs.1975 Sixth Edition UNIX leaves home. Also widely known as Version 6, this isthe first to be widely available out side of Bell Labs. Thefirst BSD version (1.x) was derived from V6.1979 Seventh Edition It was a "improvement over all preceding and followingUnices" [Bourne]. It had C, UUCP and the Bourne shell. Itwas ported to the VAX and the kernel was more than 40
  8. 8. Unix The Operating SystemUNIX (THE OS) Page 8Kilobytes (K).1980 Xenix Microsoft introduces Xenix. 32V and 4BSD introduced.1982 System III AT&Ts UNIX System Group (USG) release System III, thefirst public release outside Bell Laboratories. SunOS 1.0ships. HP-UX introduced. Ultrix-11 Introduced.1983 System V Computer Research Group (CRG), UNIX System Group(USG) and a third group merge to become UNIX SystemDevelopment Lab. AT&T announces UNIX System V, thefirst supported release. Installed base 45,000.1984 4.2BSD University of California at Berkeley releases 4.2BSD,includes TCP/IP, new signals and much more. X/Openformed.1984 SVR2 System V Release 2 introduced. At this time there are100,000 UNIX installations around the world.1986 4.3BSD 4.3BSD released, including internet name server. SVIDintroduced. NFS shipped. AIX announced. Installed base250,000.1987 SVR3 System V Release 3 including STREAMS, TLI, RFS. Atthis time there are 750,000 UNIX installations around theworld. IRIX introduced.1988 POSIX.1 published. Open Software Foundation (OSF) andUNIX International (UI) formed. Ultrix 4.2 ships.1989 AT&T UNIX Software Operation formed in preparation forspinoff of USL. Motif 1.0 ships.1989 SVR4 UNIX System V Release 4 ships, unifying System V, BSDand Xenix. Installed base 1.2 million.1990 XPG3 X/Open launches XPG3 Brand. OSF/1 debuts. Plan 9 fromBell Labs ships.1991 UNIX System Laboratories (USL) becomes a company -majority-owned by AT&T. Linus Torvalds commences
  9. 9. Unix The Operating SystemUNIX (THE OS) Page 9Linux development. Solaris 1.0 debuts.1992 SVR4.2 USL releases UNIX System V Release 4.2 (Destiny).October - XPG4 Brand launched by X/Open. December22nd Novell announces intent to acquire USL. Solaris 2.0ships.1993 4.4BSD 4.4BSD the final release from Berkeley. June 16 Novellacquires USLLate1993SVR4.2MP Novell transfers rights to the "UNIX" trademark and theSingle UNIX Specification to X/Open. COSE initiativedelivers "Spec 1170" to X/Open for fasttrack. In DecemberNovell ships SVR4.2MP , the final USL OEM release ofSystem V1994 Single UNIXSpecificationBSD 4.4-Lite eliminated all code claimed to infringe onUSL/Novell. As the new owner of the UNIX trademark,X/Open introduces the Single UNIX Specification (formerlySpec 1170), separating the UNIX trademark from anyactual code stream.1995 UNIX 95 X/Open introduces the UNIX 95 branding programme forimplementations of the Single UNIX Specification. Novellsells UnixWare business line to SCO. Digital UNIXintroduced. UnixWare 2.0 ships. OpenServer 5.0 debuts.1996 The Open Group forms as a merger of OSF and X/Open.1997 Single UNIXSpecification,Version 2The Open Group introduces Version 2 of the Single UNIXSpecification, including support for realtime, threads and64-bit and larger processors. The specification is madefreely available on the web. IRIX 6.4, AIX 4.3 and HP-UX11 ship.1998 UNIX 98 The Open Group introduces the UNIX 98 family of brands,including Base, Workstation and Server. First UNIX 98registered products shipped by Sun, IBM and NCR. TheOpen Source movement starts to take off with
  10. 10. Unix The Operating SystemUNIX (THE OS) Page 10announcements from Netscape and IBM. UnixWare 7 andIRIX 6.5 ship.1999 UNIX at 30 The UNIX system reaches its 30th anniversary. Linux 2.2kernel released. The Open Group and the IEEEcommence joint development of a revision to POSIX andthe Single UNIX Specification. First LinuxWorldconferences. Dot com fever on the stock markets. Tru64UNIX ships.2001 Single UNIXSpecification,Version 3Version 3 of the Single UNIX Specification unites IEEEPOSIX, The Open Group and the industry efforts. Linux2.4 kernel released. IT stocks face a hard time at themarkets. The value of procurements for the UNIX brandexceeds $25 billion. AIX 5L ships.2003 ISO/IEC9945:2003The core volumes of Version 3 of the Single UNIXSpecification are approved as an international standard.The "Westwood" test suite ship for the UNIX 03 brand.Solaris 9.0 E ships. Linux 2.6 kernel released.2007 Apple Mac OS X certified to UNIX 03.2008 ISO/IEC9945:2008Latest revision of the UNIX API set formally standardizedat ISO/IEC, IEEE and The Open Group. Adds further APIs2009 UNIX at 40 IDC on UNIX market -- says UNIX $69 billion in 2008,predicts UNIX $74 billion in 20132010 UNIX on theDesktopApple reports 50 million desktops and growing -- these areCertified UNIX systems.
  11. 11. Unix The Operating SystemUNIX (THE OS) Page 11Starting Out Of UNIXYou can access a UNIX system in one of two general ways: either locally (that is,while sitting at the computer you are connected to), or remotely (by connecting to thecomputer over a network). Most of what you will learn in this book applies equallywell to either case. In particular, the basic UNIX commands will work in exactly thesame way Before you can start using those commands, however, you will need toknow how to access your UNIX system.Connecting Locally:- To connect to a UNIX machine locally, you need tobe physically at the computer. If that computer is a UNIX workstation, all you need todo is log in with your username and password. If you are using Mac OS X, you justneed to run the Terminal application, available under Applications | Utilities, in orderto access the UNIX command line that is built in to the operating system.Connecting Remotely:- When you connect to a UNIX system remotely,you are using your computer to access another system that is running UNIX.Typically, this system supports many users at once. For example, many largeuniversities offer a UNIX account to all their students. The students log in to thesystem from their own computers, either through the Internet or over the universitynetwork.In order to connect to a UNIX system like this, you will need Internet access fromyour own computer. (In some cases, you may be able to dial in directly to the UNIXsystem, but the details for how to do this depend on the specific systemconfiguration.) You will also need a terminal emulator application.
  12. 12. Unix The Operating SystemUNIX (THE OS) Page 12Logging inOnce you have access to your UNIX system, you will need to log in with yourusername and password. The UNIX operating system was designed for multipleusers. Requiring each user to log in ensures that the system remains secure, andthat each user‟s files remain private.Selecting a Login Name:- Every UNIX system has at least one person,called the system administrator, whose job is to maintain the system.In general, your login name can be almost any combination of letters and numbers,although there are a few constraints: Your login name must be more than two characters long. If it is longer thaneight, only the first eight characters are relevant. It must contain only lowercase letters and numbers and must begin with alowercase letter. No symbols or spaces are allowed. It cannot be the same as another login name already in use. Some loginnames are customarily reserved for certain uses; for example, root is often alogin name for the system administrator (sometimes called the superuser).it is important to choose something that won‟t become embarrassing or confusinglater. In some cases the system administrator may select a login name for you.
  13. 13. Unix The Operating SystemUNIX (THE OS) Page 13Choosing a Password:- If you begin by installing a UNIX variant on yourown system, it will ask you to choose a password when you select a login name. Ifyour account is on a remote system, your system administrator will probably assignyou a temporary password, which you should change the first time you log in. UNIXplaces some requirements on passwords, typically including the following: Passwords must have at least six characters. Passwords must contain at least two alphabetic characters (uppercase orlowercase letters), and at least one number or symbol. Note that UNIX issensitive to case, so WIZARD is a different password than w1zard.. Your login name with its letters reversed or shifted cannot be used as apassword. For example, if your login name is msilver, you cannot choosesilverm or revlism as a password.Entering CommandsThe UNIX System makes hundreds of programs available to the user. To run one ofthese programs you issue a command. When you type date, for example, you arereally instructing the UNIX System command interpreter to execute a program withthe name date, and to display the results on your screen.The most commonly used commands, however, are typically constant acrossversions.Command Options and Arguments:- The UNIX System has astandardized command syntax that applies to almost all commands. Understandingthese patterns makes it easier to learn new UNIX commands. Some commands areused alone, some require arguments that describe what the command is to operateon, and some provide options that let you specify certain choices. Here is anexample of each type of command.
  14. 14. Unix The Operating SystemUNIX (THE OS) Page 14The date command is usually used alone:$ dateFri Apr 27 22:14:05 EDT 2007As you can see, entering the command date prints the current day and time.Many commands take arguments (typically filenames) that specify what thecommand operates on. For example, to view a file, you can type$ cat notesThis tells the cat command to display the file notes.Commands often allow you to specify options that influence the operation of thecommand. You specify options for UNIX System commands by using a minus signfollowed by a letter or word. For example, the command ls by itself lists all the files ina directory If you enter$ ls -lthe -l option says to print a long version of the list with details about each file.Stopping a Command:- You can stop a command by hitting CTRL-C. TheUNIX System will halt the command and return to the system prompt. You can dothis either while typing or after running a command. For example, you could useCTRL-C if you were in the middle of entering a command and realized that it wasmisspelled. Or you could use it to cancel ls if it were taking too long to list thecontents of a very large directoryCTRL-C is an example of a control character.
  15. 15. Unix The Operating SystemUNIX (THE OS) Page 15The passwd Command:- On some UNIX systems, you are forced tochange your password after a certain length of time (determined by the systemadministrator) for security reasons. Even if your system doesn‟t enforce this, youshould remember to change it periodically You can do this with the passwdcommand. When you issue the command, it asks for your current password, and anew password, and then requires you to retype the new password to confirm it.$ passwdpasswd: changing password for corwinOld password:New password:Re-enter new password:$The cal command:- The cal command prints a calendar for any month oryear. If you do not give it an argument, it prints the current month. For example, onMarch 27, 2007, you would get the following:$ calMarch 2007Su Mo Tu We Th Fr Sa1 2 34 5 6 7 8 9 1011 12 13 14 15 16 1718 19 20 21 22 23 2425 26 27 28 29 30 31If you give cal a single number, it is treated as a year, and cal prints the calendar forthat year. So, for example, cal 2007 will display a calendar for all of 2007. If youwant to print a specific month other than the current month, enter the month numberfirst, then the year. To get the calendar for April 2008, use the following command:$ cal 4 2008
  16. 16. Unix The Operating SystemUNIX (THE OS) Page 16The who Command:- On a multiuser system among friends or coworkers,you may wonder who else is currently logged in. The UNIX System provides astandard command for getting this information:$ whodbp pts/10 Apr 2 09 52etch pts/15 Apr 2 16 13a-liu pts/16 Mar 29 23 21corwin pts/18 Apr 2 06 33raf pts/27 Apr 1 22 04smullyan pts/31 Apr 2 16 48For each user who is currently logged into this system, the who command providesone line of output.The finger Command:- The finger command provides you with morecomplete information about other users on the system. The command:$ finger corwinwill print out information about the user corwin. For example,Login name: corwin Name: Eric KrugerDirectory:/home/corwin Shell:/usr/bin/bashLast login Sun Aug 28 20:13:05 on pts/17Project: Currently, Im writing up my summer research project.The write Command:- The write command copies the text you type to thescreen of another user who is logged in. If your login name is raf, the command:$ write corwinHey, are you busy?CTRL-Dwill display the following message on corwin‟s screenMessage from rafHey, are you busy?EOF
  17. 17. Unix The Operating SystemUNIX (THE OS) Page 17The talk Command:- A problem with write is that your messages can overlapeach other, which is awkward to read. The talk command is an enhancedcommunication program. If your login name is raf, and you type.$ talk corwinthe talk command notifies corwin that you wish to speak with him and asks him toapprove. Corwin sees the following on his screen:Message from Talk_Daemon@amber at 20:15 ...talk: connection requested by raf@ambertalk: respond with: talk raf@amberThe mesg Command :- Both the write and talk commands allow someoneto type a message that will be displayed on your screen. You may find itdisconcerting to have messages appear unexpectedly while you are working. Inorder to control this, the UNIX System provides the mesg command, which allowsyou to accept or refuse messages sent via write and talk. Type$ mesg nto prohibit programs run by other people from writing to your screen. Anyone whotries to write you get the error messagePermission deniedTyping mesg n after someone has sent you a message will stop the conversation.The sender will see the message “Can no longer write to user.”The command$ mesg yGetting Command Details:- It can be hard to remember all thecommands and how to use them. The UNIX operating system comes with a built-inmanual so that you can look up the details for how to use each command. To view
  18. 18. Unix The Operating SystemUNIX (THE OS) Page 18the manual page for a command, just type man followed by the command name. Forexample,$ man lswill display the man page for ls. In addition, many commands have some amount ofbuilt-in help. For example, ls --help will display a shorter version of the man page.Logging OutWhen you finish your work session and wish to leave the UNIX system, type exit (orCTRL-D) to log out. After a few seconds, your UNIX system will display the “login:”prompt:$ exitlogin:This shows that you have logged out, and that the system is ready for another userto log in using your terminal.Always log out when you finish your work session or when leaving your computer.An unattended session allows a passing stranger to access your work and possiblythe work of others.If you have a single-user system, it is important to remember that logging out is notthe same as turning off your computer. To avoid problems, run the shutdowncommand (or on some systems, poweroff) before logging out in order to make itsafe to turn off the machine. If you just turn the computer off without runningshutdown, you run a real risk of damaging files or loosing data.
  19. 19. Unix The Operating SystemUNIX (THE OS) Page 19Command Summary :-Command Usepasswd Change your passworddate Get the current date and timecal Display a calendarwho List all users who are currently logged infinger username Get information about usernamewrite username Send a chat message to usernametalk username Open a chat session with usernamemesg ymesg nAccept or block incoming messagesman command Get information about commandmailxmailx addressRead e-mail messages, or send an e-mail to addressexit Log out of the systemshutdown poweroff Turn off the machineWorking with Files and DirectoriesThe UNIX file system provides a powerful and flexible way to organize and manageyour information. the commands that provide the basic file manipulation operations-viewing files, changing directories, deleting and moving files-are among the UNIXcommands you will use most often.Files:- A file is the basic structure that stores information on the UNIX System(and on Windows systems, as well). Conceptually, a computer file is similar to apaper document. Technically a file is a sequence of bytes that is stored somewhereon a storage device, such as a hard drive. A file can contain any kind of informationthat can be represented as a sequence of bytes. Word processing documents,bitmap images, and computer programs are all examples of files.
  20. 20. Unix The Operating SystemUNIX (THE OS) Page 20Filenames:- Every file has a title, called a filename. A filename can be almostany sequence of characters, and up to 255 characters long. (On some older versionsof UNIX, two filenames are considered the same if the first 14 characters areidentical, so be careful if you use long filenames on these systems.) You can useany ASCII character in a filename except for the null character (ASCII NUL) or theslash (/), which has a special meaning in the UNIX file system. The slash acts as aseparator between directories and files.Many of these characters have special meanings in the command shell, whichmakes them difficult to work with in filenames! (exclamationpoint)* (asterisk) {,} (brackets)# (pound sign) ? (question mark) ; (semicolon)& (ampersand) (backslash) ^ (caret)| (pipe) (,) (parentheses) Tab@ (at sign) „,” (single or doublequotes)Space$ (dollar sign) < , > (left or right arrow) BackspaceCapitalizationWindows does not distinguish between uppercase and lowercase letters infilenames. You could save a file with the name Notes.DOC and find it by searchingfor notes.doc. The UNIX file system, however, is case-sensitive, meaning thatuppercase and lowercase letters are distinct. In UNIX, NOTES, Notes, and noteswould be three different files. If you save a file with the name Music, you will not findit by searching for music. This also applies to commands in UNIX. If you are trying tolog out with the exit command, typing EXIT will not work. By the way, this explains
  21. 21. Unix The Operating SystemUNIX (THE OS) Page 21why URLs (web addresses) can be case-sensitive, since the first web server wascreated on a UNIX-based platform, and many web servers still run UNIX.Filename Extensions:- In Windows, filenames typically consist of abasename, followed by a period and a short filename extension. Many Windowsprograms depend on the extension to determine how to use the file. For example, afile named solitaire.exe is considered to be a file named solitaire with the extension.exe, where the .exe extension tells Windows that it is an executable program. If thefile extension is altered or deleted, it will be more difficult to work with the file inWindows.Some programs either produce or expect a file with a particular filename extension.For example, files that contain C source code have the extension .c, so sorting.cwould be a C language file. Similarly, web browsers expect that HTML files will havethe extension .html, such as index.html.Common File Extensions :-Table:- Common File ExtensionsC File Type Extension File Type.au Audio .mpg,.mpegMPEG video.c C language sourcecode.o Object file (compiled and assembledcode).cc C++ source code .pl Perl script.class Compiled Java file .ps PostScript file.conf Configuration file .py Python script.d Directory .sh Bourne shell script.gif GIF image .tar tar archive.gz Compressed withgzip.tar.Z,.tar.gzFiles that have been archived with tarand then compressed.h Header file for a Cprogram.tex Text formatted with Tex/LaTeX.html Webpage .txt ASCII text.jar Java archive .uu, .uue Uuencoded file.java Java source code .wav Wave audio.jpg,.jpegJPEG image .z Compressed with pack
  22. 22. Unix The Operating SystemUNIX (THE OS) Page 22Table:- Common File ExtensionsC File Type Extension File Type.log Log file .Z Compressed with compressUNIX files can have more than one extension. For example, the file book.tar.Z is afile that has first been archived using the tar command (which adds the extension.tar) and then compressed using the compress command (which adds the .Z). Thisenables a single script to both decompress the file and untar it, using the filename asinput and parsing each of the extensions to perform the appropriate task.. DirectoriesFiles contain the information you work with. Directories provide a way to organizeyour files. A directory is just a container for as many files as you care to put in it. Ifyou think of a file as analogous to a document in your office, then a directory is like afile folder. In fact, directories in UNIX are exactly like folders in Windows.For example, you may decide to create a directory to hold all of your notes. Youcould name it Notes and use it to hold only files that are your notes, keeping themseparated from your e-mail, programs, and other files.Subdirectories:- A directory can also contain other directories. A directoryinside another directory is called a subdirectory. You can create as manysubdirectories inside a particular directory as you wish.Choosing Directory Names:- It is a good idea to adopt a convention fornaming directories so that they can be easily distinguished from ordinary files. Somepeople give directories names that are all uppercase letters, some use directorynames that begin with an uppercase letter, and others distinguish directories usingthe extension .d or .dir. For example, if you decide to use names beginning with an
  23. 23. Unix The Operating SystemUNIX (THE OS) Page 23uppercase letter for directories and avoid naming ordinary files this way, you willknow that Notes, Misc, Multimedia, and Programs are all directories.The Hierarchical File Structure:- Because directories can containother directories, which can in turn contain other directories, the UNIX file system iscalled a hierarchical file system. Within the UNIX System, there is no limit to thenumber of files and directories you can create in a directory that you own.Pathnames:- the UNIX System allows you to specify filenames by includingthe location of the file in the directory tree. This type of name is called a pathname,because it is a listing of the directories you travel through along the path you take toget to the file. The path through the file system starts at root (/), and the names ofdirectories and files in a pathname are separated by slashes.For example, the pathname for one of the save files is/home/raf/Email/saveand the pathname for the other is/home/raf/Work/saveRelative Pathnames:-You do not always have to specify the full pathnameswhen you refer to files. As a convenient shorthand, you can also specify a path to afile relative to your present directory Such a pathname is called a relative pathname.Instead of starting with a / for root, the relative pathname starts with the name of a
  24. 24. Unix The Operating SystemUNIX (THE OS) Page 24subdirectory For example, suppose you are in your home directory, /home/raf. Therelative path for the save file in the Email subdirectory is Email/save, and the relativepath for the other save file is Work/save.Specifying the Current Directory:- A single dot (.) is used as ashortcut to refer to the directory you are currently in. This directory is known as thecurrent directory.Specifying the Parent Directory:- Two dots (.., pronounced “dot-dot”)refer to the parent directory of the one you are currently in. The parent directory isthe one at the next higher level in the directory tree. Because the file system ishierarchical, all directories have a parent directory The dot-dot references can beused many times to refer to things far up in the file system. The following sequence,for example,../..refers to the parent of the parent of the current directory. If you are in Work, then ../..is the same thing as the home directory, since home is the parent of raf, which is theparent of Work.Specifying a Home Directory:- A tilde (~) can be used to refer to yourhome directory (Strictly speaking, this is a feature of the shell, which will bediscussed in the next chapter. It will work on most modern UNIX systems.)These shortcuts can be combined. For example, if your home directory is /home/raf,then~/../lizrefers to the home directory for the user liz.
  25. 25. Unix The Operating SystemUNIX (THE OS) Page 25Configuring the ShellWhen your login shell starts up, it looks for certain files in your home directory.These files contain commands that can be used to configure your workingenvironment. The particular files it looks for depend on which shell you are using:sh runs the commands in a configuration file called .profile.ksh also uses the .profile file. In addition, you can set a variable in your.profile to cause it to read the commands in a second file. The variable iscalled ENV. By convention, that file is often called .kshrc.bash uses the file .bash_profile. If that file does not exist, it will look for the file.profile, instead. The .bash_profile often contains a line that causes bash torun the commands in a second file, bashrc. When you log out of bash, it willrun the commands in .bash_logout.csh looks for a file called .login. It will also run commands in .cshrc. When youlog out of the C shell, it will run the commands in the file .logout.tcsh uses the .login file as well. It also looks for .tshrc. If that file does notexist, it will look for .cshrc instead. Like the C shell, tcsh will run the .logoutfile when you log out.This may all sound very confusing, but these configuration files all work in prettymuch the same way Each of these files is actually an example of a shell script. Theycontain commands or instructions for the shell. The commands include settings thatallow you to customize your environment.The first file that the shell reads (.profile, .bash_profile, or .login) contains variablesor settings that you want to be in effect throughout your login session. The section“Shell Variables” later in this chapter describes these variables. The file might alsoinclude commands you want to run at login, such as cal (to display a calendar for thecurrent month) or who (to show the list of users who are currently logged in).
  26. 26. Unix The Operating SystemUNIX (THE OS) Page 26Interactive Shells:- You can start another shell after you log in by using thename of the shell as a command; for example, to start the Korn shell, you could typeksh at the command prompt. This type of shell is not a login shell, and you do nothave to log in again to use it, but it is still an interactive shell, meaning that youinteract with the shell by typing in commands The instances of the shell that run in aterminal window when you are using a graphical interface are also interactive non-login shells. When you start a non-login shell, it does not read your .profile,.bash_profile, or .login file (or your .logout file), but it will still read the second shellconfiguration file (such as .bashrc).Sample Configuration Files:- If you define a variable by typing its newvalue on the command line, it will return to its previous value the next time you log in.In order to keep important variables such as PATH, PS1, and TERM defined everytime you log in, they are usually included in one of your configuration files. Here area few examples of those files. Don‟t worry if the commands don‟t make sense yet-you can come back to this later, after reading the sections “Shell Variables” and“Command Aliases.”Sample.bash profile:- Every time you log in, bash reads your .bash_profile.This file includes definitions of environment variables that will be shared with otherprograms and commands such as who that you want to run at the beginning of eachlogin session. A typical .bash_profile might look some-thing like this:# .bash_profile - example# set environment variablesexport TERM=vt100export PATH=$PATH:/sbin:/usr/sbin:$HOME/binexport MAILCHECK=30# allow incoming messages from other usersmesg y
  27. 27. Unix The Operating SystemUNIX (THE OS) Page 27# make sure backspace worksstty erase "^H"# show all users who are currently logged inwho# load aliases and local variables. -/.bashrcThe last line executes your .bashrc file. If you leave it out, bash will not read youraliases and variable definitions when you log in.Sample .bashrc File:- when you start an interactive bash shell afterlogging in (e.g., by opening an xterm window), it reads the commands in your.bashrc file. This file includes commands and definitions that you want to haveexecuted every time you run a shell-not just at login. The .bashrc file defines localshell variables (but not environment variables, which belong in .bash_profile), shelloptions, and command aliases. It might look something like this:# .bashrc file-example# set shell variables (such as the prompt)PS1="u w> "# set shell optionsset −o noclobberset −o emacsset +o notify# set default file permissionsumask 027# define aliases
  28. 28. Unix The Operating SystemUNIX (THE OS) Page 28alias lg=ls -g -color=ttyalias r=fc -salias rm=rm -ialias cp=cp -ralias wg=who | grepalias hibernate=sudo apm -sA configuration file for ksh could look like this, as well. However, the line PS1=“uw>” in this example would have to be changed to PS1=„$LOGNAME $(pwd)> ‟,because ksh doesn‟t support the bash shortcuts for defining the prompt.Sample .login File:-As the name suggests, tcsh reads the .login file onlywhen you log in. Your .login file should contain commands and variable definitionsthat only need to be executed at the beginning of your session. Examples of thingsyou would put in .login are commands for initializing your terminal settings,commands such as date that you want to run at the beginning of each login session,and definitions of environment variables.The following is a short example of what you might put in a typical .login file:# .login file-example# show number of users on systemecho "There are" who wc -l "users on the system"# set terminal options-- in particular,# make sure that the Backspace key worksstty erase "^H"# set environment variablessetenv term vt100setenv mail ( 60 /var/spool/mail/$user)
  29. 29. Unix The Operating SystemUNIX (THE OS) Page 29These examples illustrate the use of setenv, the C shell command for definingenvironment variables. setenv and its use are discussed further later on, in thesection “csh and tcsh Variables.”Sample .tcshrc File:- The difference between .tcshrc and .login is that tcshreads .login only at login, but it reads .tcshrc both when it is being started up as alogin shell and when it is invoked as an interactive non-shell. The .tcshrc file includescommands and definitions that you want to have executed every time you run ashell-not just at login.Your .tcshrc should include your alias definitions, and definitions of variables that areused by the shell but are not environment variables. Environment variables shouldbe defined in .login.# .tcshrc file-example# set shell variablesset path = ($path /sbin /usr/sbin /usr/bin /$home/bin)set prompt = "[%n@%m %c] tcsh % "# turn on ignoreeof and noclobber# turn off notifyset ignoreeofset noclobberunset notify# define aliasesalias lsc ls -Ctalias wg who | grepalias rm rm -ialias cp cp -ralias hibernate sudo apm -s# set permissions for file creation
  30. 30. Unix The Operating SystemUNIX (THE OS) Page 30umask 027This sample file includes C shell variable definitions and aliases, both of which areexplained in the following sections.Shell VariablesThe shell provides a mechanism to define variables that can be used to hold piecesof information. Shell variables can be used to customize the way in which programs(including the shell itself) interact with you. This section will describe some of thestandard variables used by the shell and other programs, and explain what they dofor you.Assigning Variables and Aliases :-Table: Assigning Variables and Aliasessh, ksh, or bash csh or tcsh EffectVAR=value set var=value Assign a value to a variable$VAR $var Get the value of a variableset set List shell variablesunset VAR unset var Remove a variableenv env List all environment variablesVAR=value; export VAR exportVAR=valuesetenv varvalueCreate an environmentvariableunset VAR unsetenv var Remove an environmentvariableset -o View shell optionsset -o option set option Turn on a shell optionset +o option unset option Turn off an optionalias name=value alias namevalueCreate a command aliasunalias name unalias name Remove an alias
  31. 31. Unix The Operating SystemUNIX (THE OS) Page 31Variables in sh, ksh, and bash:- You define a shell variable by typinga name followed by an=sign and a value. For example, you could create a variablecalled PROJDIR to save the pathname for a directory you use often:$ PROJDIR=/home/nate/Work/cs106x/Proj_3/lib/SourceTo assign a value with a space in it, use quotes, like this:$ FILELIST=graphics.c strings.c sorting.cIn the Bourne-compatible shells, variable names are conventionally written inuppercase letters, although you can use lowercase names as well. As withfilenames, variable names are case-sensitive, so the shell will treat PROJDIR andprojdir as two different variables.To get the value of a shell variable, precede the variable name with a dollar sign, $.You can print a variable with the echo command, which copies its standard input toits standard output.$ echo $PROJDIR/home/nate/Work/cs106x/Proj ect_3/lib/SourceEnvironment Variables in sh, ksh, and bash:-When you run a command, the shell makes certain shell variables and their valuesavailable to the program. The program can then use this information to customize itsactions. The collection of variables and values provided to programs is called theenvironment.Your environment includes variables set by the system, such as HOME, LOGNAME,and PATH (described in the next section). You can display your environmentvariables with the command env:$ envHOSTNAME=localhost.localdomainSHELL=/bin/bash
  32. 32. Unix The Operating SystemUNIX (THE OS) Page 32MAIL=/var/spool/mail/rafPATH=/usr/local/bin:/bin:/usr/bin:/home/raf/binPWD=/home/raf/Proj ectPS1=$ HOME=/home/rafLOGNAME=rafTo make variables that you define yourself available to commands as part of theenvironmentCommon Shell Variables in sh, ksh, and bash:- The following isa short summary of some of the most common shell variables, including those setautomatically by the system.HOME contains the absolute pathname of your login directory HOME isautomatically defined and set to your login directory as part of the loginprocess. The shell itself uses this information to determine the directory tochange to when you type cd with no argument.LOGNAME contains your login name. It is set automatically by the system.PWD is a special variable that gets set automatically to your present workingdirectory You can use this variable to include your current directory in theprompt or in a command line.PATH lists the directories in which the shell searches to find the program torun when you type a command. A default PATH is set by the system, butmany users modify it to add additional command directories.A typical example of a customized PATH, in this case for user anita, is the following:PATH=$PATH:/sbin:/usr/bin:/home/anita/binShell Options in ksh and bash:- The Korn shell and bash provide anumber of options that turn on special features. To turn on an option, use the setcommand with -o (option) followed by the option name. To view your current optionsettings, use set -o by itself.
  33. 33. Unix The Operating SystemUNIX (THE OS) Page 33The noclobber option prevents you from overwriting an existing file when you redirectoutput from a command. This can save you from losing data that may be difficult orimpossible to replace. You can turn on noclobber with set:$ set -o noclobberSuppose noclobber is set, and your current directory contains a file named temp. Ifyou try to redirect the output of a command to temp, you get a warning:$ ls -1 > temptemp: file existsYou can tell the shell that you really do want to overwrite the file by putting a bar(pipe symbol) after the redirection symbol, like this:$ ls -1 >| tempTo turn off an option, use set +o, as in$ set +o noclobberThe ignoreeof feature prevents you from accidentally logging yourself off by typingCTRL-D. If you use this option, you must type exit to terminate the shell.s

×