Linux Bible. Christopher Negus

Чтение книги онлайн.

Читать онлайн книгу Linux Bible - Christopher Negus страница 52

Linux Bible - Christopher Negus

Скачать книгу

list files by size:

       $ ls -S ...

      After you've worked with Linux for a while, you are almost sure to get a Permission denied message. Permissions associated with files and directories in Linux were designed to keep users from accessing other users' private files and to protect important system files.

      The nine bits assigned to each file for permissions define the access that you and others have to your file. Permission bits for a regular file appear as -rwxrwxrwx. Those bits are used to define who can read, write, or execute the file.

      NOTE

      For a regular file, a dash appears in front of the nine-bit permissions indicator. Instead of a dash, you might see a d (for a directory), l (for a symbolic link), b (for a block device), c (for a character device), s (for a socket), or p (for a named pipe).

Permission File Directory
Read View what's in the file. See what files and subdirectories it contains.
Write Change the file's content, rename it, or delete it. Add files or subdirectories to the directory. Remove files or directories from the directory.
Execute Run the file as a program. Change to the directory as the current directory, search through the directory, or execute a program from the directory. Access file metadata (file size, time stamps, and so on) of files in that directory.

      As noted earlier, you can see the permission for any file or directory by typing the ls -ld command. The named file or directory appears as those shown in this example:

       $ ls -ld ch3 test -rw-rw-r-- 1 joe sales 4983 Jan 18 22:13 ch3 drwxr-xr-x 2 joe sales 1024 Jan 24 13:47 test

      The first line shows that the ch3 file has read and write permission for the owner and the group. All other users have read permission, which means that they can view the file but cannot change its contents or remove it. The second line shows the test directory (indicated by the letter d before the permission bits). The owner has read, write, and execute permissions while the group and other users have only read and execute permissions. As a result, the owner can add, change, or delete files in that directory, and everyone else can only read the contents, change to that directory, and list the contents of the directory. (If you had not used the -d options to ls, you would have listed files in the test directory instead of permissions of that directory.)

      Changing permissions with chmod (numbers)

      Here are some examples of how to change permission on a file (named file) and what the resulting permission would be:

      The following chmod command results in this permission: rwxrwxrwx

       # chmod 777 file

      The following chmod command results in this permission: rwxr-xr-x

       # chmod 755 file

      The following chmod command results in this permission: rw-r--r--

       # chmod 644 file

      The following chmod command results in this permission: ---------

       # chmod 000 file

      The chmod command also can be used recursively. For example, suppose that you wanted to give an entire directory structure 755 permission (rwxr-xr-x), starting at the $HOME/myapps directory. To do that, you could use the -R option, as follows:

       $ chmod -R 755 $HOME/myapps

      All files and directories below, and including, the myapps directory in your home directory will have 755 permissions set. Because the numbers approach to setting permission changes all permission bits at once, it's more common to use letters to change permission bits recursively over a large set of files.

      Changing permissions with chmod (letters)

      You can also turn file permissions on and off using plus (+) and minus () signs, respectively, along with letters to indicate what changes and for whom. Using letters, for each file you can change permission for the user (u), group (g), other (o), and all users (a). What you would change includes the read (r), write (w), and execute (x) bits. For example, start with a file that has all permissions open (rwxrwxrwx). Run the following chmod commands using minus sign options. The resulting permissions are shown to the right of each command.

      The following chmod command results in this permission: r-xr-xr-x

       $ chmod a-w file

      The following chmod command results in this permission: rwxrwxrw-

       $ chmod o-x file

       $

Скачать книгу