Vous êtes sur la page 1sur 14

BASIC LINUX COMMAND

chmod
Commands
A command is a program which interacts with
the kernel to provide the environment and
perform the functions called for by the user.
A command can be: a built-in shell command;
an executable shell file, known as a shell script;
or a source compiled, object code file.
Structure –
Command <Options> <Arguments>
File Management and
Viewing
ls cal
cd whoami
mkdir cp
mv rm –r
pwd chmod
rmdir more
who history
cat echo
Permissions
 There are three types of file access
supported by UNIX/LINUX.
− r – read, view the contents of a file or
a directory
− w –write, edit file/directory contents
− x –execute, run executable file
Permissions(contd..)
An example,
when we type ls-l , the output is like :

- rwx r-x r-- 1 hans doc 858 Aug 22


22:28 hw1 Links
Type Group Group Modification File
Permissio Date/Time Name
Owner
ns Size
User Other
Permissi Permissions
ons
Permissions(contd..)
User – the person who created the file.
Group – the group owns the file.
Other – the rest of the world
− 4 – read permission, view the contents of a
file or a directory.
− 2 –write permission, edit file/directory
contents.
− 1 –execute permission, run executable file.
Permissions(cont..)

read=4 write=2
execute=1

rwx r-x r--

4 + 2 + 1 4 + 0 + 1 4 + 0 + 0

7 5
4
Permissions(cont..)
rwx r-x r-- is a symbolic way to specify
file/directory modes, while 754 is a numeric way
(remember 7=111,5=101, 4=100).
Way to represent this file mode symbolically
--x --x –wx
Way to represent this bit string numerically
1 1 3
Permissions(cont..)

chmod
Stands for change mode.
chmod lets you tell the system how much
(or little) access it should permit to a
file/directory.
Permissions(contd..)

chmod
 Examples:
− chmod 751 my_file – the owner of
my_file has rwx(7) permission, the
group has r-x(5) permission, others
have –x(1) permission.
Getting Started…
 Create a new directory dir1 by using
the following command,
− mkdir dir1
− Go to this directory
− cd dir1
 Use Cat to create a new file named
file1.c
Getting Started

After you save the file file1.c, change the


mode of this file by using the following
command,
chmod 644 file1.c
(u=rw-, g=r--, o=r--)
Check whether you did it right by using,
ls –l
Getting Started

Then go back to parent directory by using


cd ..
Change the mode of dir1 directory
chmod 755 dir1
Check if you got the mode set right
ls –l dir1
Any Doubts………..?????

P.S. : don’t try to be smart ….. Else you can


end up giving presentations………!!!!!!