Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống
1
/ 68 trang
THÔNG TIN TÀI LIỆU
Thông tin cơ bản
Định dạng
Số trang
68
Dung lượng
347,89 KB
Nội dung
5 5-38 Fundamentals of Solaris 7 Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D Exercise: Accessing Files and Directories Exercise Solutions Use Figure 5-3 on page 5-32 to identify the pathnames for the following objects: 1. Specify the absolute pathnames for: ▼ user2 /home/user2 ▼ coffees /home/user2/dir1/coffees ▼ dir4 /home/user2/dir4 Assume /home/user2 is the current directory for the next two questions. 2. Specify the relative pathnames for: ▼ dir3 dir3 ▼ flowers dir4/flowers ▼ recipes dir2/recipes 3. Specify the relative pathnames for the dir1 subdirectories and files. dir1/coffees; dir1/coffees/nuts; dir1/coffees/beans dir1/fruit; dir1/trees 5 Accessing Files and Directories 5-39 Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D Exercise: Accessing Files and Directories Exercise Solutions Using Figure 5-3 on page 5-32 as reference, perform each of the following tasks on your system. Use pathname abbreviations whenever possible. 4. Change to your home directory (~). cd or cd ~ 5. Change to the dir1 directory. cd dir1 6. Change to the fruit directory. cd fruit or cd ~/dir1/fruit 7. Change to the planets directory. cd ~/dir3/planets or cd / /dir3/planets 8. Go back to your home directory (~). cd or cd ~ 9. Change to the /etc directory. cd /etc 10. Change to the recipes directory. cd ~/dir2/recipes or cd /home/user2/dir2/recipes 11. Change to the flowers directory. cd / /dir4/flowers or cd ~/dir4/flowers 5 5-40 Fundamentals of Solaris 7 Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D Exercise: Accessing Files and Directories Exercise Solutions Use the ls and cd commands to complete the following steps. Refer to Figure 5-3 on page 5-32 for the first six steps as needed. 12. Return to your home directory. cd or cd ~ 13. Change to the dir1 directory. cd dir1 14. List the contents of the dir1 directory. ls 15. Display a recursive listing of the contents of the dir2 directory. ls -R /dir2 or ls -R ~/dir2 16. Use the ls command to display a detailed listing of your home directory, including hidden files. ls -la ~ 17. Use the ls option that will recursively display all subdirectories in your home directory. ls -R ~ Is there a directory in the root directory (/) called kernel? Yes ; ls -F / or ls -ld /kernel Is there a directory in /var/spool called cron? Yes ; ls -F /var/spool 18. Without changing directories, type the ls command that will display any file names that end with the number 1 in your home directory. ls ~/*1 5 Accessing Files and Directories 5-41 Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D Exercise: Accessing Files and Directories Exercise Solutions (Continued) 19. On one command line, change to your home directory and list the contents of the directory. cd;ls 20. Issue an ls command that will display file and directory names of any length beginning with the letters “d” or ”f”. ls [df]* 21. Issue an ls command that will display all files starting with file followed by any one character. ls file? 5 5-42 Fundamentals of Solaris 7 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: ❑ Contrast absolute and relative pathnames ❑ Access files and directories within the file structure using absolute and relative pathnames ❑ Identify and describe the parts of a command line ❑ Access files and directories within the file structure using pathname abbreviations ❑ List the contents of directories and their file types ❑ Identify various metacharacters ❑ Enter more than one command on a single command line ❑ Demonstrate the use of wildcard characters 5 Accessing Files and Directories 5-43 Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D Think Beyond In your own work environment, what subdirectory structure would be useful for your home directory? What kinds of files do you work with most often? [...]... 6-16 Counts lines Counts characters Fundamentals of Solaris 7 Copyright 1999 Sun Microsystems, Inc All Rights Reserved Enterprise Services August 1999, Revision D 6 Displaying Files Using the wc Command Using wc Without Options $ wc dante 33 223 1320 dante Using wc without options will give a line, word, and byte count of the contents of the file Determining the Number of Lines in a File $ wc -l dante... ^D phone_list.txt O - 808-555-9 876 O - 808-555-9 876 P - 808-555-6 543 P - 808-555-6 543 When the first line is entered, the system searches for a file named phone_list.txt If the file exists, the system overwrites its contents with the new information If the file does not exist, it is created and the content is written into it 6-26 Fundamentals of Solaris 7 Copyright 1999 Sun Microsystems, Inc All Rights... Files Using the diff Command Options -i Ignores the case of letters; for example, A is equal to a -c Produces a listing of differences with three lines of context With this option, output format is modified slightly: output begins with identification of the files involved and their creation dates Following a line of a dozen *s, the line numbers of file1 that are to be displayed are listed The actual lines... head [ -n ] filename(s) 6-12 Fundamentals of Solaris 7 Copyright 1999 Sun Microsystems, Inc All Rights Reserved Enterprise Services August 1999, Revision D 6 Displaying Files Using the head Command Displaying a Specific Number of Lines at the Beginning of a File $ head -6 /usr/dict/words 10th 1st 2nd 3rd 4th 5th $ In this example, the head -6 command displays the first six lines of the /usr/dict/words file... there are no rules against it Note – To help distinguish between files and directories, some site administrators prefer their users to start filenames with lowercase letters and directory names with capital letters 6- 24 Fundamentals of Solaris 7 Copyright 1999 Sun Microsystems, Inc All Rights Reserved Enterprise Services August 1999, Revision D 6 Creating Files You can create new, empty files using the touch... 6-13 Copyright 1999 Sun Microsystems, Inc All Rights Reserved Enterprise Services August 1999, Revision D 6 Displaying Files Using the tail Command Use the tail command to display the last n lines of a file The last 10 lines are displayed by default if the -n option is omitted Command Format tail [ -n ] filename(s) tail [ +n ] filename(s) 6- 14 Fundamentals of Solaris 7 Copyright 1999 Sun Microsystems,... Copyright 1999 Sun Microsystems, Inc All Rights Reserved Enterprise Services August 1999, Revision D 6 Comparing Files Using the diff Command Another command used for finding differences between files is the diff command The output of this command will display line-by-line differences between two text files Command Format $ diff [option] file1 file2 6-20 Fundamentals of Solaris 7 Copyright 1999 Sun Microsystems,... Control-c Interrupts current activity Control-d Indicates end -of- file or exit Control-u Erases the command line Control-w 6 -4 Stops screen output Control-q Purpose Erases the last word on the line The actual character in the shell appears as ^C, even though you press the Control key and the c key at the same time Fundamentals of Solaris 7 Copyright 1999 Sun Microsystems, Inc All Rights Reserved Enterprise... pomegranate $ cat fruit2 lemon orange apple banana tomato guava mango pomegranate 6-22 1998 1998 Fundamentals of Solaris 7 Copyright 1999 Sun Microsystems, Inc All Rights Reserved Enterprise Services August 1999, Revision D 6 File and Directory Naming Conventions These include: q File names are made up of a maximum of 255 alphanumeric characters q Some non-alphanumeric characters, such as underscores (_),... length The cat command is more often used to join two or more files into one large file Command Format cat filename(s) 6-8 Fundamentals of Solaris 7 Copyright 1999 Sun Microsystems, Inc All Rights Reserved Enterprise Services August 1999, Revision D 6 Displaying Files Using the cat Command Using the cat Command to Display a Short Text File $ cat dante The Life and Times of Dante by Dante Pocai Mention . /home/user2/dir2/recipes 11. Change to the flowers directory. cd / /dir4/flowers or cd ~/dir4/flowers 5 5 -40 Fundamentals of Solaris 7 Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services. ls command that will display all files starting with file followed by any one character. ls file? 5 5 -42 Fundamentals of Solaris 7 Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise. command to another using a pipe ● Use the tee command within a pipeline to create text within a file 6 6-2 Fundamentals of Solaris 7 Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise