| File Permisions |
|---|
Not every file on the system should be readable by everyone. Likewise, some files that everyone needs (such as the executables for commands like cp, mv, etc.) should not be subject to accidental deletion or alteration by ordinary users. This is where file protection comes into play.
Unix allows three forms of access to any file: read, write, and execute. For an ordinary file, if you have read (r) permission, you can use that file as input to any command/program. If you have write (w) permission, you can make changes to that file. If you have execute (x) permission, you can ask the shell to run that file as a program.
The owner of a file can decide to give any, all, or none of these permissions to each of three classes of people:
Each file, directory, and executable has permissions set for who can read , write, and/or execute it. To find the permissions assigned to a file, the ls command with the -l option should be used. When using the "ls -l" command on a file, the output will appear as follows:
-rwxr-x--- user unixgroup size Month day hour:minute filename
The area above designated by letters and dashes (-rwxr-x---) is the area
showing the file type and permissions.
The first character shows the filetype, and is one of the following:
d directory
- plain file
b block-type special file
c character-type special file
l symbolic link
s socket
The next 9 characters are in 3 sets of 3 characters each. They indicate the file access permissions: the first 3 characters refer to the permissions for the user, the next three for the users in the Unix group assigned to the file, and the last 3 to the permissions for other users on the system. Designations are as follows:
r read permission
w write permission
x execute
permission
- no permission
Therefore, a permission string, for example, of -rwxr-x--- allows the user (owner) of the file to read, write, and execute it; those in the unixgroup of the file can read and execute it; others cannot access it at all.