-->
Previous | Table of Contents | Next |
In the act of creating a file or directory, you automatically assign permissions to the file or directory. To see what permissions are the default, use the umask command:
$ umask 744
This means that the owner of the file has full privileges, while your group and the world have the ability to read the file. To change this permission, youll again use the umask command, listing a new permission on the command line:
$ umask 007
This may look odd, and indeed it is odd. The umask command changes permissions relative to a baseline of 777. The input to the umask command is therefore subtracted from the baseline 777, leaving you with the total of 770, meaning that the owner of the file and the group have full permissions to the file, while the rest of the world has no permissions at all.
In the same way, youre automatically the owner of a file when you create it, but there may be times when you want to transfer this ownership to another user. You can do so with the chown command, provided youre logged in the system as the root user. (You didnt think you could change the ownership logged in as an ordinary user, did you? If anyone could change the ownership of a file, security in the UNIX operating system would be nonexistent.) When using the chown (short for change ownership, by the way) command, you list the new owner of the command and the file in question:
gilbert:~$ chown pat report
You can also transfer ownership of an entire directory by using the -R option to the chown command:
gilbert:~$ chown -R pat reports_1996
Similarly, the chgrp command changes group ownership of a file, listing the new group membership and the file in question:
gilbert:~$ chgrp linux_book chap4
The Sticky Bit
In our continuing obsession with security, we present information about the sticky bit. In the past, UNIX hackers used to get around file permissions by messing with entire directories, as most system administrators would forget to set restrictive permissions for the directory itself.
The sticky bit was a response to this security problem. Linux allows you to set the sticky bit, which makes a directory impregnable to everyone but the owner of a directory and the root user. To set the sticky bit, use the chmod command in the following manner:
gilbert:/$ chmod +t directoryname
Once the sticky bit is set, no one (except the root user and the owner of the directory) has the ability to move or delete files in a directory, no matter what permissions are associated with a file.
Weve thrown around the term command a great deal without ever really defining it (our copy editor is probably gnawing her red pen by this point), but were assuming you know what a command is and how you give a command to the computer. And you also know that the combination of a command and any options is called a command line.
NOTE: Under Linux, commands can be run at a command line or under the X Window System in an xterm window (which we covered in Chapter 3). However, there are some cases when theres an X Window version of the UNIX command; for example, theres a version of man for the X Window System, called xman, that you should use instead. In this chapter, well also note the X Window version.
If youve used MS-DOS for any extended period, youll instantly recognize the Linux counterparts presented here. If youve used Microsoft Windows for an extended period and have been hidden from the command line, you may be somewhat confused initially when you run through this series of Linux commands. And if youre a UNIX workstation user, youll find that there might be slight differences between the commands/options and the version of UNIX youre used to working with. (If youre a Cray supercomputer user, youre really slumming.)
NOTE: This section will touch only on the most basic and useful Linux commands. For a more complete listing of Linux commands, check out Linux in Plain Englishcoming out shortlyor teach yourself . . . UNIX, Third Edition (MIS:Press) both listed in Appendix A.
Youve already learned about the cd and pwd commands, which are used to move between directories and print the working directory, respectively. There are many more Linux commands used to deal with directories and files.
Previous | Table of Contents | Next |