Changing permissions for files and directories in shell

Before changing any permissions, please check the current permissions of a file by ll command,

Here the first part(-rw-r--r--) represents the type of file and its permissions:

1st character is file type, - is a regular file, d is a directory

2,3,4 chars are permissions for the owner of the file, here "rw-"

5,6,7 chars are permissions for the group of the file, here "r--"

8,9,10 chars are permissions for the other users, which are not part of this group, here "r--"

Note: only the owner of the file/directory can modify the permissions of the file/directory

Permissions can be set on any file or directory using below method which is known as absolute method:

4=read 2=write 1=execute

chmod 777 <file_name>

ex: below command gives all the permissions to file1.txt

touch file1.txt #this creates a new file named file1.txt
chmod 777 file1.txt

7 - permission for the owner 7 - permission for group 7 - permission for other users which are not part of this group

ex 2:

chmod 764 file1.txt

Here the owner(user) is getting all permissions, i.e 7=4+2+1(read+write+execute)

group is getting read and write permissions, i.e 6=4+2(read+write)

other users are getting only read permission, i.e 4

for directory r,w and x permissions work as follows:

r=can list the file by ls command

w=can create/delete/rename files in directory

x=gives access to change directory, i.e cd


Change ownership of file/directory:

Note: only the owner of file can change its ownership

Syntax: chown user:group filename

chown user1:group1 file1.txt

Telnet command is used to check wherther particular port is working or not:

telnet localhost 80

if output of above command is connection refused, then there is no service running on port 80, replace localhost with target system ip address accordingly

Below command is used to check which ports are being used and which apps are already running in your linux system

netstat -tulpn