UNIX Notes:



UNIX/Linux Notes:Professor: Michael P. Harris v.20091109UNIX is a multi-user, multi-tasking operating system originally developed at AT&T Bell Laboratories. It provides programs for editing text, sending electronic mail, preparing tables, performing calculations and many other specialized functions that require separate application programs in other operating systems. One of the key identifying features of UNIX is its standardized directory and file structure.Typical UNIX/Linux root /Directory structure: bin etc dev mnt lib lost+found home tmp sys boot unix default (mounted volumes) mike teri ... etc bin lib spool hd0 fd0 sd0 (users home directories)There are many different versions of UNIX. One of the most important is the line of UNIX releases that started at AT&T, the latest being System V Release 4. Other important UNIX versions have come from the University of California at Berkeley; the latest is called BSD. Microsoft’s Xenix, a early popular microcomputer implementation of UNIX was originally based on an earlier AT&T release called System V. Linux is currently the leading popular “Open Source” implementation of a Unix-like standard operating system. POSIX is the validation standard, set for UNIX-like operating systems. Starting with Windows 2000 Pro, Windows 2000, XP, and 2003 are all now POSIX compliant. Other major versions of UNIX include SunOS, Solaris, SCO UNIX, AIX, HP/UX, ULTRIX, NOVELL UNIX (Univel), and the various implementations of the popular Linux OS.Since it started more than 35 years ago, UNIX has grown and changed in a different way from most operating systems. Many early UNIX users were computer and scientific professionals; more than a few of them extended UNIX by adding tools and functionality to do what they needed. UNIX was also used to develop a lot of the powerful networking systems that connect the world, such as Internet. So, whereas most operating systems were typically developed and controlled by one corporation, UNIX has been developed through a collective effort. This has meant more versions and somewhat more confusion than "standardized" operating systems like MSDOS & Windows. But it has also helped to make UNIX the flexible and incredibly rich and powerful operating system that it is today.UNIX and its derivatives were not designed as "user-friendly" operating systems, in fact, UNIX has, in the past, earned its label of "user-hostile." UNIX can be used the way it was originally designed, on typewriter-like terminals (ttys). Most modern versions of UNIX can also work with window system GUIs (Graphical User Interface) which allow each user to have more than one "terminal" on a single display. The X Window System (called X for short) is the most common UNIX window system. The appearance of X Windows may vary between systems due to different window managers. Four of the most common window managers are mwm (Motif Window Manager), olwm (Open Look Window Manager), CDE (Common Desktop Environment) and the new Linux windows shells Gnome, KDE, fluxbox, and others.Getting Started:UNIX can be overwhelming with its barrage of details. To get started though, all you need to do is master just a few details:oHow to Log in and out of your systemoUnderstand the Shell and how to control the system with control charactersoLearn the important UNIX specific directories and filesoManage UNIX files and directories, including listing, creating, copying, printing and removing files, and moving in and out of directoriesoWork efficiently using UNIX pipes, filters, and multi-tasking.Logging In:Before you can start using UNIX and its facilities, the System Administrator has to set up a UNIX account for you with your login name, password, and home directory. At many sites, there will be a whole network of UNIX computers so you may also have to know the hostname of the computer that has your account as well. When you turn on your terminal you should see a message from the UNIX computer that looks something like:login:Logging in is the process of making your self know to the UNIX computer and getting into your account. On remote systems you will need to run a remote login program like telnet, rlogin, cu, or tip. In this case your login session might look similar to the following: (what you type is in bold)telnet mercury.delmar.eduSun Solaris OSmercury.delmar.edu: Solaris UNIX version 9.00.10login: mpharrisPassword: ********Last login: Wed Nov 28 14:34 CST 2005, from mercury.delmar.edumotd:The "crisis" of Today is the "joke" of TomorrowREMEMBER !!!We will be shutting down at 4:30pm for system backups.Fri Dec 2 12:24:48 CST 2005$_ The UNIX Shell:Once you've logged into a UNIX computer, you're working with a program called the shell. The shell interprets the commands you enter, runs the program you've ask for, and generally coordinates what happens between you and the UNIX operating system. There are four shells in common use: the Bourne shell, Korn shell, Bash and C shell. For the novice the differences are slight however some to run some software or execute some program (especially shell scripts) you will need to know which shell you are using (ask your system administrator). The only immediate difference you will see is that the Bourne, Korn, and Bash shells prompt you with $_ while the C shell most often uses %_ as the prompt. Certain keyboard commands (keystrokes) are interpreted by the shell, these are commonly called control characters. The basic control characters are:Ctrl-C or [DEL]Interrupt character (interrupts or cancel a command)Ctrl-DReturns you to UNIX command level. Used to signal end of input. ** Also logs you off of most UNIX systemsCtrl-H or [BACKSPACE]Erase character to left of cursorCtrl-QRestart output after paused by Ctrl-SCtrl-SPauses output to the screenCtrl-UErase the whole input line so you can start overUNIX vs. MSDOSThe UNIX operating system has been around much longer than MSDOS. While MSDOS owes much of its original heritage to a single-user operating system named CP/M, MSDOS evolved gaining more and more UNIX like capability. MSDOS is not case sensitive meaning that commands can be typed in either upper or lower case and MSDOS treats them all as if they were typed in UPPER CASE. UNIX is case sensitive meaning that there is a difference between a command typed in upper or lower case. The UNIX standard is that commands are typed in lower case. A brief comparison of MSDOS and UNIX command equivalents follows:CDpwdCD DIRNAMEcd dirnameCHKDSKfsckCOPY FILE1 FILE2cp file1 file2COPY FILE1 + FILE2 FILE3cat file1 file2 >file3COPY FILENAME PRNpr filename | lprDIRlsDIR /Wls -CDIR /Pls | moreDEL FILENAMErm filenameMD DIRNAMEmkdir dirnameREN FILE1 FILE2mv file1 file2RD DIRNAMErmdir dirnameTYPE FILENAMEcat filenameFile Access and PermissionsAn important point to always remember is that in UNIX everything is a file. The textbook definition of UNIX usually goes something like this...UNIX - a multi-user/multi-tasking interactive operating system developed by AT&T. UNIX has a directory structure that is tree-like with files containing all the information that is part of the system. Most people familiar with microcomputers and MSDOS are familiar with the tree-like directory structure with directories, sub-directories and pathnames. But in UNIX the directory structure and file system is the heart of the system. UNIX is also device independent --there for no duplication of commands is necessary for different devices such as the screen, printer, or disk drives.For example, UNIX always keeps the files in its directory structure is a sorted order, there for to rename a file is really moving that file within the directory structure. To copy that file to another directory, to the screen, or to a floppy disk drive is the same command because UNIX is device independent, everything is a file, the destination directory, the screen, the auxiliary storage device are all files to UNIX. This concept may take a little getting used to before all that is means sets in.To log into a UNIX system your terminal must be described to the system. In the directory /dev the system device files (files that contain the hardware interfacing information UNIX needs) are contained. In addition, your terminal type is stored in /etc/ttytype, your terminal speed in /etc/ttys, and your terminal setup and capabilities data in /etc/termcap. The advantage of this system is obvious, if you change your terminal or enhance its capabilities, your just edit the system files. In addition you can have multiple definitions and settings for multiple different users.The UNIX executable commands are kept in the /bin directory with miscellaneous system data files kept in the /etc directory. UNIX commands are usually short and terse and most always in lower case. UNIX filenames may include A-Z, a-x, 0-9, . and _. After UNIX boots from the kernel code stored in /unix directory, the /etc/rc startup file is executed. This (reboot cold) startup file would be the equivalent of the MSDOS CONFIG.SYS and AUTOEXEC.BAT files. The system default setup information is stored in the /etc/default file. When users log into a UNIX system, there access is controlled by password and access information stored in the /etc/passwd and /etc/group files. Once logged in users are met by the users login message-of-the-day stored in the /etc/motd file and then the users personal startup and setup commands are executed from their own private .profile file stored in their /home/username login/home directory.One logged into the UNIX system file access is controlled by the standard UNIX permissions: r w x -. The permission settings are for read, write (or change), eXecute, and permission denied (-). The permissions are grouped into a set of three rwxrwxrwx where the first three are the permissions for the user/owner of the file, the second three are the permissions for members of the group assigned to the file and the last three permissions are for all others who may wish access to the file. The command chown is used to change the owner of the file. The command chgrp will change the group assigned to the file. And the command chmod (for change access mode) will change the file permissions. Of course, you must have write permission to change the owner, group assignment, or permissions to a file. As an example, assume the ls command (list single file) gave you the following permission settings for the file /etc/motd... rwxr-x--xThese permission settings would indicate that the owner (usually supervisor) has Read, Write, and eXecute permissions to the file. Those who have the assigned group access permissions can Read and eXecute the file, all others may only eXecute the file. When changing permissions to your files with the chmod command, you have the options of a, u, g, and o (for All, User/owner, Group, and Others) the syntax is:chmod options filenamewhere options can include:(1) a, u, g, o(2) + or -and (3) r, w, xin any combination.For example: chmod g+rx myfile would add Read and eXecute to the group portion of the permission settings.Alternate Input / Output, Piping, and RedirectionThe Unix commands for redirecting Input and Output are:>redirect output<redirect input>>redirect output append<<redirect input append|pipe (output into input)teesplit output into two streamsFor example:who | sort > wholistwould execute the who command (generate a list of who is currently logged on to the system) and pipe the output into the input of the sort command (alphabetize) and the sorted list would be written to the file wholist.and...banner < wholist >> registerthe file contents of wholist would be fed into the command banner (which generates large bannerized letters from file contents) and add this output to the end of the file register.UNIX DIRECTORY GUIDETypical UNIX/Linux root /Directory structure: bin etc dev mnt lib lost+found home tmp sys boot unix default (mounted volumes) mike teri ... etc bin lib spool hd0 fd0 sd0 (users home directories)/UNIX root directory/binUNIX Commands (binary files)/bootUNIX file system bootstrap loader programs/etc miscellaneous system data files /etc/defaultsystem default setup files/devperipheral device control files/liblibraries for the 'C' compiler/lost+founddepository for misplaced files/mntempty directory to mount file systems/syscode for UNIX kernel (operating system)/tmptemporary files (may be auto deleted)/homeusers master/personal directory (or /usr, or /user)/ home /binmore commands usually user created/ home /libmore language libraries and data files/ home /spoolprint spooler master directory/ home /tmpusers temporary files/ home /asmadministration accounting files/unixexecutable code for UNIX kernelUNIX FILE GUIDE.name of current directory..name of current directory's parent.profileset up environment at login (personal startup file)/etc/groupdesignate group 'names'/etc/logbooklogbook of installed software/etc/motd(message of the day) login message for users/etc/passwddefine system users and access/etc/rcdefine system initialization and startup commands/etc/systemiddefine system name/etc/termcapdefine standard terminal setup information and capabilities/etc/ttysdefine terminal port status/speed/etc/ttytypedefine default terminal type/home/lib/crontabtime & date for auto execution/home/adm/messagesrecord of console messagesSample UNIX / home directory with subdirectories: / home adam betty edward mark ... demo1 memo etc letter util fax pgms news bin fax make demo2 mm1 let1 fax1 jan mod1.c mm2 let2 fax2 feb mod2.c let3 marAll users have a personal .profile file in /home/username/.profileALPHABETICAL LIST OF UNIX COMMANDSThe commands in the Basic System are listed below in alphabetical order.asktimeset system date and timeassignassign a device to a useratexecute commands at a later timeatqexamine the "at" job queueatrmremove a job from the "at" job queueawkpattern scanning and processing languagebannerprint large lettersbcarbitrary-precision arithmetic languagebdiffcompare very large filesbfsscan big filescalprint calendarcatconcatenate and print filescdchange working directorychgrpchange groupchmodchange mode (change access permissions)chownchange file ownerchrootchange the process root directorycmpcompare two files (any type)commselect or reject lines common to two sorted filescopycopy groups of filescpcopycpiocopy file archives in and outcronexecute commands at specified timescryptencode or decode a filecsplitsplit files according to contextcucall the UNIX systemdateprint and set the datedcdesk calculatordevnmidentify device namedfreport the number of free disk blocksdiffcompare two text filesdiff3compare three text filesdircmpcompare directoriesdirnamedeliver the directory part of a path namedisableturn terminal use offdtypeprint disk type (such as Xenix, MSDOS, tar)dusummarize disk useechoecho argumentsedinvoke text editor (line editor)egrepsearch a file for a patternenableturn terminal use onenvset or print the environment for command executionextext editor (line editor)exprevaluate arguments as an expressionfalseprovide truth value by returning with a nonzero exit codefgrepsearch a file for a patternfiledetermine file typefindfind filesfingerfind information about usersfsckcheck file system for consistency and repair if necessarygrepsearch a file for a patterngrpcheckcheck group filehaltsysshut system downhdgive hex dump of a fileheadgive first few lines of a fileidprint user and group ID and namejoinjoin two relationskillterminate a processllist directory contents in long form (equivalent to ls -1)lclist directory contents in columnslearngive computer-aided instruction about UNIXlineread one linelnmake a link to a filelogingive access to the systemlognameget login namelookfind files in a sorted listlprsend files to the line printer queue for printingls list the contents of a directorymailsend, receive, or dispose of mailmesgpermit or deny messages sent to a terminalmkdirmake a directorymkfsmake a file systemmknodmake a special filemkuseradd a new user accountmoredisplay a file one screen at a timemountattach a file system to a directory on the root subtreemvmove or rename files and directoriesnewgrplog into a new groupnice run a command at a different prioritypackcompress filespasswdchange login passwordprprint a filepsreport process statuspstatprint system factspwcheckcheck the password filepwdprint the name of the working directoryquotsummarize file system ownershiprandomgenerate a random numberremoteexecute commands on another machinerestorinvoke incremental file system restorerrmremove a filermailsend mail among usersrmdirremove a directoryrmuserremove a userrshinvoke a restricted a shellsdiffcompare two files side by sidesedinvoke stream editorsetmntestablish a mount table (/etc/mnttab)settimechange file access and modification datesshinvoke the Bourne shellshutdownshut down the systemsleepsuspend execution for an intervalsortsort or merge filessplitsplit a file into piecessttyset terminal optionssumake the user root or another user temporarilysumcalculate checksum and count blocks in a filesysadminperform file system backup and restoretaildeliver last part of a filetararchive filesteecreate a tee in a pipe to save intermediate outputtesttest conditionstouchupdate file access and modification timestrtranslate characterstruereturn with a zero exit valuetsetset terminal typettyget terminal nameunmaskset default file creation maskunmountdetach a file system from the root directoryunameprint the current UNIX nameuniqreport repeated lines in a fileuucpcopy files from UNIX to UNIXuulogcopy files from UNIX to UNIXuuxexecute commands on remote UNIXviinvoke a screen-display editor based on exvshinvoke the visual shellwaitwait for background jobs to finishwallwrite to all userswccount lines, words, and characterswhat identify fileswholist users currently logged onwhodoshow who is doing whatwritesend a message to a user's terminalxargs construct argument lists and execute commandsyesprint string repeatedly ................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download