You are on page 1of 6

chmod is used to change the permissions of files or directories.

chmod options permissions file name

Let's say you are the owner of a file named myfile, and you want to set its permissions so that:

1. the user can read, write, ande xecute it;


2. members of your group can read ande xecute it; and
3. others may only read it.

This command will do the trick:

chmod u=rwx,g=rx,o=r myfile

This example uses symbolic permissions notation. The letters u, g, and o stand for "user",
"group", and "other". The equals sign ("=") means "set the permissions exactly like this," and
the letters "r", "w", and "x" stand for "read", "write", and "execute", respectively. The commas
separate the different classes of permissions, and there are no spaces in between them.

Here is the equivalent command using octal permissions notation:

chmod 754 myfile

Here the digits 7, 5, and 4 each individually represent the permissions for the user, group, and
others, in that order. Each digit is a combination of the numbers 4, 2, 1, and 0:

 4 stands for "read",


 2 stands for "write",
 1 stands for "execute", and
 0 stands for "no permission."

So 7 is the combination of permissions 4+2+1 (read, write, and execute), 5 is 4+0+1 (read, no
write, and execute), and 4 is 4+0+0 (read, no write, and no execute).

EXAMPLES
Read by owner only

$ chmod 400 sample.txt

Read by group only

$ chmod 040 sample.txt


Read by anyone

$ chmod 004 sample.txt

Write by owner only

$ chmod 200 sample.txt

Write by group only

$ chmod 020 sample.txt

Write by anyone

$ chmod 002 sample.txt

Execute by owner only

$ chmod 100 sample.txt

Execute by group only

$ chmod 010 sample.txt

Execute by anyone

$ chmod 001 sample.txt

Allow read permission to owner and group and anyone.

$ chmod 444 sample.txt

Allow everyone to read, write, and execute file.

$ chmod 777 sample.txt

BEFORE: -rw-rw-r-- mik mik assgn1_client.c

COMMAND: chmod u=r assgn1_client.c

AFTER: -r--rw-r-- mik mik assgn1_client.c

Example 2 :
Let’s restrict the permission such that the user cannot search the directory EXAM.
BEFORE: drwxrwxr-x mik mik EXAM

COMMAND: chmod u=rw EXAM

AFTER: drw-rwxr-x mik mik EXAM

chown command
chown command
chown command changes the user and/or group ownership of for given file. The syntax is:

chown owner-user file


chown owner-user:owner-group file
chown owner-user:owner-group directory
chown options owner-user:owner-group file

Examples

First, list permissions for demo.txt, enter:


# ls -l demo.txt
Sample outputs:
-rw-r--r-- 1 root root 0 Aug 31 05:48 demo.txt

In this example change file ownership to vivek user and list the permissions, run:
# chown vivek demo.txt
# ls -l demo.txt
Sample outputs:

-rw-r--r-- 1 vivek root 0 Aug 31 05:48 demo.txt

In this next example, the owner is set to vivek followed by a colon and a group onwership is also
set to vivek group, run:
# chown vivek:vivek demo.txt
# ls -l demo.txt
Sample outputs:

-rw-r--r-- 1 vivek vivek 0 Aug 31 05:48 demo.txt

In this example, change only the group of file. To do so, the colon and following GROUP-name
ftp are given, but the owner is omitted, only the group of the files is changed:
# chown :ftp demo.txt
# ls -l demo.txt
Sample outputs:

-rw-r--r-- 1 vivek ftp 0 Aug 31 05:48 demo.txt

The unlink command,which removes a specified file.

unlink syntax
unlink FILE

unlink examples
unlink hope.txt

Removes the file name hope.txt, and if there is no other hard link to the file data, the file data itself is
removed from the system.
link command

Description
The link command creates a hard link named FILE2 which shares the same index node as the
existing file FILE1. Since FILE1 and FILE2 share the same index node, they will point to the
same data on the disk, and modifying one will be functionally the same as modifying the other.

link examples
link computer.txt hope.txt

The above example would create the file hope.txt linked to the file computer.txt. Any changes
that occurred with either of these files would affect the other file or link.

Running the ln command without options creates a hardlink from source to destination. With the
help of the option -s it creates a symbolic link, instead.

Note: difference between hard link and softlink

Allowed within file systems only Allowed between different file systems

Symbolic links can be made to directories as well as to files on different filesystems or different
partitions.

Example 1: Creating a symbolic link

$ ln -s /usr/bin/python link_to_python
$ ls -la link_to_python
lrwxrwxrwx 1 frank frank 15 Oct 5 14:25 link_to_python -> /usr/bin/python
How do I create soft link / symbolic link?
Soft links are created with the ln command. For example, the following would create a soft link
named link1 to a file named file1, both in the current directory
$ ln -s file1 link1
To verify new soft link run:
$ ls -l file1 link1
Sample outputs:

-rw-r--r-- 1 veryv wheel 0 Mar 7 22:01 file1


lrwxr-xr-x 1 veryv wheel 5 Mar 7 22:01 link1 -> file1

You might also like