(精品)Unix5(en).ppt

上传人:hyn****60 文档编号:70976403 上传时间:2023-01-31 格式:PPT 页数:51 大小:1.18MB
返回 下载 相关 举报
(精品)Unix5(en).ppt_第1页
第1页 / 共51页
(精品)Unix5(en).ppt_第2页
第2页 / 共51页
点击查看更多>>
资源描述

《(精品)Unix5(en).ppt》由会员分享,可在线阅读,更多相关《(精品)Unix5(en).ppt(51页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。

1、Chaper 5-Intro to UNIX File SystemlFiles are the basic system used by UNIX to store&organize your informationlUNIX divides the system into smaller units of storageDirectoriesSub-Directories(nested under directories)lThis sets up the basic file system used by UNIX(and most other OS)1File TypeslA file

2、 is a sequence of byteslUNIX has three categories of files:Regular Files-code,text,data,etc.Directory Files-info about other filesSpecial Files-info for I/O and peripherals*l*UNIX treats I/O devices as files,so each system device has a file2DirectorieslA simple system of organizing files on your UNI

3、X disklUNIX organizes directories in levels“Hierarchical”structureThe top directory is called rootAll other directories branch from rootlDirectories dont contain your files,they provide a reference path for the fileslSee Figure 5.1(as following slide)3Figure 5-1Figure 5-1 Directory Structure Directo

4、ry Structure4Parent&ChildlThe levels in the hierarchy are described using a parent/child relationshipParent is above the child in the hierarchyA parent may be the child of another directoryOnly the root directory has no parent directoryAll directories trace back to rootSee Figure 5.2(as following sl

5、ides).5Figure 5-2Figure 5-2 Parent and Child Relationship Parent and Child Relationship6Important Directoriesl/Root directoryl/usrHolds many other user-oriented directoriesl/usr/docs,/usr/man,/usr/bin.In UNIX also hold users home directories,but linux dont.l/binBasic UNIX program filesl/devHolds dev

6、ice filesl/sbinHolds system files that usually are are automatically by the UNIX system.l/etcHolds UINX configuration files7The Home DirectorylA particular directory associated with user accountlWhen log on,you are placed automatically into your home directory.lYou can create files and subdirectorie

7、s under it.lUsually has the same name as your accountlOther user cant access it.lSee Figure 5.3(as following slide)8Figure 5-3Figure 5-3 Directories,Subdirectories,and Files Directories,Subdirectories,and Files9Working DirectorylThe working directory is the directory you are currently working in lAc

8、cessing files in another directory requires that you Make that directory the working directoryORReference that directory when accessing the files in that directory(examples will be shown later)10Paths&PathnameslPathname a reference to a files directory within the file systemThe pathname traces a pat

9、h for the file from the root directory downlA path ends with a fileOrdinary file ORDirectory file,which can have another branch of directories underneathlSee Figure 5.4(as following slide)11Figure 5-4Figure 5-4 Pathnames in a Directory Structure Pathnames in a Directory Structure12PathnameslAbsolute

10、 PathnamePath from root (/)downward/usr/local/stuff/file.txtlRelative PathnamePath from working directorystuff/file.txt which is only valid if the working directory happens to be/usr/local13Filenames&Directory NameslSection 5.3.5 covers the rules for naming files in UNIX(p90)These apply to any versi

11、on of UNIX,including FreeBSD&LINUXRemember,UNIX names are case sensitivelfile.txt,File.Txt&FILE.TXT are differentSince UNIX names can be very long,use them to describe the file/directory contentsNO SPACES!EVER!WE MEAN IT!14ExtensionslExtensions further help to organize filenamesDifferent types of fi

12、les have different extensions(.txt for text,.c for C,)Multiple extensions can be usedfile.has.more.txt15Directory CommandslSo how do you navigate directories in UNIX?The shell has specific commandsTo try these out,login to your systemSee Figure 5-5 for an example file system(as the following slide)1

13、6Figure 5-5Figure 5-5 An Example of a Directory Structure An Example of a Directory Structure17Where Am I?lpwd-print working directoryshows absolute pathnote:in most UNIX systems,the working directory you login to usually has the same name as your usernamethis doesnt show the files in the directory,

14、just the absolute path$pwd Return.Display your HOME directory path./usr/david$_.Prompt for next command.18Where Am I Going?lcd-change directorycd source goes to the directory named source which is a child of the current directorycd/usr/david goes to the directory named david,which is a child of usr,

15、which is a subdirectory of rootcd goes to the users home directorySee examples as the following two slides19Example 1$pwd Return.Check your current directory./usr/david$cd source Return.Change to source directory.$pwd Return.Display your working directory./usr/david/source$_.Prompt for the next comm

16、and.20Example 2Assuming you have permission,you can change your working directory to/devby using the following command sequence:$cd/dev Return.Change to/dev directory.$pwd Return.Check your working directory./dev.Your current directory is/dev.$_.Prompt for next command.21I Need A Directory!lLets mak

17、e a directory A fresh UNIX account has no subdirectories in the users home directoryDirectories are useful for grouping filesSome planning makes it easier to organize and handle your files in the long runlUse the mkdir command to make a new directory22mkdirlmkdir memos make the memos directory,a chi

18、ld of the current working directorylmkdir/usr/david/text make a directory under/usr/david named textlmkdir memos/old make a directory under memos named old,assuming memos is a child of the current working directorylmkdir-p xx/yy/zz make a the entire path specified(assumes they dont exist)lSee the fo

19、llowing slides23Figure 5-6Figure 5-6 Your Directory Structure at the Beginning Your Directory Structure at the BeginningDirectory StructureLets start with the directory structure presented in Figure 5.6.Depending on your system configuration and administration requirements,you might have other files

20、 or subdirectories in your HOME directory.245.4.4 Directory Creation:The mkdir CommandThe mkdir(make directory)command creates a new subdirectory under your workingdirectory or any other directory you specify as part of the command.Create a directory called memos under your HOME directory:$cd Return

21、.Make sure you are in your HOME directory.$mkdir memos Return.Create a directory called memos.$pwd Return.Check your working directory./usr/david$cd memos Return.Change to memos directory.$pwd Return.Check your working directory./usr/david/memos.Your current directory is memos.$_.Prompt for next com

22、mand.25Figure 5-7Figure 5-7 Your Directory Structure After Adding the memos Subdirectories Your Directory Structure After Adding the memos SubdirectoriesBeforeAfter26While you are in your HOME directory,create a new subdirectory called important inthe memos directory.$cd Return.Make sure you are in

23、your HOME directory.$mkdir memos/important Return.Specify the important directory pathname.$cd memos/important Return.Change to important directory.$pwd Return.Check your working directory./usr/david/memos/important$_.Now your working directory is important.Figure 5.8 shows your directory structure

24、after adding memos and important subdirectories.27Figure 5-8Figure 5-8 Your Directory Structure After Adding the memos and important Subdirectories Your Directory Structure After Adding the memos and important Subdirectories28Figure 5-9Figure 5-9 Creating the source Directory Creating the source Dir

25、ectoryFigure 5.9 shows how to create a directory called source under your HOME directory.Figure 5.10 shows your directory structure after adding the source subdirectory.A directory structure can be created according to your specific needs.4429Figure 5-10Figure 5-10 Your Directory Structure After Add

26、ing the source Directory Your Directory Structure After Adding the source DirectoryBeforeAfter30The mkdir Command:-p Option The-p option creates levels of directories under your current directory.Create a directory structure three levels deep,starting in the HOME directory:$cd Return.Make sure you a

27、re in your HOME directory.$mkdir-p xx/yy/zz Return.Create a directory called xx;in xx create a directory called yy,and in yy create a directory called zz.$_.Ready for next command.Figure 5.11 depicts the directory structure after this command sequence has beenapplied.-parents Option The alternative

28、option in Linux.Like the-p option,-parents creates levels of directories under your current or the specified directory.The command line for using the-parents is:$mkdir-parents xx/yy/zz Return.Create a directory called xx;in xx,create a directory called yy;and in yy,create a directory called zz.31Fig

29、ure 5-11Figure 5-11 Your Directory Structure After Adding the Three-Levels Deep Subdirectories Your Directory Structure After Adding the Three-Levels Deep SubdirectoriesBeforeAfter32I Dont Want It Anymore!lrmdir remove directorylBut,there are conditions must be in a parent directorycannot remove a d

30、irectory unless it is empty(no files)lrmdir will return an error if the directory does not exist,or if it isnt emptylSee examples as the following two slides33Example 1Remove the important directory from your memos directory:$cd Return.Make sure you are in your HOME directory.$cd memos Return.Change

31、 your working directory to memos.$pwd Return.Make sure you are in memos./usr/david/memos$_.Yes,you are in memos.$rmdir important Return.Remove the important directory.$_.Ready for next command.1.You were able to remove the important subdirectory because it was an empty directory.2.You must be in a p

32、arent directory to remove a subdirectory.4434Example 2From the david directory,remove the source subdirectory:$cd Return.Change to david directory.$rmdir source Return.Remove the source directory.rmdir:source:Directory not empty$rmdir xyz Return.Remove a directory called xyz.rmdir:xyz:Directory does

33、 not exist$_.Ready for next command.1.You could not remove the source subdirectory because it was not anempty directory.2.rmdir returns an error message if you give a wrong directory nameor if it cannot locate the directory name in the specified pathname.3.You must be in the parent directory or a hi

34、gher level of directoryto remove subdirectories(children).4435Whats In Here?lls list contents of directorylists files in current directory by name,in alphabetical order(files&directories)ls code lists contents of the child directory code,or any files named code in the current working directoryls has

35、 numerous options(see Table 5-1,as the following slides)lmake sure there is a space between the command name and the optionSee examples as the following slides 36Assuming your current directory is david,show the contents of your HOME directory by typing ls Return.$ls123Draft_1REPORTmemosmyfirstphone

36、ssourcexx$_37In some systems,the output of the ls command is not vertical in one column and the default format is set to display filenames across the screen.$ls123 Draft_1 REPORT memos myfirst phones source xx$_38You may want to list the contents of directories other than your current directory.Whil

37、e in your HOME directory david,list files in the source directory:$cd Return.Make sure you are in the david directory.$ls source Return.While in david,display list of files in the source directory.first.cfirst.cpp$_.Ready for next command.While in your HOME directory,check whether first.c exists in

38、the source directory:$ls source/first.c Return.Display the first.c filename in the source directory to see whether it exists.It does exist,so the file-name is displayed.source first.c$ls xyz Return.Display a file called xyz if it exists.If it does not exist,you get the error message.xyz:No such file

39、 or directory$_.You get the prompt sign again.39Table 5.1 The ls Command Optionsls OptionsWhen you need more information about your files or you want the listing in a different Format,use the ls command with options.40The wonders of lslls-l long formatlls-a show hidden fileslls-F designate directori

40、es using/and executable files using*41File PermissionslAs a multi-user operating system,UNIX must setup a way to restrict access to files based on user preferenceslEvery file has an attribute,or permissionRead permission(r)Write permission(w)Executable permission(x)lPermissions are set for owners,gr

41、oups and the world(everybody)lSee the following slides42Figure 5-13Figure 5-13 The The ls ls Command and the-l Option Command and the-l Option43Figure 5-14Figure 5-14 The The lsls Command-Long Format Command-Long FormatFile type-Ordinary filed directory fileb block-oriented special(device)file,such

42、as diskc character-oriented special(device)file,such as printerl a link to another file44More about fileslUNIX has utilities to set permissionschmod we will cover this laterlNote that every file has a modification date,owner(user name),group and sizethese are only seen in long(-l)formatlWhat about h

43、idden files?These start with a period(.)What do they do well hit that in Chapter 745Whats In My File?lcat displays file on screenTheres no scrolling or movement control,so cat just lets the ASCII fly!lWell,and will stop/start scrolling on some terminals,but its not an exact scienceHow to avoid this

44、well use more later$cat myfirst Return.Display the myfirst file.$cat myfirst yourfirst Return.Display the myfirst and yourfirst files.46Putting Bits On Paperllp line printersends files to the printer,if your system has one installed(Section 5.6.2,p113)lnot your local PCs printer,but the network prin

45、ter attached to the UNIX serverlp fred.txt send fred.txt to the printerlpstat print status(queue)lpstat-d name of default printercancel lp1 kill jobs on printer lp1llpr printing command in Linux47Cleaning Out The Fileslrm remove(delete)filesrm text.txt delete the file text.txtrm fred.txt iso9000.txt

46、 delete the files fred.txt and iso9000.txtlrm will give an error if a specified file isnt thereby default,rm does not confirm a delete job48Remove group of files lWanna clean out a whole group of files in one pass use a wildcardrm*.txt delete all files with the extension.txtrm*delete all files in the working dirrm-r*remove all files in this directory or any subdirectories49Whoops!lBe very very,very careful using rmno confirmation&no recovery-i should be used often-r should be used rarelywildcards are very dangerous,yet extremely useful50HomeworklP120Review Exercises 57,951

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 生活休闲 > 生活常识

本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知淘文阁网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

工信部备案号:黑ICP备15003705号© 2020-2023 www.taowenge.com 淘文阁