Sei sulla pagina 1di 26

Basic File Attributes

• ls –l

ls –l
total 176
-rw-r--r-- 1 root root 683 Aug 19 09:59 0001.pcap
-rw------- 1 root root 1586 Jul 31 02:17 anaconda-ks.cfg
drwxr-xr-x 2 root root 4096 Jul 31 02:48 Desktop
drwxr-xr-x 2 root root 4096 Jul 31 02:48 Documents
-rw-r--r-- 1 root root 48867 Jul 31 02:17 install.log
-rw-r--r-- 1 root root 683 Aug 19 09:59 0001.pcap

• File type and permission


• Links
• Ownersip
• Group ownership
• Files size
• Last modification time
• File name
$ ls –d
List only directory

Ex: ls –ld helpdir


File ownership
The system administrator creates a user account, he
assign these parameters to the users
User-ID
Group-ID
File /etc/passwd maintains the User-ID
/etc/group maintains the Group-ID
To know your own uid and group id
$ id
File permission
Unix has a simple and well defined system of assigning permission to
file.

$ls -l
-rwxr-xr-- 1 amrood users 1024 Nov 2 00:10 myfile
drwxr-xr-- 1 amrood users 1024 Nov 2 00:10 mydir

r-----Read
w----Write
X-----Execute
First group-user
Second group-group
Third group-others
Changing file permission
chmod

ls –l abc
-rw-r--r-- 1 student users 1024 Nov 2 00:10 abc

Chmod command change file access


permissions
chmod command can be used in two ways
• Relative manner
• Absolute manner
Relative manner
chmod category operation permission filename(s)

category User group others


Operation performed permission
Permission rwx

ls –l abc
-rw-r--r-- 1 student users 1024 Nov 2 00:10 abc

Chmod u+x abc


ls –l abc
-rwxr--r-- 1 student users 1024 Nov 2 00:10 abc
Chmod ugo+x abc
ls –l abc
-rwxr-xr-x 1 student users 1024 Nov 2 00:10 abc
Shorthand notation
Chmod a+x abc
Chmod +x abc
Chmod can be applied to multiple file

Ex:Chmod u+x abc xyz mno

Permissions are removed with – operator


Ex:chmod go-r abc
More than one permission can also be set
Ex:chmod g+rwx abc
Absolute manner
Absolute manner uses octal number
Octal digits have value 0 to 7

Read permission 4 (octal 100)


Write permission 2 (octal 010)
Execute permission 1 (octal 001)

Ex:chmod 400 abc


Binary Octal Permission
000 0 ---
001 1 --x
010 2 -w-
011 3 -wx
100 4 r--
101 5 r-x
110 6 rw-
111 7 rwx

Ex:chmod 666 abc


chmod 644 abc
chmod 762 abc
Write octal representation for
following
i) rwxr-xrw-
ii) rw-r-----
iii) --x-w-r--
Security implication
Chmod 000 abc
Or
Chmod u-rw, go-r abc

Ls –l abc
---------- 1 student users 1024 Nov 2 00:10 abc
Using chmod recursively (-R)
Chmod –R a+x shell_script
(Shell_script is a directory)

Chmod –R 755 .
Chmod –R a+x *
Directory permission
Changing File Ownership
chown
The chown command stands for "change owner"
and is used to change the owner of a file.
The chown command changes the ownership of
a file. The basic syntax is as follows:
$ chown option user(owner) file(s)
EX:$ chown amrood testfile
Changing Group Ownership:
The chrgp command changes the group
ownership of a file. The basic syntax is as
follows:
$ chgrp group filelist
The value of group can be the name of a group
on the system or the group ID (GID) of a group
on the system.
example:
• $ chgrp special testfile
We can change user and group with the
command

Chown sharma:dba dept.list


THE VI EDITOR
• No matter what work you do in unix, you will
create files , write some programs.
• you may have to edit some of the file(s).
• For all this you need to learn to use an editor.
• UNIX provides a one vi Editor created by bill
joy.
vi basics
Invoking vi editor

vi <filename>
Three mode
Command Mode
Input mode
Ex mode
Command Mode
When user starts up vi editor, user are in
“command mode”.

The default mode of the editor where every key


pressed is interpreted as a command to run on
text.
Input mode
To enter the text, have to change from default
command mode to Input mode
Every key pressed after switching to this mode
actually shows up as text. This mode is invoked
by pressing one of the keys among i a I A o O r R
s S.

Potrebbero piacerti anche