UNIX Notes: - Del Mar College



UNIX/Linux NotesProfessor: Michael P. Harris v.20120902UNIX is a multi-user, multi-tasking operating system originally developed at AT&T Bell Laboratories. It provides utilities/programs for editing text, sending email, preparing tables, performing calculations, Internet access, and many other specialized functions that require separate application programs in other operating systems. One of the key identifying features of UNIX/Linux is the standardized directory and file structure – the fiesystem.Typical UNIX/Linux (root) / Directory structure: bin boot etc dev lib home lost+found mnt root sbin sys tmp usr sys default mike teri shea fd0 hda1 sda bin lib sbin share X (Users home directories) (mounted volumes) (installed apps)The most important versions of UNIX are 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; called BSD. Microsoft’s Xenix, (before MSDOS) was an early popular microcomputer implementation of UNIX based on AT&T release System V. Major versions of UNIX include: SunOS, Solaris, SCO UNIX, AIX, HP/UX, and ULTRIX.GNU Linux is currently the leading popular “Open Source” implementation of a UNIX clone standard operating system. POSIX is the validation standard, set for UNIX-like operating systems. Starting with Windows 2000; Windows XP, Vista and Windows 7 -all have POSIX compliant kernels. Popular Linux OS distributions include: GNU, Ubuntu, Fedora, Debian, Redhat, Knoppix, Puppy, DSL, Gentu, Cygwin, and TinyCore.Since it started more than 50 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 the 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 than corporate standard operating systems like MSDOS & Windows, but it has also helped to make UNIX and Linux the flexible and incredibly powerful operating systems that they are 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." Most modern versions of UNIX can also work with windowing system GUIs (Graphical User Interfaces) 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. Some of the most common window managers are: mwm (Motif Window Manager), CDE (Common Desktop Environment) and the new Linux windows shells: Gnome, KDE, LXDE, Unity, fluxbox, flwm, FLTK, gtk2, iceWM, xfce and others.Getting StartedUNIX/Linux can be overwhelming at first 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 system.oUnderstand the Shell and how to control the system with control characters.oLearn the important UNIX/Linux specific directories and files (the filesystem).oManage UNIX/Linux files and directories, including listing, creating, copying, printing and removing files, and moving in and out of directories.oWork efficiently using UNIX/Linux redirection, pipes, filters, and multi-tasking.Logging InBefore you can start using UNIX/Linux and its facilities, the Super User (root system administrator), has to set up a user account for you with your login name, password, and home directory. At many sites, there will be a whole network of UNIX/Linux computers so you may also have to know the hostname of the computer that has your account as well. When you login at your terminal you should see a message from the UNIX/Linux OS that looks something like:login:Logging in is the process of making yourself known to the UNIX/Linux computer and getting into your account. On remote systems you will need to run a remote login program like telnet, ssh, rxvt, or rlogin. In this case your login session might look similar to the following: (what you type is in bold)ssh mercury.delmar.eduSun Solaris OSmercury.delmar.edu: Solaris UNIX version 10.01.10login: mpharrisPassword: ********Last login: Sat Sep 1 14:34 CST 2012, from mercury.delmar.edumotd: The "crisis" of Today is the "joke" of TomorrowREMEMBER !!!We will be shutting down at 4:30pm for system backups.Wed Sep 5 12:24:48 CST 2012[mpharris@mercury] ~ $_The UNIX/Linux ShellOnce 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 programs you've ask for, and generally coordinates what happens between you and the UNIX/Linux operating system. There are four shells in common use: the Bourne shell, Korn shell, Bash and C shells. 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/Linux vs. MSDOSThe UNIX/Linux operating system has been around much longer than MSDOS. While MSDOS owes much of its original heritage to a single-user microcomputer operating system named CP/M, MSDOS evolved gaining more and more UNIX/Linux 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/Linux is case sensitive meaning that there is a difference between a command typed in upper or lower case. The UNIX/Linux standard is that commands are typed in lower case. A brief comparison of MSDOS and UNIX/Linux command equivalents follows:CDpwdCD DIRNAMEcd dirnameCHKDSKfsckCOPY FILE1 FILE2cp file1 file2COPY FILE1 + FILE2 FILE3cat file1 file2 >file3COPY FILENAME PRNpr filename | lprDIRls -halDIR /Wls -CDIR /Pls -hal | 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/Linux 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/Linux the directory structure and file system is the heart of the system. UNIX/Linux is also device independent --therefore no duplication of commands is necessary for different devices such as the screen, printer, or disk drives.For example, UNIX/Linux always keeps the files in its directory structure in sorted order, therefore 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/Linux commands are 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/Linux 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.Most UNIX/Linux executable commands (utilities) are kept in the /bin, /sbin, and /usr/bin directories with miscellaneous system data files kept in the /etc directory. UNIX/Linux commands are usually short and terse and most always in lower case. UNIX filenames may include A-Z, a-z, 0-9, . and _. After UNIX/Linux boots from the kernel code stored in the /boot or /sys directory, startup files in the /etc/init.d and /etc/profile.d directories are executed. The /etc/profile global user login configuration file and each users private ~/.profile login configuration file are executed. These are the equivalent to the MSDOS CONFIG.SYS and AUTOEXEC.BAT files. The system default setup information is stored in files in the /etc/default directory.When users log into a UNIX/Linux system, their 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 global /etc/profile followed by the users personal startup and setup commands are executed from their own private .profile file stored in their /home/username login home directory.Once logged into a UNIX/Linux system, file access is controlled by the standard UNIX/Linux permissions: r w x ?. The permission settings are for Read, Write (change), eXecute, and permission denied (?). The permissions are grouped into a sets 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 user/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.As an example, assume the ls command (list directory) gave you the following permission settings for the file /etc/motd... is ?rwxr-x--xThe first “–”indicates this is a normal file. The next nine permission settings would indicate that the owner (usually root) 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 the access mode permissions to your files with the chmod command, you have the options of typing: a, u, g, and o (for All, User/owner, Group, and Others) the syntax is:chmod -options filename…where 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/Linux commands for redirecting Input and Output are:>redirect output<redirect input>>redirect output append<<redirect input (here)|pipe (output into input)teesplit output into two streamsFor example:who | sort > wholist…would 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 then the sorted list would be redirected/written to the file wholist.And with...banner < wholist >> register…the contents of the file wholist is fed into the command banner (which generates large bannerized letters) and add this output to the end of the file register.UNIX/Linux Directory GuideTypical UNIX/Linux (root) / Directory structure: bin boot etc dev lib home lost+found mnt root sbin sys tmp usr sys default mike teri shea fd0 hda1 sda bin lib sbin share X (Users home directories) (mounted volumes) (installed apps)/UNIX/Linux root directory/bin, /usr/binUNIX/Linux binaries (commands/utilities)/bootUNIX/Linux file system boot loader programs/etcSystem configuration data files /etc/defaultSystem default setup files/devPeripheral device control (driver) files/homeUsers personal directories (contains user login directories)/lib, /usr/libLibraries for the 'C' compiler/lost+foundDepository for misplaced files/mntDirectory containing empty directories to mount file systems/procSystem processes control files/rootThe Super User (root) login directory/sbin, /usr/sbinAdministration binaries (commands) files/sysCode for UNIX kernel (operating system)/tmpTemporary files (may be auto deleted)/usr/shareShared user files and installed application packages/usr/share/manOnline manuals for commands and files/var/spoolPrint spooler master directoryUNIX/Linux File Guide.Name of current directory..Name of current directory's parent~/.profileSet up environment at login (user personal startup file)/etc/bashrcBash restart cold (e.g. cold start configuration file)/etc/dircolorsConfiguration file for the dircolors utility (command)/etc/fstabLog/table of mounted filesystems/etc/groupDesignate user group 'names'/etc/init.d/*Directory of system initialization and startup files/etc/motdMessage Of The Day -login message for users/etc/passwdDefined system users and access information/etc/printcapDefine standard printer setup information and capabilities/etc/profileUser set up environment at login (global startup file)/profile.d/*.shDirectory of user/application shell script startup files (*.sh)/etc/shellsList of available login shells (ex. sh, bash, ksh, …)/etc/termcapDefine standard terminal setup information and capabilitiesSample UNIX/Linux /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 or .bash_profile in /home/username/.profileUnix/Linux Commands: Prof. Michael P. Harris, CCNA, CCAI(a working command set) ITSC 1358 – Unix/Linux System Admin.[, [[Alias for the test boolean expression command. [[ is an enhanced test.((Enhanced form of the let Integer math expression command.adduser, useraddUsed by root to add user to system. Usage: adduser useridalias, unaliasAssign name to specified command list. e.g. create a macro commandatExecute a shell script at specified time. Usage: at [-f] file time atq, atrmatq shows, and atrm removes, pending jobs queued by at.awk, gawk, nawkSearch for and process patterns in a file. A shell scripting language.bannerPrint banner to standard output. Usage: banner [option] charactersbashBourne Again SHell. This is the default shell in most Linux installations.busyboxMulti-call command library –acts like the command name used to call it.bzip, bzip2Compress files with an algorithm different from gzip. See also: lzma bunzip, bunzip2Uncompress files compressed with bzip. See also: gzipcc, c++Invoke the C and C++ program compilers. See also: gcc, g++calDisplay a 12-month or a one-month calendar. Usage: cal [month] yearcatConcatenate/combine stdin to stdout. Read or display files.cdChange working Directory. Usage: cd path, cd, cd ~, cd .., cd —cfdiskSimilar to fdisk, but menu-driven, create/edit partitions. See: fsckchmodSet permissions (access modes) for files or directories. See also: umask chgrpChange the group associated with a file. Usage: chgrp [-R] group files chownChange the user/ownership of a file. Usage: chown [-R] userid fileschsh Change default shell. See also: sh, bash, ksh, csh, tcsh, zshclearClear screen command. (tput clear)cmpCompares two text files for differences. See also: diff, diff3, uniqcommCompare sorted text files. See also: sort, diff, diff3, uniqcompressCompress (uncompress) files to the older .Z file format. See: gzip, zcatcpCopy one or more files. Usage: cp [-r][-p] source target[directory]crontabSchedule command(s) to run at regularly specified times. See also: atcshThe C shell. See also: bash, ksh, sh, csh, tcsh, bsh, ash, and zshcutSelect characters or TABed fields from files/lines of input. See: pastedateDisplay or set date and time. Not related to time. Usage: date [date]dfDisplay disk free space and disk capacity on physical devices. See also: dudiffDisplay differences between two files. See also: diff3, uniq diff3Compare three files and reports on differences. See also: uniqduDisplay information on disk usage and file sizes. ex. du / –bh | lessechoDisplay text/arguments to standard output. ex. echo $PATH, echo ~emacsA very powerful screen oriented text editor. See also: vi, vim, nanoenv, printenvDisplay, or set a new value to, the environmental setting variables.evalScan and evaluate the command line. See also: let, expr, testexAn interactive command-based editor. See also: vim, vim, sedexecSystem call which creates a subshell to execute a binary or a script.exitexit (terminate) a command-line shell. Also to logout of a shell.expandConvert tabs in files to spaces and write to standard output.exportPlace the value of a variable in the set environment (make it global).exprEvaluate an expression and displays the result. See: let, eval, testfalseNull command that returns an unsuccessful exit status. See also: truefcView, edit, execute commands from the command history. See: historyfdiskUtility used to partition hard drives. See: cfdisk Usage: fdisk devicefileDisplay the classification of a file(s) based on the type of data within.findFind files matching a large variety of search criteria. ex. find . –type dfingerDisplay information about a specified userid or userids. See also: pinkyfmtSimple text formatting utility. Make lines the same length. See also: prfoldBreak lines of text files so they are no wider than a given length. See: fmtfreeDisplay used/free system memory along with other useful information.fsckFile System Check and Repair. Filesystem diagnostics.ftpFile Transfer (Protocol) over the network. See also: tftp, scp, wgetgcc, g++Invoke the GNU C or C++ compiler. See also: cc, c++grep, fgrep, egrepFind a string or pattern within a file(s). Usage: grep pattern [files]groupsShow which groups you are a member of. See also: id, whoamigrubGNU GRand Unified Bootloader. Boot multiple OSs. See also: lilogzip, gunzipUtility used to compress or uncompress files. (.gz, .tar.gz, or .tgz)haltShut down system as root, without reboot, immediately. See: shutdownhashRemember the location of commands in the search path.headDisplay the first part (10 lines default) of a file. See also: tailhistoryView and manipulate the shell command history list. See also: fchostLook up host names using a domain server. See also: hostname, unamehostnameDisplay/set the hostname (computername). $HOSTNAME /etc/HOSTNAMEidDisplay your userid and groupid. See also: logname, groups, whoamiinetd Daemon which starts other daemons on demand. See: /etc/inetd.confifconfigDisplay information on network interfaces that are currently Display system information. This is the GNU hypertext reader. See: maninitMaster process, runs at bootup, executes commands in: /etc/inittabjobsLists current running jobs/programs. See also: ps, pstree, topkillSend a signal to terminate a job or process. ex. kill –9 pidkshKorn SHell. See also: bash, sh, ksh, csh, tcsh, and zshlddList/locate the shared libraries on which a given executable depends.lessImproved more command. Display text files, many options. See: moreletEvaluate a integer numeric expression. See also: (( )), eval, testliloLInux LOader, install a boot loader on a device boot sector. See: grubln, ln ?sCreate a link to a file. Create hard links and/or ?s symbolic links.locateFind files that that match a pattern; easier syntax than find. (updatedb)loginLogin to the Unix/Linux operating system. See also: ssh, logoutlognameConsult /etc/utmp for user's login name. See also: who, id, hostnamelogoutExecute logout as individual user and bring up the login: prompt. ^DlprSend file to be printed, used with pr. See also: lpq, lprm, /var/spool lpqPrinter queue, show print jobs that are waiting to be printed. lprmCancel a print job from a print queue.lsList directory contents. ls –hal, ls –FAC, ls ––color, ls –FRACmakeKeep a set of programs current, works by executing the script makefile.makewhatisCreate database used by apropose and whatis. /usr/share/man/whatisman, ––helpDisplay information from online the Unix reference manual. See: whatismcMidnight Commander file manager and visual shell. Also: mcedit, mcviewmkdirMake (create) a directory. See also: cd, rmdir, rm –rd, mvmkfsMake (create) a File System –format a device or partition. See: ddmkswapCreate a Linux swap space on a specified hard disk partition. See: swaponmoreList file contents, stopping after each full screen. Q exits. See: lessmount, umountMount a partition as a directory in the filesystem. See: /etc/fstabmvMove (rename) files and directories. See also: cp, cpio, ddniceSet the runtime priority of a program. Usage: nice program_nameodOctal Dump –display contents of a file in octal/hex. See: hd, hexdumppasswdChange your login password. See: /etc/passwdpasteJoin corresponding lines from files. See also: cut, split, joinpathchkDetermine the validity and portability of filenames. See also: cygcheckperlPractical Extraction & Report Language. Scripting language. See: pythonpingCheck if an Internet computer is responding (online). See: tracerouteprPaginate files for printing; used with lpr. See also: fold, fmtpsDisplays processes status. Usage: ps -a See also: top, jobs, top, kill pstreeDisplay processes in the form of a parent/child tree structure. See: pspwdPrint absolute path of the Working (current) Directory. $PWD, $OLDPWDpythonInterpreted, interactive, object-oriented scripting language. See: perlreadRead a line from standard input into the variable $REPLY. See: echormRemove files or [-r] directories. Usage: rm [-r][-rd] filepath rmdirRemove empty directories. See also: rm –rrmuserRemove user account from the filesystem. See also: userdel, adduserrouteShow the routing table entries. Usage: route [-n]rpmInvoke the Redhat Package Manager in command line mode. See: yumrxvtA terminal program, like xterm, with less features and uses less memory.sedEdit a file stream (redirect). Also a tool for processing text files.set, setenvSet or display values of shell variables. See also: env, export, declareshThe standard Bourne SHell. See also: bash, ksh, csh, tcsh, and zshshutdownReboot/shutdown system as root. Usage: shutdown [-h] [-r] minutessleepCreate a process that sleeps for specified interval. See also: waitsortSort and/or merge files. See also: uniq, diff, cut, paste, join, splitsourceRun a shell script in the current shell/environment. Alias: “.” (dot)splitSplit a file into specified number of segments. See also: csplit, cutsshSecure remote login SHell. See also: telnet, rlogin, rsh, xtermstartxFront-end to xinit (xterm), start X-clients/X-server window managers.suSimulate User -login as another user, including root (Super User).sudoSuper User DO, allow users root permission to run tasks. /etc/sudoersswapon, swapoffEnable or disable swap disk (file) usage. See also: mkswapsymlinksProvide a list of, and information about, symbolic links. See: ln -ssyncWrite memory buffers to physical devices for safe removal. See: rsynctailDisplay the last part (default 10 lines) of a file. See also: head, tactarTape ARchive, file compression/archiving utility. tar [–xcvf] file.tartcshExtended version of the C-shell, csh. See also: bash, ksh, sh, and cshteeCopy standard input to standard output and to one or more files. Also “|”telnetRemote login over the network. See also: ssh, rsh, rlogin, xtermtestEvaluate a boolean expression or compares arguments. Alias: [ and [[tftpUser interface to TFTP (trivial FTP) protocol. See also: ftp, scp, wgettimeDisplay run times for current shell programs and processes. See: uptimetopDynamically display process status. See also: ps, pstree, jobs, killtouchCreate an empty file or update access and modification times of a file.trTRanslation utility, replace specified characters in a text file.trueA null command that returns a successful exit status. See: falsettyShow information that represents your terminal and terminal pathname.umaskEstablish the file-creation permissions mask. Usage: umask xyzumountFinish writing to a device and unmount it from the active filesystem.unameDisplays information about the UNIX OS system. Usage: uname [-a]uniqDisplay lines of a file that are unique. See also: diff, cmp, communzipUncompress files compressed with zip, compatible with DOS PKzip.updatedbScript used to build/update the database used by locate.uptimeShow the system up time, number of users, and average load. See: timeuserdelRemove user account (as root). The user's home directory is not deleted.usersPrints list of users on the system. See also: who, groups /etc/passwdvdirVariant of the ls command. Defaults to printing a long listing.viStandard screen oriented VIsual editor. See: vim, view, nano, mcedit viewvi/vim in read-only mode. See also: less, mcviewvimVi IMproved, vi editor. See also: vi, view, nano, and mceditwaitWait for a background process to terminate. See also: sleepwcWord Count, display number of lines, words and/or characters in a file.wgetFile transfer utility using HTTP, FTP, and other Internet protocols.whatisDisplay a one-line summary about a specified command. See also: manwhereisFind utilities/files from standard locations. See: makewhatis, locatewhichFind utilities/commands using the search path. See: locate, whereiswhoDisplay information about currently logged in users. See also: users, idwhoami, who am iDisplay information about the userid that is currently logged in. See: idxtermStart an X-Window terminal session. See also: rxvtzcatRead to stdout files that have been compressed with gzip or compress.zip, unzipZip compress/uncompress utility compatible with DOS PKzip. See: gzip ................
................

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

Google Online Preview   Download