Sun Fundamentals of Solaris 7 EU-118 Student Guide With Instructor Notes phần 6 pps

62 333 0
Sun Fundamentals of Solaris 7 EU-118 Student Guide With Instructor Notes phần 6 pps

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

6 Exercise: Using Directory and File Commands Tasks 12 Change to your home directory and with one command, create a directory called house with a subdirectory of furniture in your home directory 13 Create an empty file called chairs in the new directory furniture 14 Using one command, create three directories called letters, memos, and misc in your home directory 15 Using one command, delete the directories called memos and misc in your home directory 16 Try to delete the directory called house/furniture with the rm (no options) command What happens? 17 Identify the command to delete a directory that is not empty Delete the directory house/furniture List the contents of house to verify that furniture has been deleted 18 From your home directory, redirect the output of the ls command to a file called file.list 19 Display the contents of file.list using the cat command 20 Append the output of the date command to file.list 21 Display a calendar and using the tee command, append the output to file.list 22 Use the tee command to create a file with the names of five of the students in the class in it Examine the contents of your class list with the cat command 6-50 Fundamentals of Solaris Copyright 1999 Sun Microsystems, Inc All Rights Reserved Enterprise Services August 1999, Revision D Exercise: Using Directory and File Commands Workshop Labs Use what you have learned so far in this course to work through the following: What shell has the system administrator set up for you? Create a directory in which to place all of your personal executable files and place a copy of any executable file that currently exists in your home directory into this new directory While performing a keyword search on shell you find many commands that you want to learn more about in your spare time Since your time is valuable you would like to save a listing of the commands revealed by the search in a file and refer to it when you have a free moment Place this file in your home directory to be used for reference later Directory and File Commands 6-51 Copyright 1999 Sun Microsystems, Inc All Rights Reserved Enterprise Services August 1999, Revision D Exercise: Using Directory and File Commands Exercise Summary Discussion – Take a few minutes to discuss what experiences, issues, or discoveries you had during the lab exercises  Manage the discussion here based on the time allowed for this module, which was given in the “About This Course” module If you find you not have time to spend on discussion, then just highlight the key concepts students should have learned from the lab exercise q  Ask students what their overall experiences with this exercise have been You might want to go over any trouble spots or especially confusing areas at this time q  6-52 Conclusions Have students articulate any conclusions they reached as a result of this exercise experience q  Interpretations Ask students to interpret what they observed during any aspects of this exercise q  Experiences Applications Explore with students how they might apply what they learned in this exercise to situations at their workplace Fundamentals of Solaris Copyright 1999 Sun Microsystems, Inc All Rights Reserved Enterprise Services August 1999, Revision D Exercise: Using Directory and File Commands Exercise Solutions Determine the file type of /etc/passwd and display the contents of the file file /etc/passwd cat /etc/passwd Display the contents of the file /usr/dict/words one screen at a time Exit after displaying two screens more /usr/dict/words To exit, type q or Control-c What command would you most likely use to read the contents of /usr/bin/cp ? strings /usr/bin/cp Return to your home directory (if you need to) and list the contents cd; ls Copy the dir1/coffees/beans file into the dir4 directory and call it roses cp dir1/coffees/beans dir4/roses Create a directory called vegetables in dir3 mkdir dir3/vegetables Move the dir1/coffees/beans file into the dir2/recipes directory mv dir1/coffees/beans dir2/recipes Copy dir3/planets/mars to the practice directory and name the file addresses cp dir3/planets/mars practice/addresses Directory and File Commands 6-53 Copyright 1999 Sun Microsystems, Inc All Rights Reserved Enterprise Services August 1999, Revision D Exercise: Directory and File Commands Exercise Solutions Create a directory called play in your practice directory and move the practice/addresses file to that play directory mkdir practice/play mv practice/addresses practice/play 10 Copy the play directory in the practice directory to a new directory in the practice directory called appointments cp -r practice/play practice/appointments 11 Recursively list the contents of the practice directory ls -R practice 12 Change to your home directory and with one command, create a directory called house with a subdirectory of furniture in your home directory cd; mkdir -p house/furniture 13 Create an empty file called chairs in the new directory furniture touch house/furniture/chairs 14 Using one command, create three directories called letters, memos, and misc in your home directory mkdir letters memos misc 15 Using one command, delete the directories called memos and misc in your home directory rmdir memos misc 16 Try to delete the directory called house/furniture with the rm (no options) command What happens? rm house/furniture rm: house/furniture is a directory 6-54 Fundamentals of Solaris Copyright 1999 Sun Microsystems, Inc All Rights Reserved Enterprise Services August 1999, Revision D Exercise: Directory and File Commands Exercise Solutions 17 Identify the command to delete a directory that is not empty Delete the directory house/furniture List the contents of house to verify that furniture has been deleted rm -r house/furniture; ls house 18 From your home directory, redirect the output of the ls command to a file called file.list ls > file.list 19 Display the contents of file.list using the cat command cat file.list 20 Append the output of the date command to file.list date >> file.list 21 Display a calendar and using the tee command, append the output to file.list cal | tee -a file.list 22 Use the tee command to create a file with the names of five of the students in the class in it Examine the contents of your class list with the cat command $ tee classlist name1 name1 name2 name2 name3 name3 name4 name4 name5 name5 ctrl-d $ cat classlist Directory and File Commands 6-55 Copyright 1999 Sun Microsystems, Inc All Rights Reserved Enterprise Services August 1999, Revision D Check Your Progress Before continuing on to the next module, check that you are able to accomplish or answer the following: u u Determine a file’s type with the file command u Display the contents of text files using the cat, more, head, and tail commands u Determine word, line, and character count using the wc command u Compare the contents of text files using diff and cmp u Create empty files or update access time of existing files using the touch command u Create and remove directories using mkdir and rmdir u Manage files and directories using the mv, cp, and rm commands u Save the output from a command into a file u Pass output from one command to another using a pipe u 6-56 Control screen output using control characters Use the tee command within a pipeline to create text within a file Fundamentals of Solaris Copyright 1999 Sun Microsystems, Inc All Rights Reserved Enterprise Services August 1999, Revision D Think Beyond Why is rm -r * such a dangerous command? What might you to prevent use of this command? Directory and File Commands 6-57 Copyright 1999 Sun Microsystems, Inc All Rights Reserved Enterprise Services August 1999, Revision D Managing Files With File Manager Objectives Upon completion of this module, you should be able to: q Describe the basic concepts of the File Manager q Demonstrate the drag-and-drop capability of File Manager q Create and remove folders q Execute actions from the File Manager’s menu options q Move a file or a folder onto the workspace backdrop q Find a file using File Manager’s Locate facility q Customize the manner in which file and folder information is displayed in the File Manager window 7-1 Copyright 1999 Sun Microsystems, Inc All Rights Reserved Enterprise Services August 1999, Revision D Permissions Default Permissions When a user accesses the system, files and directories are protected by default permissions These are put in place automatically when a file or directory is created $ mkdir secure; touch pluto $ ls -l drwxr-xr-x user2 staff -rw-r r user2 staff File Security 512 May 24 May 24 17:25 secure 17:25 pluto 8-11 Copyright 1999 Sun Microsystems, Inc All Rights Reserved Enterprise Services August 1999, Revision D Permissions Types of Permissions Every file or directory has a set of permissions that determines who can what with it Permissions are represented by characters that control who may read, write, and execute the contents of a file or directory 8-12 Fundamentals of Solaris Copyright 1999 Sun Microsystems, Inc All Rights Reserved Enterprise Services August 1999, Revision D Permissions Types of Permissions Table 8-1 Permissions and Corresponding Symbols Read Permission Symbol r Write w Execute x Permission Plain File Directory File can be displayed or copied File contents can be modified Contents can be listed with the ls command.a Files can be added or deleted.b Access to the directory is controlled.c File can be executed (shell scripts or executables only) a To display a long listing (ls -l), you must also have execute (access) permission on the directory b To add or delete files, you must have execute permission on the directory c To copy a file from a directory, you must have execute permission on the directory To use the mv command to place a new file in a directory or move a file from a directory, you must also have execute permission on the directory You must also have read permission on the file itself for either of these actions to be performed Note – As can be seen from Table 8-1, in order for a directory to be of any practical use, at least read and execute permissions must be set As seen from previous examples, you may see a dash (–) in place of r, w, or x This indicates no permission The following are samples of different types of permissions on files and directories: q The file is read/write/execute for owner only -rwx -q The directory is read/execute for owner and group dr-xr-x - File Security 8-13 Copyright 1999 Sun Microsystems, Inc All Rights Reserved Enterprise Services August 1999, Revision D Permissions Types of Permissions q The file is read/write/execute for owner, and read/execute for group members and others -rwxr-xr-x q The directory is read/write/execute for owner, read/execute for group, and execute for others drwxr-x x 8-14 Fundamentals of Solaris Copyright 1999 Sun Microsystems, Inc All Rights Reserved Enterprise Services August 1999, Revision D Changing Permissions Overview The chmod command is used by a file’s owner (or superuser) to change file permissions The two modes of operation with the chmod command are symbolic and octal q Symbolic mode uses combinations of letters and symbols to add or remove permissions from various categories of users q Octal mode uses octal numbers to represent file permissions Octal mode is also referred to as absolute or numeric mode File Security 8-15 Copyright 1999 Sun Microsystems, Inc All Rights Reserved Enterprise Services August 1999, Revision D Changing Permissions Symbolic Mode The command format for symbolic mode uses letters and symbols Command Format chmod mode filename who op permission(s) r Read w Write x Execute = Set permissions - Remove access + Give access u g o a 8-16 User or owner of the file Group to which the file belongs Others outside owner and group All of the above Fundamentals of Solaris Copyright 1999 Sun Microsystems, Inc All Rights Reserved Enterprise Services August 1999, Revision D Changing Permissions Symbolic Mode Changing Permissions With Symbolic Mode You can: q Remove group read permission $ ls -l dante -rw-r r user2 $ chmod g-r dante $ ls -l dante -rw r user2 q staff staff Jun 11 1:44 Jun 11 dante 1:44 dante Jun 11 1:44 dante Add execute permission for owner, and read permission for group and others $ chmod u+x,go+r dante $ ls -l dante -rwxr r user2 staff  Deny read permission to others $ chmod o-r dante $ ls -l dante -rw - user2 q staff Jun 11 1:44 dante There is no space after u+x and before go+r,although there is a comma between them q Set permissions to read and write for everyone $ chmod a=rw dante $ ls -l dante -rw-rw-rw- user2 File Security staff Jun 11 1:44 dante 8-17 Copyright 1999 Sun Microsystems, Inc All Rights Reserved Enterprise Services August 1999, Revision D Changing Permissions Octal (Absolute) Mode Octal mode is based on the base eight numbering system (0–7 are the available numerals) Command Format chmod octal_mode filename Each permission has an octal value as shown in Table 8-2 Table 8-2 Permissions for Each Octal Value Octal Value Read Write 8-18 Permissions Execute Fundamentals of Solaris Copyright 1999 Sun Microsystems, Inc All Rights Reserved Enterprise Services August 1999, Revision D Changing Permissions Octal (Absolute) Mode The octal values for the permission set are shown in Table 8-3 Table 8-3 Octal Values for Permission Sets Octal Value Permissions r w x r w - r - x r - - - w x - w - - - x - - - File Security 8-19 Copyright 1999 Sun Microsystems, Inc All Rights Reserved Enterprise Services August 1999, Revision D Changing Permissions Octal (Absolute) Mode Octal values are combined to identify the octal_mode that is used with the chmod command Table 8-4 Combined Values and Permissions Octal Value Permissions 644 rw-r r 751 rwxr-x x 775 rwxrwxr-x 777 rwxrwxrwx The first position defines the user (owner) permissions, the second position defines the group, and the last position defines others Default permissions on files are 644, and default permissions on directories are 755 Note – When using octal mode with the chmod command, you must list all three numbers, one for each category of user: user, group, and others 8-20 Fundamentals of Solaris Copyright 1999 Sun Microsystems, Inc All Rights Reserved Enterprise Services August 1999, Revision D Changing Permissions Octal (Absolute) Mode Changing Permission With Octal Mode You can: q Give user, group, and others read and execute access $ ls -l dante rw-rw-rw- user2 staff $ chmod 555 dante $ ls -l dante -r-xr-xr-x user2 staff q Jun 11 11:54 dante Change user and group permissions to include write access $ chmod 775 dante $ ls -l dante -rwxrwxr-x user2 staff q Jun 11 11:54 dante Jun 11 11:54 dante Change group permission to read and execute $ chmod 755 dante $ ls -l dante -rwxr-xr-x user2 staff File Security Jun 11 11:54 dante 8-21 Copyright 1999 Sun Microsystems, Inc All Rights Reserved Enterprise Services August 1999, Revision D Default Permissions The umask Filter The umask filter determines the default permissions for files and directories The permissions are assigned during the creation of new files and directories Displaying Your umask $ umask 022 The default permissions which will be assigned to a newly created file or directory are determined by the application of the umask filter against the maximum system assignable file (666) and directory (777) permissions Each digit in the umask value represents permission categories which are to be denied, or “masked out,”, from the maximum permissions  8-22 Depending up the shell, the umask value will display differently as either 0022, 022, or 22 Fundamentals of Solaris Copyright 1999 Sun Microsystems, Inc All Rights Reserved Enterprise Services August 1999, Revision D Default Permissions The umask Filter As an example, in the case of a newly created file, the maximum system assignable file permissions are represented by the octal value 666 This corresponds to read/write (42-) access for the user, read/write (42-) access for the group, and read/write (42-) access for all others This can be represented as: 42-42-42rw-rw-rwThe default umask filter value is octal 022, which corresponds to no access denial ( -) for the user, a denial of write (-2-) access for the group, and a denial of write (-2-) access for all others This can be represented as: 2 w wWhen the access categories to be denied are “masked out” from the maximum system assignable values, the default permissions which are assigned to a newly created file are left 42-42-42- Maximum system assignable file permissions 2- Default umask filter value 42-4 Default permissions assigned to a newly created file rw-r r-Note – Execute permissions can be placed on files by the user but are not assigned by the system when a file is created File Security 8-23 Copyright 1999 Sun Microsystems, Inc All Rights Reserved Enterprise Services August 1999, Revision D Default Permissions This same process can be applied when determining what the default permissions will be when creating new directories In this case, the maximum system assignable permissions are represented by the octal value 777 This corresponds to read/write/execute access for the user, group, and others 421421421 Maximum system assignable directory permissions rwxrwxrwx 2 w w4214-14-1 rwxr-xr-x Default umask filter value Default permissions assigned to a newly created directory Another way to look at the meaning of the umask value is to subtract each digit of the umask from the maximum assignable file and directory permissions to determine the octal value of the permissions assigned to newly created files and directories 666 022 644 777 022 755 8-24 Maximum system assignable file permissions umask value Octal value of permissions assigned to a newly created file Maximum system assignable directory permissions umask value Octal value of permissions assigned to a newly created directory Fundamentals of Solaris Copyright 1999 Sun Microsystems, Inc All Rights Reserved Enterprise Services August 1999, Revision D Default Permissions The umask Filter The umask value is set in the kernel but an alternate value can be placed in /etc/profile by the system administrator Users can set their own umask value A more secure umask than the default (022) would be 027, which gives no permissions to others Table 8-5 umask Settings umask Setting File Directory 022 Gives read and write permission to the owner of the new file and read permission to group and others Gives all permissions to the owner and read and execute permissions to group and others 027 Gives read and write permission to the owner of a new file, read permission to group, and no permissions to others Gives all permissions to the owner, read and execute permissions to group, and no permissions to others File Security 8-25 Copyright 1999 Sun Microsystems, Inc All Rights Reserved Enterprise Services August 1999, Revision D ... ls -l profile -rw-r r user2 staff 560 Jun 11 11:23 profile -rw-r r-File type User Group Others Figure 8-1 8 -6 Permissions for Each Class of User Fundamentals of Solaris Copyright 1999 Sun Microsystems,... Files With File Manager 7- 9 Copyright 1999 Sun Microsystems, Inc All Rights Reserved Enterprise Services August 1999, Revision D Creating a New Folder 7- 10 Fundamentals of Solaris Copyright 1999 Sun. .. you start at the root of the file system (the / directory), the Find operation may take a considerable amount of time to complete 7- 16 Fundamentals of Solaris Copyright 1999 Sun Microsystems, Inc

Ngày đăng: 24/07/2014, 02:20

Từ khóa liên quan

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan