Sunday, 15 April 2012

Getting help,File and Directory Permissions In Linux


Getting Help:



The command that are used to get the help are discussed as :
  1. Whatis
Display a short description of command , it uses a database that is updated nightly. Often not available immediately after installation.

Syntax:
# Whatis cal

  1. Help
Display usage summary and argument list
Syntax:
<command> --help
Example:
#Date –help

  1. Man and Info:
Both provide documentation for command. Almost every command has a “man” page. Collection of pages are called linux manual.
# man date
# info date

Viewing Text Page
Syntax:
#less [option] [filename]
Example:
# less abc.txt
scroll with arrows/PgUp /PgDown

/text    :           search for text
n          :           Next Match

Option:
-c         :           Clear before displaying
-s         :           Squeeze multiple blank lines into a single blank line

Simply we can also use “less” along with pipe | as
# ll |less

File and Directory:

ll’ is used to display the information about the files and directory including date, time, users,group, size, name and permission.

Four symbols are used when displaying permission.
R          :           Read
W        :           Write
X          :           Execute
-           :           no permission

-rwxrwxrwx :             files
drwxrwxrwx :            directory
files and directory permission are symbolized by ten character.

If we want to change permission, then there are two methods:
  1. symbolic
  2. Numeric


1. Symbolic Method:

Syntax:

Chmod mode directory/filename
Mode Option:
  1. u,g,o
  2. w,r,x
  3. +,-
  4. =

  1. # chmod u+rwx file or directory : in case of user only
  2. # chmod ug+rwx file or directoty : in case of user and group
  3. # chmod u+w,g+r,o+x directory/file
  4. # chmod u+rw,g+rw directory/file
  5. # chmod u-r, g-w,o-rw directory/file
  6. # chmod ugo+rwx file/directory
  7. # chmod ugo-rwx file/directory

  • + is used to add permission
  • - is used remove permission

chmod ugo=rw directory/file
this command will assign read/write permission to u,g,o
suppose we have one file as
test.txt
permission : -r- - r- -r- -
chmod u=w,g=wx,o=w test.txt
this command will assign write to user, write/execute to group and write to other while remove the previous permission.
The main difference between +,= are + operator simply add the new permission with previous one and = assign the new permission while removing old (new permission overwrite an old)

2. Numeric Method:

In this method, calculation are based on following numbers
       r = 4        
      w = 2        
       x = 1        
      0 = no permission

Example:
#chmod 777 file/directory
in this case user get 7 means that user has permission of read/write/execute, group get 7 means read/write/execute and ame for other

# chmod 531 file/directory
in this case user get 5 means that user has permission of read/execute, group get 3 means write/execute and other get 1 means that other has permission to execute.

#chmod 742 file/directory
7 : User : rwx
4 :Group : r
2 : Other : w


Thanks ,

2 comments: