In order to be able to change permissions on file in Ubuntu, user need to know the basic of Ubuntu permissions. There is a guide on Ubuntu permissions in the previous post. You can check Linux file permissions guide to learn how Ubuntu permissions work.
Here is an example on Ubuntu change permissions on file. To differentiate a file and a folder is by looking at the first bit of the permission set. A normal file is indicate with - , while a folder is indicate by d , which means directory. Here is an example:
Ubuntu permissions on file:
luzar@ubuntu:~$ ls -l
total 4
-rw-r--r-- 1 luzar luzar 0 2008-10-21 03:43 file.txt
drwx------ 2 luzar luzar 4096 2008-10-21 03:43 folder
luzar@ubuntu:~$
The Ubuntu command used to change permissions on file is chmod. Here are some examples on Ubuntu change permissions on file using octal method and code method:
Example 1 - Ubuntu change permissions on file; give owner full permissions, group and others a read and execute permissions.
Using octal method:
luzar@ubuntu:~$ chmod 755 file.txt
luzar@ubuntu:~$ ls -l
total 4
-rwxr-xr-x 1 luzar luzar 0 2008-10-21 03:43 file.txt
drwx------ 2 luzar luzar 4096 2008-10-21 03:43 folder
luzar@ubuntu:~$
Using code method:
(Based on current permissions Ubuntu permissions on file)
luzar@ubuntu:~$ chmod ugo+x file.txt
luzar@ubuntu:~$ ls -l
total 4
-rwxr-xr-x 1 luzar luzar 0 2008-10-21 03:43 file.txt
drwx------ 2 luzar luzar 4096 2008-10-21 03:43 folder
luzar@ubuntu:~$
Example 2 - Ubuntu change permissions on file; give full permissions for owner but no permission for group and others.
Using octal method:
luzar@ubuntu:~$ chmod 700 file.txt
luzar@ubuntu:~$ ls -l
total 4
-rwx------ 1 luzar luzar 0 2008-10-21 03:43 file.txt
drwx------ 2 luzar luzar 4096 2008-10-21 03:43 folder
luzar@ubuntu:~$
Using code method:
(Based on current permissions in example 1)
luzar@ubuntu:~$ chmod go-rx file.txt
luzar@ubuntu:~$ ls -l
total 4
-rwx------ 1 luzar luzar 0 2008-10-21 03:43 file.txt
drwx------ 2 luzar luzar 4096 2008-10-21 03:43 folder
luzar@ubuntu:~$
Example 3 - Ubuntu change permissions on file; Give full permissions for owner, group and others.
Using octal method:
luzar@ubuntu:~$ chmod 777 file.txt
luzar@ubuntu:~$ ls -l
total 4
-rwxrwxrwx 1 luzar luzar 0 2008-10-21 03:43 file.txt
drwx------ 2 luzar luzar 4096 2008-10-21 03:43 folder
luzar@ubuntu:~$
Using code method:
(Based on current permissions in example 2)
luzar@ubuntu:~$ chmod go+rwx file.txt
luzar@ubuntu:~$ ls -l
total 4
-rwxrwxrwx 1 luzar luzar 0 2008-10-21 03:43 file.txt
drwx------ 2 luzar luzar 4096 2008-10-21 03:43 folder
luzar@ubuntu:~$
*Note: Using the code method, the command depends on the current permissions. List the current permissions with ls -l command so you can decide to add (+) or remove (-) certain permission.
Here is an example on Ubuntu change permissions on file. To differentiate a file and a folder is by looking at the first bit of the permission set. A normal file is indicate with - , while a folder is indicate by d , which means directory. Here is an example:
Ubuntu permissions on file:
luzar@ubuntu:~$ ls -l
total 4
-rw-r--r-- 1 luzar luzar 0 2008-10-21 03:43 file.txt
drwx------ 2 luzar luzar 4096 2008-10-21 03:43 folder
luzar@ubuntu:~$
The Ubuntu command used to change permissions on file is chmod. Here are some examples on Ubuntu change permissions on file using octal method and code method:
Example 1 - Ubuntu change permissions on file; give owner full permissions, group and others a read and execute permissions.
Using octal method:
luzar@ubuntu:~$ chmod 755 file.txt
luzar@ubuntu:~$ ls -l
total 4
-rwxr-xr-x 1 luzar luzar 0 2008-10-21 03:43 file.txt
drwx------ 2 luzar luzar 4096 2008-10-21 03:43 folder
luzar@ubuntu:~$
Using code method:
(Based on current permissions Ubuntu permissions on file)
luzar@ubuntu:~$ chmod ugo+x file.txt
luzar@ubuntu:~$ ls -l
total 4
-rwxr-xr-x 1 luzar luzar 0 2008-10-21 03:43 file.txt
drwx------ 2 luzar luzar 4096 2008-10-21 03:43 folder
luzar@ubuntu:~$
Example 2 - Ubuntu change permissions on file; give full permissions for owner but no permission for group and others.
Using octal method:
luzar@ubuntu:~$ chmod 700 file.txt
luzar@ubuntu:~$ ls -l
total 4
-rwx------ 1 luzar luzar 0 2008-10-21 03:43 file.txt
drwx------ 2 luzar luzar 4096 2008-10-21 03:43 folder
luzar@ubuntu:~$
Using code method:
(Based on current permissions in example 1)
luzar@ubuntu:~$ chmod go-rx file.txt
luzar@ubuntu:~$ ls -l
total 4
-rwx------ 1 luzar luzar 0 2008-10-21 03:43 file.txt
drwx------ 2 luzar luzar 4096 2008-10-21 03:43 folder
luzar@ubuntu:~$
Example 3 - Ubuntu change permissions on file; Give full permissions for owner, group and others.
Using octal method:
luzar@ubuntu:~$ chmod 777 file.txt
luzar@ubuntu:~$ ls -l
total 4
-rwxrwxrwx 1 luzar luzar 0 2008-10-21 03:43 file.txt
drwx------ 2 luzar luzar 4096 2008-10-21 03:43 folder
luzar@ubuntu:~$
Using code method:
(Based on current permissions in example 2)
luzar@ubuntu:~$ chmod go+rwx file.txt
luzar@ubuntu:~$ ls -l
total 4
-rwxrwxrwx 1 luzar luzar 0 2008-10-21 03:43 file.txt
drwx------ 2 luzar luzar 4096 2008-10-21 03:43 folder
luzar@ubuntu:~$
*Note: Using the code method, the command depends on the current permissions. List the current permissions with ls -l command so you can decide to add (+) or remove (-) certain permission.
0 comments:
Post a Comment