<<

. 9
( 69 .)



>>




28
2
WORK WITH FILES




In addition to searching by name or wildcard pattern, you can also
search by other qualities of the file, such as the last time the file was
changed, the owner of the file, or the permissions of the file. You
control the search with the arguments you include after the pathname
of the directory.

ARGUMENT SEARCHES FOR
Files belonging to a certain group.
-group groupname
Like -name, but matches regardless of case.
-iname filename
Files modified within a certain number of minutes.
-mmin minutes
Files modified within a certain number of days.
-mtime days
Files that have specific permissions set.
-perm +filemode
Files that are an exact size in characters.
-size charsc




– The shell executes the
‹ Type -name and a space. ˇ Type -print and press
FIND FILES BY PATTERN
Return. find command and prints
„ Type find and a space. › Type a wildcard pattern in the file location for each file
quotes.
¤ Type the pathname of a matching the wildcard
pattern.
directory and a space.




29
UNIX FOR MAC




CHANGE THE CURRENT DIRECTORY
When your current directory changes, your prompt changes

Y
ou can change your current directory by using the cd
as well, to reflect the new location. Your prompt displays
command. Each shell window operates in a specific
the names of up to three directories above your current
location within the file structure, and you can view
location, or fewer if you are close to the root directory.
this location by typing the pwd command. The pwd
For example, if you are in the directory /usr/share/
command is Unix shorthand for print (display) working
tcsh/examples, on a computer named ferro, your prompt
directory. The current working directory is the directory
looks something like this:
from which relative pathnames are computed and the
default directory in which files are found or saved.
[ferro:share/tcsh/examples] user%
If you type cd alone, it returns you to your Home directory.
You can use wildcards and filename completion with the cd
If you provide the cd command with a pathname argument,
command; it accepts special directory names such as cd ..,
either relative or full, you change to that directory. You can
to go up one directory level, and cd ˜user, to change to
change your current directory to any directory that grants
the Home directory of the user user. You can also use the
you execution access permissions. This allows you to
cd - command to return to the last directory in which you
explore nearly all of the directories on your hard drive, with
were working.
the exception of a few system directories that are
protected.



CHANGE THE CURRENT DIRECTORY




– The shell shows your ‹ Type a new directory
DETERMINE YOUR CURRENT CHANGE TO A DIFFERENT
WORKING DIRECTORY DIRECTORY
current location. name and press Return.
„ Type pwd and press ¤ Type cd and a space. – Your current directory
Return. changes to the new location.



30
3
WORK WITH DIRECTORIES

You can move through the file system by using the
directory stack. The stack is a list of directories of which
the shell keeps track. You can list the stack by typing dirs.
To change to a new directory and add it to the directory
stack, use the command pushd pathname. This
command adds a new pathname to the stack, and prints
the stack. You can use the directory stack by typing popd
to remove the top directory from the stack and change
to the next one down, or by typing pushd ” with no
arguments ” to swap the top two stack entries and
change to the new top directory. The directory stack is
very useful if you are going to be switching between
several directories in the same shell window.

Example:
[ferro:˜/Documents] user% pushd /usr/lib
/usr/lib ˜/Documents
[ferro:/usr/lib] kynn% pushd /etc
/etc /usr/lib ˜/Documents
[ferro:/etc] kynn% popd
/usr/lib ˜/Documents
[ferro:/usr/lib] kynn%




– Your current directory
ˇ Type cd - and press Return.
RETURN TO THE RETURN TO YOUR
PREVIOUS DIRECTORY HOME DIRECTORY changes to your Home
– Your current directory
› Repeat steps 2 and 3 to Á Type cd and press Return. directory.
changes back to the previous
move to a new directory. directory.



31
UNIX FOR MAC




CREATE A DIRECTORY
create the directory /usr/local/resp, you must have write

Y
ou can use the mkdir command to create new
access to the /usr/local directory. You can either change
directories. Directories are useful for organizing your
your working directory to the /usr/local directory using the
files into a logical structure. When you create a
cd command and type mkdir resp, or you can type mkdir
directory in the Unix shell, you can access it through the
/usr/local/resp from any current directory.
Mac OS X Finder as a folder; conversely, when you create a
folder in the Mac OS X Finder, you can access it as a
When you give a pathname, whether relative or full, the
directory in the Unix shell.
intervening directories must exist. If they do not, you
receive an error message, and the directory is not created.
The arguments that you give to the mkdir command affect
You can tell the mkdir command to create any necessary
how the command creates new directories. When you
directories by using the -p option. For example, to create
create a directory with a space in the name, you must
the directory ˜/Documents/by-date/2003/03, you can type
enclose it in quotation marks, unless you want to create
mkdir -p ˜/Documents/by-date/2003/03. This command
several directories at once.
creates the by-date and 2003 directories as well as the 03
directory if they do not already exist ” presumably, the
To create a directory, you need to have write permissions
Documents directory already exists in your Home directory.
for the current directory or the directory in which you are
creating the new directory. For example, if you want to


CREATE A DIRECTORY




¤ Type the name of a new ¤ Type the names of several
CREATE A DIRECTORY CREATE SEVERAL
DIRECTORIES AT ONCE
directory and press Return. directories you want to create
„ Type mkdir and a space.
„ Type mkdir and a space. and press Return.
– The shell creates the new
– The shell creates the new
directory.
directories.



32
3
WORK WITH DIRECTORIES




By default, anyone on the system can read and
execute any directories you create, which means
that all users of your computer can change to the
new directories and list their contents. If you do not
want universal access to your files or directories, you
can change the directory permissions by using the
chmod command, or you can instruct the mkdir
command to set the file mode automatically by
using the -m option.
When using the -m option, you follow it with the file
mode you want to set, as with the chmod command.

Example:
[ferro:˜] user% mkdir -m go-rwx Private
[ferro:˜] user% ls -lad Private
drwx””” 2 user staff 68 Nov 20 17:03 Private




¤ Type the name of your ¤ Type the pathname of
CREATE A DIRECTORY WITH CREATE INTERVENING
A MULTIWORD NAME DIRECTORIES
new directory in quotation your new directory, including
„ Type mkdir and a space. „ Type mkdir -p and a
marks, and press Return. intervening directories, which
do not yet exist.
space.
– The shell creates the new
– The shell creates the new
directory.
directories.


33
UNIX FOR MAC

DELETE A DIRECTORY
subdirectories using the rmdir command. You can now

Y
ou can remove unwanted directories by using the
remove the directory. Sometimes apparently empty
rmdir command. One use for this command is to
directories contain hidden files ” such as .DS_Store, which
remove extraneous directories that make it harder to
is a Mac OS X system file ” and you need to locate them
locate files you actually need.
with the ls -A command and remove them before
removing the directory.
While you can use the rm command to delete normal files,
you cannot use it to delete directories. This is a safety
While you are not allowed to remove the current directory
measure to prevent you from accidentally deleting a
using the rmdir command, you may be able to remove it
directory that might contain useful or important files. To
indirectly. For example, if you are in the subdirectory foo of
delete a directory, you must use the rmdir command.
your Home directory, you can type rmdir ˜/foo. However,
this is not generally a good idea, because you can end up
The argument given to the rmdir command is the name of

<<

. 9
( 69 .)



>>