• No results found

9: Change the Group of a File or Directory

In document Teach Yourself Unix in 24 Hours pdf (Page 122-126)

Changing the group membership of a file or directory is quite analogous to the steps required for changing file ownership. Almost all UNIX systems enable users to use the chgrp command to accomplish this task.

1. Usage of chgrp is almost identical to chown, too. Specify the name of the group, followed by the list of files or directories to reassign:

% ls -lg

-rwxrwxrwx 1 taylor ci 0 Oct 12 15:17 mytest % chgrp ftp mytest

% ls -lg

-rwxrwxrwx 1 taylor ftp 0 Oct 12 15:17 mytest

The caveat on this command, however, is that you must be a member of the group you’re assigning for the file, or it fails:

% ls -lg

-rwxrwxrwx 1 taylor ftp 0 Oct 12 15:17 mytest % chgrp root mytest

Portions of UNIX are well thought out and offer innovative approaches to common computer problems. File groups and file ownership aren’t examples of this, unfortu- nately. The majority of UNIX users tend to be members of only one group, so they cannot change the group membership or ownership of any file or directory on the system. Instead, users seem to just use chmod to allow full access to files; then they encourage colleagues to copy the files desired, or they simply allow everyone access.

Unlike the other commands you’ve learned in this book, chown might be one you will not use. It’s entirely possible that you’ll never need to change the ownership or group membership of any file or directory.

Summary

In this hour, you learned the basics of UNIX file permissions, including how to set and modify file permissions with chmod and how to analyze file permissions as shown by the ls -l command. You also learned about translating between numeric bases (binary and decimal) and how to convert permissions strings into numeric values. Both are foundations for the umask command, which you learned to interpret and alter as desired. Permission is only half the puzzle, however, so you also learned about file ownership, group ownership, and how to change either for any file or directory.

Workshop

The Workshop summarizes the key terms you learned and poses some questions about the topics presented in this chapter. It also provides you with a preview of what you will learn in the next hour.

Key Terms

file creation mask When files are created in UNIX, they inherit a default set of access

permissions. These defaults are under the control of the user and are known as the file creation mask.

mode A shorthand way of saying permissions mode.

permissions mode The set of accesses (read, write, and execute) allowed for each of the three classes of users (owner, group, and everyone else) for each file or directory on the system. This is a synonym for access permission.

5

Questions

1. In what situations might the following file permissions be useful? r--rw-r-- r--r--rw-

rw--w--w- -w--w--w- rwxr-xr-x r-x--x--x

2. Translate the six file permissions strings in instruction 1 into their binary and numeric equivalents.

3. Explain what the following umask values would make the default permissions for newly created files:

007 077 777

111 222 733

272 544 754

4. Count the number of groups that are represented by group membership of files in the tmp directory on your system. Use id to see if you’re a member of any of them. 5. Which of the following directories could you modify, if the id command listed the

following information? Which could you view using the ls command? % id

uid=19(smith) gid=50(users) groups=50(users) % ls -lgF

drw-r--r-- 2 root users 512 Oct 12 14:52 sh/ drwxr-xr-x 2 shakes root 512 Oct 12 07:23 shakes/ drw--- 2 meademd com435 1024 Oct 12 14:46 tmp/ drwxr-x--- 3 smith users 512 Oct 12 12:37 viewer/ drwx--- 3 jin users 512 Oct 12 12:37 Zot!/

Preview of the Next Hour

In the next hour, you learn the various UNIX file-manipulation commands, including how to copy files, how to move them to new directories, and how to create new directories. You also learn how to remove files and directories as well as about the dangers of file removal on UNIX.

5

6

Hour

6

Creating, Moving,

Renaming, and

Deleting Files and

Directories

In this hour, you learn the basic UNIX file-manipulation commands. These commands will explain how to create directories with mkdir, remove directories with rmdir, use cp and mv to move files about in the file system, and use rm to remove files. The rm command has its dangers: you learn that there isn’t an “unremove” command in UNIX and how to circumvent the possible dangers that lurk in the program.

Goals for This Hour

In this hour, you learn how to

6

Move files to new locations using mv

Rename files using mv

Remove directories using rmdir

■ Remove files using rm

Minimize the danger of using the rm command

This hour introduces several tremendously powerful commands that enable you to create a custom file-system hierarchy (or wreak unintentional havoc on your files). As you learn these commands, you also learn hints and ideas on how to best use the UNIX file system to keep your files neat and organized. These simple UNIX commands, all new in this hour, are found not only in all variants of UNIX, both BSD-based and System V-based, but they also can be brought onto DOS through utilities such as the MKS Toolkit from Mortice-Kern Systems.

In document Teach Yourself Unix in 24 Hours pdf (Page 122-126)