<<

. 8
( 69 .)



>>

CHANGE FILE PERMISSIONS
one set of users by combining these designators together,

Y
ou can change the permissions on files you own,
such as go, to indicate users in the file group and users not
allowing you to grant or withhold permission to
in the file group, while omitting the file owner.
others to read, write, or execute your files. There
are two parameters for the chmod command, the first being
You can mark permission changes with a plus symbol (+) to
the new mode, and the second being the file you want to
add permissions, a minus symbol (-) to remove them, or an
change. You specify the mode change by indicating who the
equal symbol (=) to set them. The possible permissions are
change affects, whether the change should be to add,
the same as those shown by the ls -l command: r for
remove, or set permissions, and what kind of permissions
read access, w for write access, and x for execute access.
you want to set.
You can make more than one change at a time to a given
Unix uses letters to designate the users that your mode
file by listing them with commas as separators. For example,
change affects: u, for the owner of the file, or user, g, for
to set the file example to be readable, writeable, and
users in the file group, o, for others ” users not in the
executable by you, readable and executable by those in the
group ” or a, for all users. You can designate more than
file group, and readable by those outside of the group, you
can type chmod u=rwx,g=rx,o=r example.



CHANGE FILE PERMISSIONS




– The shell indicates that
‹ Type the name of a file
REMOVE READ ACCESS ADD WRITE ACCESS
and press Return. anyone in the file group can
„ Type chmod and a space. „ Type chmod g+w and a change this file.
– The shell indicates that only space.
¤ Type og-r and a space. you can read the file.
¤ Type the name of a file
and press Return.


24
2
WORK WITH FILES




You can change the permissions TYPE THIS:
for an entire directory and its
[ferro:˜] user% chmod -R go-rx ˜
contents, including your Home
[ferro:˜] user% ls -l
directory, by using the -R option
with the chmod command. The
-R option dictates that modes
should be changed recursively, RESULTS:
which means that the changes
drwx------ 8 user staff 272 Nov 13 13:57 Desktop
apply to all files in that directory
drwx------ 12 user staff 408 Nov 13 02:00 Documents
or in its subdirectories. drwx------ 22 user staff 748 Nov 13 03:40 Library
drwx------ 3 user staff 102 Nov 4 13:49 Movies
For example, if you want to drwx------ 3 user staff 102 Nov 4 13:49 Music
make sure your Home directory drwx------ 3 user staff 102 Nov 4 13:49 Pictures
drwx------ 4 user staff 136 Nov 4 13:49 Public
is readable only by you and not drwx------ 5 user staff 170 Nov 4 13:49 Sites
by other users of your computer,
you use the chmod “R
command.




– The shell indicates the new
¤ Type the name of a file
SET EXECUTION PERMISSIONS SET CUSTOM PERMISSIONS
and press Return. permissions: the file is now
„ Type chmod a-x,u+x and a „ Type chmod a=r and a read-only by everyone.
– The shell indicates that only
space. space.
Note: You cannot alter this file
you can execute this file.
¤ Type the name of a file without changing the permissions
and press Return.
back.


25
UNIX FOR MAC



SELECT FILES USING WILDCARDS
A caret (^) at the start of a pattern or a range of characters

Y
ou can use wildcard characters to avoid having to
indicates that the pattern should select those characters
type out the full name of each file you want to work
that do not match the given pattern. For example, if you
with in Unix. This not only saves typing but also lets
want to use the ls -l command on all directories and
you refer to multiple files with similar names in a single
files that begin with the letter P, you can type ls -l P*. To
command.
remove all files beginning with A, followed by three letters,
and ending in .doc, from your Documents directory, you
Unix shell wildcards are also called glob-patterns, and the
can type rm -i Documents/A???.doc. You should always use
use of these wildcards is known as globbing in Unix jargon.
the -i option with the rm command if you give it wildcard
You can use these wildcards whenever you give a filename
arguments, to avoid deleting the wrong files. A careless rm
argument to a shell command.
* command in the wrong directory can remove the
The asterisk wildcard (*) matches any sequence of zero or contents of the directory.
more characters in a filename. The question mark (?) matches
Hidden files are resistant to being identified through
any single character. A range of characters in square brackets,
wildcards. The command ls *, for example, does not list
such as [a-m], matches any single character within that range.
them while ls .* lists only hidden files.
Keep in mind that letters in filenames are case-sensitive, so
while the letter d is a match for [a-m], the letter D is not,
because it does not come between lowercase a and m.

SELECT FILES USING WILDCARDS




– The shell executes your
¤ Type a wildcard pattern
MATCH A GLOB PATTERN USE CARETS TO SELECT
UNMATCHED FILES
that matches the files you command on the files in the
„ Type a command that
„ Type a command that
want to select. current directory, except for
takes a filename as an
those specified by the
takes a filename as an
– The shell executes your
argument.
wildcard pattern.
argument.
command on the files
¤ Type ^ followed by the
specified by the wildcard
pattern. wildcard pattern matching
the files you do not want to
select.
26
2
WORK WITH FILES



SELECT FILES USING COMPLETION
To see the results of an ambiguous match, you can press

Y
ou can easily specify filename arguments by using
Control + D after the beep. Alternatively, you can type set
command completion, which is a special function
autolist, which instructs your shell to list the remaining
built into the shell. To use filename completion, you
choice whenever file completion fails. This is a good
must type out the first part of the filename and then press
command to save in your .tcshrc file, which ensures that this
the Tab key. If there is a file that matches the incomplete
feature is set every time you start a Terminal window.
filename, the shell fills in the full filename for you.
Similarly, you can turn off autolist with unset autolist.
If no file matches the filename, your shell program emits a
You can combine filename completion with full or relative
beep, indicating that there is not a match. If more than one
pathnames as well; if you type a partial pathname and press
file matches, the shell program fills in as much as it can and
Tab, the shell lists the options within that path. Using
then emits a beep, while waiting for you to enter more text
filename completion can save you a lot of typing as well as
to differentiate between the files that match the pattern up
making it less likely that you mistype any characters.
to that point and then differ. At this point, you can either
type out the rest of the command line and press Return, or
type enough of the command line to uniquely identify the
file you want to access, and then press Tab again.



SELECT FILES USING COMPLETION




„ Type set autolist. ‹ Type the first few letters of › Type enough letters to Á Press Return.
the filename and press the make an unambiguous
– The shell executes the
¤ Type a shell command Tab key. match.
that takes a filename as an command.
– A list of possible matches ˇ Press the Tab key again.
argument.
appears.
– The shell completes the
filename.



27
UNIX FOR MAC



FIND FILES BY NAME
which you are looking. The argument -print tells the

Y
ou can locate files by their names or other criteria by
find command to display the location of the file.
using the find command. This command tends to be
faster than the Mac OS X Sherlock application for
You can also give a wildcard pattern instead of a filename,
locating files, especially those that are used by the system
and the find command lists all files that match that
or otherwise hidden from the Finder.
pattern. When you use wildcard patterns in this way you
need to enclose them in quotation marks. For example, if
The find command is a complex and very powerful utility
you save a Word document but you do not keep track of
that lets you run many different types of searches and
what folder you save it in, you can use the find command
perform a variety of actions on the files that it finds.
to locate all the .doc files in your Documents directory:
However, the most common use for the find command is
simply to locate files with a certain name and print out their
find ˜/Documents -name "*.doc" -print
locations.
This displays a list of all file locations matching the pattern.
The basic syntax for the find command is:
If you want to see a full file listing instead of the relative
pathname for the files found, you can replace the print
find pathname -name filename -print
command with the ls command.
The first parameter, pathname, is the directory where you
want to search. The filename is the name of the file for


FIND FILES BY NAME




– The shell executes the
‹ Type -name and a space. ˇ Type -print and press
LOCATE FILES BY NAME
Return. find command and prints
„ Type find and a space. › Type a filename. the file location.
¤ Type the pathname of a
directory and a space.

<<

. 8
( 69 .)



>>