Loading…
Warp is now open-source Learn more
Loading…
On Linux and Unix-like operating systems (MacOS included), the chmod command is used to change the permissions of files and directories. The x option specifically sets the execute permission on a file, allowing it to be run as a program.
For example, to make a script executable by every user on the system, you can use the following command:
$ chmod +x script.shThen run the script directly:
$ ./script.shNote that the + sign here translates to “add permission”.
In the case of directories, the execute permission has a slightly different meaning than for files, as when set, it allows users to list their content using the ls command, or enter them using the cd command.
In some cases, you might want to control which user is allowed to execute a file.
To do so, you can use a combination of the letters:



Note that in this last case, executing chmod a+x has the same effect as chmod +x.
The X (uppercase x) option allows to conditionally set the execute permission of files and directories.
When used:
This option is particularly useful when you want to recursively change the permission of a directory and its subdirectories, without affecting the regular files themselves.
For example, let’s consider the following tmp directory:

Running the chmod -R g+X command on this directory will set the execute permission for the group on:
But will leave the permissions of the script.sh file unchanged.

Note that running chmod +X will have the same effect as running chmod a+X.
The sudo command is used to execute a command as the superuser (or root).
Executing the chmod command with sudo allows you to modify the permissions of files or directories that you do not have access to as the current user.
For example, you can use the sudo chmod +x command on a system file to give permission to all users to execute it.
$ sudo chmod +x /sbin/rebootIt is important to note that giving the execute permission to all users to a file or directory belonging to the system may lead to security vulnerabilities and have unintended consequences.
Comments will help make your scripts more readable
Via command line arguments and prompting users for input
Use cURL to send data to a server
Learn how to upload a file to FTP, SFTP servers, Artifactory, and AWS S3 using the curl command.
Learn how to copy directories and their content in Linux using the cp command with options like -r for recursive copying, -i for interactive mode, and -a for preserving attributes.
Learn how to manually and automatically create and list groups in Linux.
Learn how to output the size of directories and subdirectories in a human-readable format in Linux and macOS using the du command.
Learn how to count files and folders contained in directories and subdirectories in Linux using the ls, find, and wc commands.
Learn how to output the list of open TCP and UDP ports in Linux, as well as their IP addresses and ports using the netstat command.
Learn how to filter and format the content of files and the output of commands in Linux using the awk command.
Learn how to recursively create nested directories using the mkdir command, Bash scripts, and Python scripts.
Learn how to remove local and remote user accounts and associated groups and files in Linux using the userdel and deluser commands.
$ chmod +x script.sh$ ./script.sh$ sudo chmod +x /sbin/reboot