Linux Server Configuration


Examining Permission of a file: ls –l


Download 493.5 Kb.
bet18/48
Sana16.06.2023
Hajmi493.5 Kb.
#1495871
1   ...   14   15   16   17   18   19   20   21   ...   48
Bog'liq
0501-linux-server-configuration

3.7 Examining Permission of a file: ls –l


The ls -l command allows us to look at the permissions on a file:


$ ls -l


drwxr-x--- 9 aaronc staff 4096 Oct 12 12:57 accounts
-rw-rw-r-- 1 aaronc staff 11170 Dec 9 14:11 report.txt

The third and fourth columns are the owner and group-owner. The first column specify the permissions:



  • one character for the file type: d for directories, – for plain files.

  • three characters of rwx permissions for the owner (or a dash if the permission isn’t available)

  • three characters of rwx permissions for the group owner

  • three characters of rwx permissions for everyone else

If someone owns a file, then per-owner permissions apply to him. Otherwise, if he is in the group that group-owns the file, then per-group permissions apply to him. If neither of those is the case, then for-everyone-else permissions apply to him.




3.8 Changing Permissions of Files and Directories: chmod


The chmod command changes the permissions of a file or directory. A file’s permissions may be changed only by its owner or by the superuser. The command chmod takes an argument describing the new permissions. The permissions can be specified in many flexible (but correspondingly complex) ways.


Permissions can be set using letters in the following format:


[ugoa][+=-][rwx]





  • The first letters indicate who to set permissions for: u for the file’s owner, g for the group owner, o for other users, or a for all users

  • = sets permissions for files, + adds permissions to those already set, and – removes permissions

  • The final letters indicate which of the r,w,x permissions to set

For example if we want to add executable permission for a program named bubblesort to all users, we type the following command:


$ chmod a+x bubblesort


We may use numerical permissions with chmod. Three decimal numbers identify permissions for owner, group and others. The number in binary format should be interpreted as follows:

Decimal: 664


Bianry: 110 110 100
Meaning: rwx rwx rwx
Explanation: A ‘1’ in each position specifies ‘permission’, a ‘0’ specifies ‘no permission’.

For example:


$ chmod 664 bubblesort


The above command is equivalent to:


$ chmod ug=rw,o=r bubblesort


A common requirement is to change the permissions of a directory and its contents. The command chmod accepts a –R (Mnemonic: ‘recursive’) option:


$ chmod -R g+rwX,o+rX public-directory


The above command



  • Adds rwx permissions on public-directory for the group owner, and adds rx permissions on it for everyone else

  • And any subdirectories, recursively

  • Any any contained executable files

  • Contained non-executable files have rw permissions added for the group owner, and r permission for everyone else


Download 493.5 Kb.

Do'stlaringiz bilan baham:
1   ...   14   15   16   17   18   19   20   21   ...   48




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling