Tải bản đầy đủ (.pdf) (62 trang)

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

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (416.23 KB, 62 trang )

6
6-50 Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
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
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
Workshop Labs
Use what you have learned so far in this course to work through the
following:
1. What shell has the system administrator set up for you?
2. 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.
3. 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.
6
6-52 Fundamentals of Solaris 7
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 do not have time to spend on
discussion, then just highlight the key concepts students should have learned from the
lab exercise.
● Experiences

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.
● Interpretations

Ask students to interpret what they observed during any aspects of this exercise.
● Conclusions

Have students articulate any conclusions they reached as a result of this exercise
experience.
● Applications

Explore with students how they might apply what they learned in this exercise to
situations at their workplace.
6
Directory and File Commands 6-53
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
Exercise: Using Directory and File Commands
Exercise Solutions
1. Determine the file type of /etc/passwd and display the contents
of the file.
file /etc/passwd
cat /etc/passwd
2. 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
3. What command would you most likely use to read the contents of
/usr/bin/cp ?
strings /usr/bin/cp
4. Return to your home directory (if you need to) and list the
contents.

cd; ls
5. Copy the dir1/coffees/beans file into the dir4 directory and
call it roses.
cp dir1/coffees/beans dir4/roses
6. Create a directory called vegetables in dir3.
mkdir dir3/vegetables
7. Move the dir1/coffees/beans file into the dir2/recipes
directory.
mv dir1/coffees/beans dir2/recipes
8. Copy dir3/planets/mars to the practice directory and name
the file addresses.
cp dir3/planets/mars practice/addresses
6
6-54 Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
Exercise: Directory and File Commands
Exercise Solutions
9. 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
Directory and File Commands 6-55
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
6
6-56 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:
❑ Control screen output using control characters
❑ Determine a file’s type with the file command
❑ Display the contents of text files using the cat, more, head, and
tail commands
❑ Determine word, line, and character count using the wc command
❑ Compare the contents of text files using diff and cmp

❑ Create empty files or update access time of existing files using the
touch command
❑ Create and remove directories using mkdir and rmdir
❑ Manage files and directories using the mv, cp, and rm commands
❑ Save the output from a command into a file
❑ Pass output from one command to another using a pipe
❑ Use the tee command within a pipeline to create text within a file
6
Directory and File Commands 6-57
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 do to
prevent use of this command?
7-1
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
ManagingFilesWithFileManager
7
Objectives
Upon completion of this module, you should be able to:
● Describe the basic concepts of the File Manager
● Demonstrate the drag-and-drop capability of File Manager
● Create and remove folders
● Execute actions from the File Manager’s menu options
● Move a file or a folder onto the workspace backdrop
● Find a file using File Manager’s Locate facility
● Customize the manner in which file and folder information is
displayed in the File Manager window
7
7-2 Fundamentals of Solaris 7

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
Relevance

Present the following question to stimulate the students and get them thinking about the
issues and topics presented in this module. While they are not expected to know the
answer to the question, the answer should be of interest to them and inspire them to learn
the content presented in this module.
Discussion – File manipulation is frequently done by using the
graphical user interface. What alternatives to using the command line
does working within the GUI provide?
7
Managing Files With File Manager 7-3
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
The File Manager
Front
Panel
File Manager
icon
File
Manager
window
display
File
Manager
icon
7
7-4 Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
The File Manager
The File Manager enables you to graphically organize files into a

hierarchical structure of folders and subfolders (directories).
Directories are displayed with folder icons. Files are displayed with
appropriate icons.
The File Manager, by default, opens a view of a folder which is the
current directory. From that folder, you can change to other folders,
both up and down in the hierarchy, to view each directory’s contents.
The path to the current folder is always displayed in the top area of
the File Manager window.
The path to the
current folder
The pathname of
the current folder
7
Managing Files With File Manager 7-5
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
File and Folder Icons
Audio file
Binary file
Core file
Graphic file
PostScript (text) file
Standard file
Folder icon
7
7-6 Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
File and Folder Icons
To help you identify files and directories more easily, the File Manager
displays differing icons depending on the content of the file.
The most common file icon you will see will be the standard file icon.

If a file is a data file associated with a particular application, that
application will be automatically started when you double-click on the
icon.
If you double-click on a folder icon, the File Manager moves you into
that directory and displays its contents. You can only move down
through the file system hierarchy in this way.
There is always a special icon displayed in the upper left corner of the
File Manager display.
Double-clicking on this (go up) icon will move you to the next level up
in the hierarchy.
7
Managing Files With File Manager 7-7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
Moving and Copying Files Using Drag-and-Drop
File is
selected
then
dragged
to the
appropriate
folder
icon
7
7-8 Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
Moving and Copying Files Using Drag-and-Drop
Select + Drag + Drop
To move a file from one folder to another, position the mouse pointer
over the file icon, hold down the left mouse button and drag the icon
to the appropriate folder icon.

Once the file icon is positioned over the folder icon, release the mouse
button and the file will be moved to that folder.
Control + Select + Drag + Drop
If you press the Control key before the file icon has been selected and
keep it held down while the drag-and-drop process takes place, the file
will be copied rather than just moved to the other folder.
Note – You cannot move or copy file icons to the path icon display in
the top part of the File Manager window display.
If you want to move or copy files to the parent directory of the current
folder, you can drag and drop the file icon to the (go up) icon.
7
Managing Files With File Manager 7-9
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
File Menu Options
The File Menu options enable you to perform the following tasks:
● Create a new folder (directory)
● Create a new file
● Change to your home directory (if your current folder is different
from your home folder)
● Go up one level of folder in the hierarchy
● Change to a specified directory
● Find files based on their name or content
● Open a Terminal window (in which to give UNIX commands)
Note – There are keyboard mnemonics which can be used as shortcuts
to the File menu options.
7
7-10 Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
Creating a New Folder
7

Managing Files With File Manager 7-11
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
Creating a New Folder
When the New Folder option is chosen, a separate window is
displayed. Type the name of the new directory.
Once the name has been applied, you have the choice of left clicking
either OK or Apply.
● Clicking OK adds the new folder with the name you just typed,
and closes the New Folder window.
● Clicking Apply adds the new folder, and keeps the New Folder
window on the screen display, ready for you to type in the name
of another new folder.
If you want to create several new directories, click Apply for all new
folder names except the last. When the last folder name has been
typed, click OK to remove the New Folder window.
Note – When you click Apply, the name is retained in the typing area
of the New Folder window. You must remove the previous folder
name using the Backspace key or the equivalent mouse action.
7
7-12 Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
Creating a New File
As with the New Folder option, a window will be displayed in which
you must type the name of the file to be created.
If you click OK, the file will be created, with the name you typed, and
the New File window will close.
However, if you click Apply, the file will be created and the New File
window will stay on the screen so you can create another new file. By
clicking Apply after each file name has been typed, you can add
several new files from the same New File window.

7
Managing Files With File Manager 7-13
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
Folder or File Name Conflicts
If you attempt to create a folder or file with the same name as an
existing folder or file, you will be notified by the File Manipulation
Error window.
Click OK, then type an alternative name for the folder or file which is
to be created.
7
7-14 Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
Changing Folders
The Go To option on the File Manager’s File menu enables you to
specify which folder to change to by specifying a path name.
Enter a valid pathname into the appropriate entry box, then click OK.
If there are any permission controls which prevent you from changing
to the specified folder, you will be notified with the following window
display:
7
Managing Files With File Manager 7-15
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
Finding Folders and Files
7
7-16 Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
Finding Folders and Files
The Find menu option enables you to search through the file system
hierarchy using search criteria. The criteria can be either the name of
the folder or file or, in the case of a file, the contents.

Wildcard characters can be used when specifying the name of the file
to find. For example:
a* Finds folder or file names which start with the letter “a”
*s Finds folder or file names which end with the letter “s”
??a Finds three-character folder or file names, where the last
character in the name is the letter “a”
[Aa]* Finds folder or file names which start with the letter “a”
(either uppercase or lowercase)
The search folder name is the starting point when searching the file
system hierarchy.
Note – If you start at the root of the file system (the / directory), the
Find operation may take a considerable amount of time to complete.

×