《Unix操作系统命令.pdf》由会员分享,可在线阅读,更多相关《Unix操作系统命令.pdf(75页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、Unix 操作系统命令操作系统命令UNIX操作系统(第五版)操作系统(第五版)Jerry Peek,Grace Todino&John Strang 著 龚志翔著 龚志翔等译等译2003年年1月出版月出版书号:书号:7-111-10164-2页数页数:188定价:定价:26.00元元Reference BookLog in and out of a Solaris systemNavigate the Solaris file systemCreate files and directories,and change their permissionsManipulate text files
2、,and use the vi text editorUse commands to search directories and filesUse basic network commandsIdentify and modify initialization filesCourse ObjectivesReleaseSunOS SolarisHP-UXAIX WindowsRedhat Linuxdate version versionversionversion versionversion19831119851198611987219894.0.2319904.1.31.1A 1991
3、19925293.11993419945.42.4Halloween 19951095,NT2.019965.5.12.5.110.24.219975.62.6114.35.019985.774.3.1 9819996.0,6.120005.8811i 5L Me,20007.020025.995L(5.2)XP8.0Release sunOSSolaris HP-UX AIX Windows Redhat LinuxDate version versionversionversionversionversionHalloweenUnix Version HistoryWhat can it
4、do?Server:Web server,Mail server,Database Server,Program DevelopmentWho should know Unix?Unix administrator,Oracle Administrator,Network Engineer Program DeveloperMore about UnixInput devicesOutput devicesHardwareOperating System vs.Application SoftwareClient vs.ServerSoftwareSolaris OS?Kernel?Shell
5、?File SystemHardwareKernelShellCPUOthersMacUnixLinuxWindowsSUN,IBM,HP,SGI,FreeBSD,DEC,SCORedHat,SuSE,SlackWare,红旗红旗NT,98,2000,XPUNIX 和其他操作系统比较和其他操作系统比较Manages devices,memory,and processesControls the functions between the system programs/utilities and the system hardwareManages swap space,daemons,fi
6、le systems,and other functionsKernelA shell is an interface between the user and the kernel,which acts as an interpreter or translatorThree shells are available in the Solaris environment:Bourne shell (sh)Korn shell (ksh)C shell (csh)Bourne-again shell (bash)ShellWritten by Stephen Bourne for AT&T U
7、nixThe earliest and best-known Unix shellCommon denominator of most shell scriptingBourne-Again Shell(bash)#root$userBourne Shell(sh)Created as part of BSD Unix by Bill Joy,the author of vi,at the University of California at BerkeleyIntroduced command-line history and a programming environment simil
8、ar to the C programming languageNot compatible with Bourne shell syntaxtcsh,an enhanced but totally compatible csh#root%userC Shell(csh)A hierarchy of directories,subdirectories,and files grouped together for a specific purpose.Directory A location for other files and directories.The directory struc
9、ture enables you to create files and directories accessed through a hierarchy of directories.Subdirectory Any directory below another directory.For example,some of the subdirectories under the/directory are/usr,/etc,and/kernel.The File SystemA pathname uniquely identifies a particular file or direct
10、ory byspecifying its locationA slash(/)between each directory name in the path to indicate different directories A slash in the first position represents the/directoryAbsolute Pathname Specifies a file or directory in relation to the/directory Begin with a slashRelative Pathname Specifies a file in
11、relation to the current working directory Do not begin with a slashPathnames$Command option(s)argumentsA space must be used as a delimiter between each part of the command lineUp to 256 characters can be entered on a single command lineDifferent from DOS Case sensitive Different command prompt:/Comm
12、and-Line SyntaxClear the terminal screenclearclearDisplay the absolute pathname of the current directory(print working directory)pwdpwdChange DirectoriesAccept both absolute and relative pathnamesCurrent directory.Parent directory.cd directory_namecd/export/home/jerrycd jerry/dir1cdcd./.cdDisplaying
13、 a Listing of Files and Directories ls aDisplaying hidden filesHidden file:a file started with a“.”ls RDisplaying a recursive listing ls tSorts by time stamp instead of by name ls lDisplaying a long listd rwx r-x r-x 4 user nobody 1024 Feb 22 09:20 a.txt文 拥 同 其链拥拥大最后一次文文 拥 同 其链拥拥大最后一次文件 有 组 它接有有小修改时
14、间件件 有 组 它接有有小修改时间件类 者 人 人号者组名类 者 人 人号者组名型 权 权 权型 权 权 权限 限 限限 限 限lsd directory-normal filefile filename(s)Text,including ASCII text,English text,commands text and executable scripts Executable or Binary,including 32-bit executable and extensible linking format(ELF)code files and other dynamically lin
15、ked executables Data,those created by an application running on the systemls FDisplaying file types目录文件/目录文件/可执行文件*可执行文件*文本文件文本文件(none)File Typer-读权限读权限w-写权限,对目录来说,可生成文件与子目录或删除文件与子目录写权限,对目录来说,可生成文件与子目录或删除文件与子目录x-执行权限,对目录来说,可查找该目录下内容执行权限,对目录来说,可查找该目录下内容-没有权限没有权限如如-rw-r-r拥 同 其拥 同 其有 组 它有 组 它者 人 人者 人 人
16、其中 拥有者-生成文件时登录的人,权限最高,u表示其中 拥有者-生成文件时登录的人,权限最高,u表示同组人-系统管理员分配的同组的一个或几个人,g表示同组人-系统管理员分配的同组的一个或几个人,g表示其它人-除拥有者,同组人外的人,o表示其它人-除拥有者,同组人外的人,o表示所有人-包括拥有者、同组人及其它人,a表示所有人-包括拥有者、同组人及其它人,a表示File PermissionChange permissionsSymbolic mode uses combinations of letters and symbolschmod g-r file1chmod u+x,go+r fil
17、e1chmod a=rw file1chmodchmod mode filenamewho cp permission(s)r Readw Writex Execute=Set permissions-Remove access+Give accessu User or owner of the fileg Group to which the file belongso Others outside owner and groupa All of the aboveOctal mode uses octal numberschmod 555 dantechmod 644 dantechmod
18、 755 danteOctal Value Permissions4 Read2 Write1 ExecuteOctal Value Permissions7 r w x6 r w -5 r -x4 r -3 -w x2 -w -1 -x0 -Create new,empty files or update access and modification timestouch filename(s)touchCreate directories using either an absolute or a relative pathnameMust have the appropriate pe
19、rmissions to create a directorymkdir-p directory_namemkdir dir1/dir2mkdir dir3 dir4 dir5mkdir/gamesmkdir-p dir6/dir7/dir8mkdirCopy filescp-i source_file destination_filecp-i source_file(s)destination_directorycp beans applecp beans apple dir2cp i beans appleCopy a directory and its contents to anoth
20、er directorycp-ri source_directory(s)destination_directorycp-r dir3 dir4cp-r dir3 dir4/tmpcpMove or rename files and directoriesmv-i source target_filemv-i source target_directorymv nuts beansmv/export/home/jerry/brands mv dir5 dir6mvRemove filesrm-i filename(s)rm file1 file2 file3rm-i file4Removing
21、 Directoriesrmdir directory_name(s)rm-ri directory_name(s)rmdir empty_dirrm r dir6rm ir/dir7rm&rmdirCreate alternate names or aliases for files and directories symbolic(or soft)linksln-s source_file target_filelnSymbolic links link a file or directory across file systemsLink 1file2Data blocksData bl
22、ocks/file2 The UNIX Manpages describes information about the systems on-line commands,system calls,file formats,and system maintenanceman nameman k keyword Scrolling in ManpagesSpacebarScroll through a manual page one screen at a timeReturnScroll through a manual page one line at a timebMove back on
23、e screenf Move forward one screenq Quit the man command/stringSearch forward for informationn Find the next occurrence of stringMan -man is your friendAre keyboard characters with special meaning to the shellExamples:;$%!*?|Except The dot(.)and underscore(_)MetacharactersRepresents zero or more char
24、actersls d*Asterisk(*)Represents any single characterls d?ls z?.txtQuestion Mark(?)Match a set or range of characters to a single character positionls b-fb*ls fFf*a?cSquare Brackets()Enter multiple commands on a command linecd;lsdate;cal;pwdSemicolon(;)Use()to redirect the output of a command to a f
25、ile rather than to the screenUse()to append the output of a command to an existing filecal 10 2004 a.txtcal 11 2004 a.txtcat f2.txt Angle Brackets(,)Takes the output of one command and passes it as input into a following commandls-l/etc|morePiping(|)Configuration files,web pages,program source code
26、are all text-basedText viewers v.s.editorsText EditingDisplays the contents of a text file on screenIs often used to join two or more files into one large filecat filename(s)cat /dev/null /b.txtcatDisplays the contents of a text file one screen at a timemore filename(s)Spacebar Scroll to the next sc
27、reenReturn Scroll one line at a timeb Move back one screenf Move forward one screenh Display a Help menu of more featuresq Quit and return to the shell prompt/stringSearch forward for stringn Find next occurrence of stringmoreDisplays the first or last n lines of one or more filesDisplays first or l
28、ast 10 lines by defaulthead -n filename(s)tail -n filename(s)tail -30 /usr/dict/wordstail f 可实时刷新可实时刷新head&tailCommandmodeLast-linemodeEntrymodeEscapeReturn:/?i a ovi Full Screen Text Editorvi filenameOpen or create a filevi Open a new file to be named laterInvoking vi向上向上k向下向下j向左向左h向右向右lPositioning
29、i在光标当前位置插入在光标当前位置插入a在光标所在位置后插入在光标所在位置后插入o在光标所在行下插入一空行在光标所在行下插入一空行退出插入状态退出插入状态Inputx删除一个字符x删除一个字符dw删除当前词dw删除当前词3dw 删除三个词3dw 删除三个词dd删除当前行dd删除当前行5dd 删除五行5dd 删除五行:5,10d:5,10dDeleting Textr替换一个字符r替换一个字符cw替换一个单词cw替换一个单词cc替换一行cc替换一行C替换从光标至行尾C替换从光标至行尾Changing Textyw拷贝词拷贝词yy拷贝行(或拷贝行(或Y)p当前行下粘贴当前行下粘贴:1,2co3拷贝
30、行1,行2在行3之后拷贝行1,行2在行3之后:4,5m6移动行4,行5在行6之后移动行4,行5在行6之后Copying and Pasting Text:w存盘存盘:w newfile存成新文件存成新文件:wq 存盘退出Vi(或ZZ,或:x)存盘退出Vi(或ZZ,或:x):q!强行退出不存盘强行退出不存盘Saving and Quitting Files改变大小写改变大小写J把当前行和下一行连起来J把当前行和下一行连起来u废除刚才的编辑操作(undo)u废除刚才的编辑操作(undo):set nu 显示行代码(:set nonu):set nu 显示行代码(:set nonu):21光标停在指
31、定行:21光标停在指定行21G光标停在指定行(G 到文件尾,1G 到文件头)21G光标停在指定行(G 到文件尾,1G 到文件头)/串从当前行往下查找/串从当前行往下查找?串从当前行往上查找?串从当前行往上查找n查找继续n查找继续:r file2 在光标所在位置插入另一个文件:r file2 在光标所在位置插入另一个文件:1,$s/旧串/新串/g替换全文(或:%s/旧串/新串/g):1,$s/旧串/新串/g替换全文(或:%s/旧串/新串/g)Advanced Editing OptionsDisplays the user name corresponding to the effective
32、user IDid option(s)idid rootid a rootidDisplay a compact list of users logged inusersusersDisplays information about all users currently logged on to the local systemwhowThe who am i command displays information about your real user IDwho am iThe whoami command displays only the login name of the ef
33、fective userwhoamiFinding PeopleFind files based on specific criteria,then execute a command on the matching filesfind path expression actionfind/-name perl/精确查找精确查找find/-name“perl”/模糊查找模糊查找find.-mtime 10 print/按修改时间查找按修改时间查找find/etc-user 0 size+400 print /按用户属主和大小查找按用户属主和大小查找find -perm 777 /holes/按
34、权限查找按权限查找findSearches a file for a specified text string and prints all lines that contain that pattern to the screen case sensitivegrep option(s)string filename-i Ignore case of string when searching-v Search for all lines that do not match stringgrep root /etc/passwdls-la|grep-i sep 1ls file*|xarg
35、s grep dd 在文件内容进行查找在文件内容进行查找greplist the processes currently running on the system/usr/bin/ps-options-e List every process now running-f Generates a full listing-U uidlistProcesses whose real UID or login names are givenps ef|grep telnet/usr/ucb/ps-auwxprstatpsTerminate unwanted command processes th
36、at you cannot quit in the normal waykill-signal process-idkill 12932kill-9 12418sleep 1001&pkill sleepkill Ability to execute several jobs simultaneouslyCommand ValuejobsDisplay which jobs are currently runningfg%nPlace a job in the foregroundbg%n Place a job in the backgroundstop%nSuspend a backgro
37、und jobkill%nAbort the specified background jobControl-cAbort the foreground jobControl-zSuspend the foreground job./usr/openwin/bin/admintool&Job ControlNetwork Basicsping s host2ifconfig anetstat rnrusers-l tarenalab3traceroute Important Files and UtilitiesScript 1:1.vi/tmp/a.txt#!/bin/shpwdcaldat
38、e2.chmod a+x/tmp/a.txtShell Scriptingcrontab lcrontab esetenv EDITOR vicrontab r0 2*/tmp/a.txt13 5 13*5/tmp/b.txt0,30 8-17*1-5/tmp/c.txt*/tmp/d.txtSetup Initialization FilesThe SunOS 5.x system software provides several default environment variables whose values can be customizedTemporarily change t
39、he environment variables at the command line,affecting only the current shellPermanently changes it by modifying the initialization filesEnvironment VariablesInitialization files contain commands and variable settings thatare executed when a shell is startedTwo levels:System-wide Reside in the/etc d
40、irectory User-specific Reside in a users home directoryShell System-Wide User-Specific(Read First)(Read Second)Bourne /etc/profile$HOME/.profileC /etc/.login$HOME/.login$HOME/.cshrc$HOME/.logoutFeatures of Initialization FileskshInvoking Korn ShellshInvoking Bourne ShellcshInvoking C ShellbashInvoki
41、ng Bourne-again ShellShell Switchessetenv variable valuesetenv OPENWINHOME/usr/openwinEnvironment Variables%echo$PATH%setenv WTO uname-n%echo$WTO%echo“$WTO”%echo$WTO%echo$WTOQuoting in Shellsset path=(.)set path=($path pathname.)which Displays the pathname leading to an accessible command based on y
42、our search path which viwhereis Displays all directories where desired command is located,including appropriate man page/usr/ucb/whereis viPathDisplays previously entered commands typed in the C shell to the screenset history=30%history%history 5%!n%!HistorySubstitute a short command for a long oneCreate a single command for a series of commandsCreate alternate forms of existing commandsChange a command setalias alias-name value%alias h history%alias c clear%alias home cd;ls%alias ls ls-l%alias copy cp-i%alias%unalias copyAliasesset prompt=valueset prompt=hostname:$cwd%Custom Prompts