0% found this document useful (0 votes)
2 views

Assignment 3 - Copy

The document explains how to make a script executable in Linux using the 'chmod' command, which modifies file permissions. It details the syntax, options, and modes (symbolic and octal) for setting permissions, along with practical steps to navigate to a script's directory, check current permissions, and apply executable permissions. Finally, it outlines how to verify the changes and execute the script using the './' notation.

Uploaded by

Barun Banerjee
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Assignment 3 - Copy

The document explains how to make a script executable in Linux using the 'chmod' command, which modifies file permissions. It details the syntax, options, and modes (symbolic and octal) for setting permissions, along with practical steps to navigate to a script's directory, check current permissions, and apply executable permissions. Finally, it outlines how to verify the changes and execute the script using the './' notation.

Uploaded by

Barun Banerjee
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

ASSIGNMENT: 3

AIM: How to Make Script Executable in Linux using “chmod” Command



In Unix operating systems, the chmod command is used to


change the access mode of a file. The name is an abbreviation
of change mode. Which states that every file and directory has a
set of permissions that control the permissions like who can read,
write or execute the file. In this the permissions have three
categories: read, write, and execute simultaneously represented
by `r`, `w` and `x`. These letters combine together to form a
specific permission for a group of users.
The `chmod` command is used to modify this permission so that
it can grant or restrict access to directories and files. Let’s have a
look at the syntax and options for the `chmod` command in Linux
Operating System.

Syntax of chmod command


chmod [options] [mode] [File_name]
Here,
 Options: Optional flags that modify the behavior of
the chmod command.
 Mode: The permissions to be set, represented by a three-digit
octal number or symbolic notation (e.g., u=rw,go=rx).
 File_name: The name of the file or directory for which the
permissions are to be changed.
Options Available in chmod Command Linux
Options Description

Apply the permission change recursively to all the files and directories
`-R` within the specified directory.

It will display a message for each file that is processed. while indicating the
`-v` permission change that was made.

It works same as `-v` but in this case it only displays messages for files
`-c` whose permission is changed.

`-f` It helps in avoiding display of error messages.


Options Description

`-h` Change the permissions of symbolic links instead of the files they point to.

Modes in chmod Command in Linux


The “mode” helps in setting new permissions that have to be
applied to files or directories.
This mode can be specified in several ways, we will discuss two
modes: Symbolic and Octal mode.
1) Symbolic mode
If we talk about symbolic mode, we can say that it is the most
common method used for specifying fir permissions. In this we
have to make a combination of letters and operators to set or
tell what to do with permissions.
The following operators can be used with the symbolic mode:
Operators Definition

`+` Add permissions

`-` Remove permissions

`=` Set the permissions to the specified values

The following letters that can be used in symbolic mode:


Letters Definition

`r` Read permission

`w` Write permission

`x` Execute permission

The following Reference that are used:


Reference Class

u Owner

g Group

o Others
Reference Class

a All (owner,groups,others)

Examples of Using the Symbolic mode:


 Read, write and execute permissions to the file owner:
chmod u+rwx [file_name]

 Remove write permission for the group and others:


chmod go-w [file_name]

 Read and write for Owner, and Read-only for the group and
other:
chmod u+rw,go+r [file_name]

2) Octal mode
It is also a method for specifying permissions. In this method we
specify permission using three-digit number. Where..
 First digit specify the permission for Owner.
 Second digit specify the permission for Group.
 Third digit specify the permission for Others. The digits
NOTE: The digits are calculated by adding the values of the
individual permissions.
Value Permission

4 Read Permission

2 Write Permission

1 Execute Permission

Examples of Using the Octal mode:


Suppose if we to give read and write permission to the file Owner.
Read, write and executable permission to the Group. Read-only
permission to the Other. They our command would be.
chmod 674 [file_name]

Here.
 6 represent permission of file Owner which are (rw).
 7 represent permission of Group which are (rwx).
 4 represent permission of Other which is (r).
Practical Implementaion of How to Make
script executable in Linux
Understanding Script Execution in Linux
In Linux, scripts are typically written in languages like Bash,
Python, or Perl. While the script’s content is crucial, ensuring it
has executable permissions is equally important. Without
execution permissions, Linux won’t allow the script to run.
Step 1: Navigate to the Script’s Directory
Open the terminal and use the cd command to navigate to the
directory where your script is located.
For example:
cd /path/to/your/script
Step 2: Check Current Permissions
Use the `ls` command with the `-l` option to list the files in the
directory along with their permissions. This step helps you identify
the current permissions of your script:
ls -l

checking current permission

Step 3: Make the Script Executable


To make a script executable, you need to use the
`chmod` command. Assuming your script is named `example .sh`,
you can make it executable with the following command:
chmod +x example.sh
This command adds the execute (+x) permission to the script.
Step 4: Verify Changes
Run the `ls -l` command again to verify that the script now has
execute permissions. You should see an ‘x’ in the permission field
for the script:
ls -l

verifying changes after making script executable

Step 5: Execute the Script


Now that your script has executable permissions, you can run it
using the `./` notation followed by the script’s name. For
example:
./example.sh

execute the script

This notation tells Linux to look in the current directory ( .) for the
script named example.sh.

You might also like