<<

. 35
( 69 .)



>>

UNIX FOR MAC



CHANGE FILE OWNERSHIP
A similar command is chgrp. The chgrp command

Y
ou can change ownership of a file so that you or
changes the group associated with a file or set of files. If
someone else can modify the contents of the file. The
you need to share a set of files with a group of other users,
chown command reassigns ownership of a file to a
you can add these users to the group associated with the
new user. This command can only be run by root or by a
file or change the group for the file. In general, changing
privileged user with the sudo command. The syntax of the
the group for the file is easier.
chown command is chown newuser filename, but you
can also change both the owner and the group associated
The chgrp command has a similar syntax to chown. If you
with a file if you specify both at once. To do this, you enter
type chgrp devt myapp.java, then anyone in the
the username of the new user and the group name
development team obtains group access to the file. If
separated by a colon. A command like chown
members of the group can write to the file, this allows
horace:devt myapp.java, for example, changes the
anyone in that group to modify the file. Like chown, chgrp
owner to horace and the group to devt for the file
can be run recursively with the -R option.
myapp.java.
Like many commands, you can use chown to work on an
entire directory if you add an argument to run the
command recursively. A chown command that starts with
chown -R is run against all the files in the directory name
that you supply.

CHANGE FILE OWNERSHIP




‹ Type the name of a file, ‹ Type the name of a file,
CHANGE THE OWNERSHIP CHANGE THE GROUP OF A FILE
OF A FILE and press Return. and press Return.
„ Type sudo chgrp followed
„ Type sudo chown › Type ls -l followed by a › Type ls -l followed by a
by a space.
followed by a space. space, then the name of the space, the name of the file,
¤ Type the name of a group
¤ Type the username of a file, and press Return. and then press Return.
on your system followed by a
user on your system followed – The file now has a new – The file now has a new
space.
by a space. owner. group.

166
11
SYSTEM ADMINISTRATION COMMANDS



When you change the group and
TYPE THIS:
ownership of a file, you do not affect the
contents of the file in any way. Information [ferro:˜] user % ls -i *
about a file, referred to as metadata, is
stored in a separate location from the file
itself. You affect this metadata when you
change ownership or the permissions RESULT:
associated with a file. Metadata is stored in
a file system structure known as an inode.
139742 AnnaRoof.JPG 140953 NoLaneBridge.JPG
You see metadata every time you list file
143416 AnnaSky.JPG 140093 OldBarn.JPG
information using the ls “l command.
You can list files with the numbers of the
141835 AugSky1.JPG 140095 OldBarn2.JPG
inodes that are associated with these files
by using the “i option instead. It is
sometimes useful to know which inodes
are being used. For example, two files in
the same file system with the same inode
refer to the same content.




‹ Type the name of a group ‹ Type the name of a group
CHANGE THE OWNER CHANGE THE GROUP OF
AND GROUP OF A FILE AN ENTIRE DIRECTORY
on your system followed by a on your system followed by a
„ Type sudo chown „ Type sudo chgrp followed
space, then type the name of space.
a file, and press Return.
followed by a space. by a space. › Type the name of a
› Type ls -l followed by a
¤ Type the name of a user ¤ Type -R followed by a directory, and press Return.
space, the name of the file,
on your system followed by a space. – All the files in the directory
and then press Return.
colon (:). now have a new owner and
– The file now has a new group.
owner and group. 167
UNIX FOR MAC




CREATE SYMBOLIC LINKS
After you type this command and press Return, you can

Y
ou can simplify the navigation of your file system by
type commands such as ls utils or cd utils. If you
creating symbolic links. A symbolic link is a special
only specify the file or directory that you want to point to
file that acts as a pointer or shortcut to another file or
when you type the ln -s command, the link receives the
directory at another location in the system.
same name as the original file.
By creating a symbolic link to a directory with a long or
If you share a set of files with other users, and those files
difficult pathname, you can move to the directory by typing
are not stored in your home directories, you can use
cd followed by the name of the link you create. If you want
symbolic links to simplify the sharing process and better
to create a shortcut for moving into or listing the contents
organize the shared files. If you do not include the -s
of the directory /Applications/Utilities, you can type the
argument, you create a hard link instead of a symbolic one.
command ln -s /Applications/Utilities util. The full
A hard link is a special copy of a file, in that it is a reference
pathname specifies where you want your link to point,
to the original file. Though it looks like a file that is
while the final argument specifies what you want to call
completely independent of the original, it is the original file
your link. The -s argument tells the ln command that you
with a new file system reference; any changes to the
want to create a symbolic link.
original file are reflected in the link.




CREATE SYMBOLIC LINKS




– A long listing of your
¤ Type the full pathname of ‹ Type ls -l followed by
CREATE A SYMBOLIC LINK
a text file, and press Return. space. symbolic link appears.
„ Type ln -s followed by a
– A symbolic link is created – The l in the first column
› Type the name of your
space.
which points to the file. new symbolic link, and press indicates that this file is a
Return. symbolic link.

168
11
SYSTEM ADMINISTRATION COMMANDS

You can use hard links to make files easier to
TYPE THIS:
access or to give them additional names. Hard
links offer a particular advantage over copies of
ls -l /bin/csh
[ferro:˜]
files, unlike copies, hard links require no
ls -l /bin/tcsh
[ferro:˜]
additional disk space. The contents of the file are
stored in only one place on the system,
regardless of how many hard links you create.
RESULT:
If you and another user maintain personal copies
of a file, the contents of those files can easily 167100 /bin/csh
become out of synch. However, if you use a hard 167100 /bin/tcsh
link, you can both keep a hard link file in your
home directory, with the assurance that any
changes that either of you makes are reflected in
both hard link files.
You create hard links with the ln command. For
example, the command ln java myapp allows
you to refer to java as myapp.
Hard links are similar to symbolic links, except
that hard links point to the contents of a file,
while symbolic links point to the name of a file.
When two files use the same inode, you know
they are hard links.




– The contents of the
ˇ Type less followed by a „ Type ln followed by a › Type ls -l followed by a
space. original file appear, showing space. space, the names of the two
that your symbolic link files separated by a space,
Á Type the name of your ¤ Type the name of a text
connects to the original file. and then press Return.
symbolic link, and press file in your directory followed
– The files appear identical
Return. by a space.
except for their names.
‹ Type a new filename, and
169
press Return.
UNIX FOR MAC




CHECK DISK USAGE
system that is running out of space. For example, if you cd

Y
ou can use the df and du commands to determine
into a particular directory and use the command du “sk *
how much space is available on your disks and how
| sort “n, you receive a list of the contents of that
much space is used, respectively. The df command
directory sorted in size order. This is very helpful if you
tells you how much disk space is allocated, used, and
want to know where most of the disk space is being
available. When you use the df command with a -k
consumed.
argument, disk space appears in kilobytes instead of
512-byte blocks.
You can use the df -k command periodically to see how
much space remains on your disk. When a file system
One of the columns that appears in the df output is
approaches full capacity, the responsiveness of the system
Capacity. This column shows you how much room in that
decreases, although any file system that is less than 90
file system is already used as a percentage of the overall
percent full is not a reason for concern. At the same time,
space available. Most Unix system administrators try to
any file system that jumps in size by 10 percent in a short
keep file systems at less than 90 percent of capacity simply
amount of time may do so again. The rate at which a file
because they perform better when there is adequate free
system is growing suggests how soon you will run out of
space.
space.
You can use the du command to determine how much
space a particular directory uses. This command can help
you track down files that consume a lot of space in a file


CHECK DISK USAGE




– The system displays your – The system displays your
DISPLAY DISK FREE DISPLAY DISK FREE
SPACE IN BLOCKS SPACE IN KILOBYTES
file system usage in blocks. file system usage in kilobytes.
„ Type df and press Return. „ Type df -k and press
Return.


170
11
SYSTEM ADMINISTRATION COMMANDS

<<

. 35
( 69 .)



>>