chmod
Using chmod you can change the permission of single or multiple directories or files.
In unix, nothing works without proper permissions. To run any script ,the first thing you need to
do after writing it is to give execute permissions .
To view file permissions. use ls –lrt
Example 1)
/home/d456/$ ls –lrt
-rw-r--r-- 1 d456 Readers 1181170 Apr 27 2011 apache_manual.tar.gz
-rw-r--r-- 1 d456 Readers 1128480 Apr 27 2011 perl cookbook.zip
-rw-r--r-- 1 d456 Readers 70228 May 3 2011 IMP.txt
All the files have read and write permissions to the user read to the group and others.
-rw-r--r-- can be interpreted in octal notation as 110-100-100 or 644
To change the permissions of the file IMP. txt with read and write to user and
group, only read to others (rw-rw--r--) ,you can use:
D2-/home/d456/$ chmod 664 IMP.txt
D2-/home/d456/$ ls –lrt
rw-r--r-- 1 d456 Readers 1181170 Apr 27 2011 apache_manual.tar.gz
-rw-r--r-- 1 d456 Readers 1128480 Apr 27 2011 perl cookbook.zip
-rw-rw-r-- 1 d456 Readers 70228 May 3 2011 IMP.txt
-rw-r--r-- 1 d456 Readers 5748626 May 12 2011 sg245511.pdf
Example 2)
you want to allow all users to run the script named script_name.sh
/home/d476/$ chmod a+x script_name.sh
/home/d476/$ ls –lrt script_name.sh
-rwx -rx--rx-- 1 d476 Readers 5748626 Jun 10 2011 script_name.sh
Here a in ‘a+x’ represents all.similarly use ‘u’ is for user, ‘g ‘ for group , ‘o’’ for others ‘+’ to give permissions and ‘-‘ to deny.
Example 3)
You may have to give permissions to all the files in a directory tree use –R option.
To give all files and directories read ,write and execute permissions in /home directory ,
D2- /home $ chmod -R 777 *
chmod: /home/ d476/relativity.txt operation not permitted
chmod : /home/ d476/ source3.sh operation not permitted
You will definitely get these errors if you are not an admin user or logged in as a different user.
No comments:
Post a Comment