Shell Script Directory Management
Shell Script Directory Management
Owner permissions − The owner's permissions determine what actions the owner of the file can
perform on the file.
Group permissions − The group's permissions determine what actions a user, who is a member
of the group that a file belongs to, can perform on the file.
Other (world) permissions − The permissions for others indicate what action all other users can
perform on the file.
File Access Modes
The permissions of a file are the first line of defense in the security of a Unix system. The basic
building blocks of Unix permissions are the read, write, and execute permissions, which have
been described below −
Read
Grants the capability to read, i.e., view the contents of the file.
Write
Grants the capability to modify, or remove the content of the file.
Execute
User with execute permissions can run a file as a program
Directory Access Modes
Directory access modes are listed and organized in the same manner as any other file. There
are a few differences that need to be mentioned −
Read
Access to a directory means that the user can read the contents. The user can look at
the filenames inside the directory.
Write
Access means that the user can add or delete files from the directory.
Execute
Executing a directory doesn't really make sense, so think of this as a traverse permission.
A user must have execute access to the bin directory in order to execute the ls or
the cd command.
Using file permission symbols
ls command allows you to see the fi le permissions for fi les, directories, and devices on the
Linux system
$ ls -l sybcanew
- for regular files ,d for directories ,l for links,c for character devices,b for block devices
and n for network devices
After that, you see three sets of three characters. Each set of three characters defines an
access permission triplet:
r for read permission for the object , w for write permission for the object and x for
execute permission for the object
If a permission is denied, a dash appears in the location. The three sets relate the three
levels of security for the object:
owner of the object , group that owns the object and Everyone
The
The three permissions are read(octal 4),write(octal2) and execute (octal 1).And three
user classes are file owner, file group, and Others.
To change the file or the directory permissions, you use the chmod (change mode) command.
There are two ways to use chmod — the symbolic mode and the absolute mode.
2 -
Removes the designated permission(s) from a file
or directory.
3 =
Sets the designated permission(s).
$ ls -l abc1.txt
-rwxrwxrwx+ 1 Aniket None 0 Apr 17 09:33 abc1.txt
$ ls -l abc1.txt
[ugoa…][+-=][rwxX…]
The first group of characters defines to whom the new
permissions apply:
u for the user
g for the group
o for others (everyone else)
a for all of the above
Next, a symbol is used to indicate
The second way to modify permissions with the chmod command is to use a number to specify
each set of permissions for the file.
We can use octal number to represent access permission for all users.
The three permissions are read(octal 4),write(octal2) and execute (octal 1).And three
user classes are file owner, file group, and Others.
The value of the user can be either the name of a user on the system or the user id (uid) of a
user on the system.
The chgrp command changes the group ownership of a file. The basic syntax is as follows −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.
# setuid for uers and setgid for group users are set for a file
Real userid = executing the process Effective user id =to check access permissions
of file
Set setuid bit
Add.exe owner of the file is root
Normal user(administrator )is executing the process add.exe ,execution of add.exe will be done
with the root privileges (owner of the file no matter who is executing the process)
$ ls -l return2.sh
-rwxrwxr-x+ 1 Aniket None 220 Apr 7 10:12 return2.sh
$ls -l return2.sh
-rwsrwsr-x+ 1 Aniket None 220 Apr 7 10:12 return2.sh