0
0
Linux CLIscripting~5 mins

Permission types (read, write, execute) in Linux CLI - Commands & Configuration

Choose your learning style9 modes available
Introduction
Files and folders on Linux have permissions that control who can read, change, or run them. These permissions help keep your data safe and your system working properly.
When you want to allow someone to open and read a file but not change it
When you need to let a script run as a program
When you want to prevent others from deleting or modifying your files
When setting up shared folders where some users can only view files
When securing sensitive files by restricting access
Commands
This command lists the file details including its permissions so you can see who can read, write, or execute the file.
Terminal
ls -l example.txt
Expected OutputExpected
-rw-r--r-- 1 user user 123 Apr 27 12:00 example.txt
-l - Shows detailed information including permissions
This command adds execute permission for the file owner so they can run the file as a program or script.
Terminal
chmod u+x example.txt
Expected OutputExpected
No output (command runs silently)
u+x - Adds execute permission for the user (owner)
Check the permissions again to confirm the execute permission was added for the owner.
Terminal
ls -l example.txt
Expected OutputExpected
-rwxr--r-- 1 user user 123 Apr 27 12:00 example.txt
-l - Shows detailed information including permissions
This command removes write permission for group and others to prevent them from changing the file.
Terminal
chmod go-w example.txt
Expected OutputExpected
No output (command runs silently)
go-w - Removes write permission for group and others
Verify the write permission was removed for group and others.
Terminal
ls -l example.txt
Expected OutputExpected
-rwxr--r-- 1 user user 123 Apr 27 12:00 example.txt
-l - Shows detailed information including permissions
Key Concept

If you remember nothing else from this pattern, remember: read lets you view, write lets you change, and execute lets you run a file.

Common Mistakes
Trying to run a script without execute permission
The system will not allow the file to run and shows a permission denied error
Use chmod u+x filename to add execute permission for the owner before running
Giving write permission to everyone on sensitive files
Anyone can change or delete the file, risking data loss or security issues
Remove write permission for group and others using chmod go-w filename
Confusing permission letters and symbols when using chmod
Incorrect commands may not change permissions as intended or cause errors
Use u (user), g (group), o (others) with + (add), - (remove), = (set exactly) carefully
Summary
Use ls -l to see file permissions and understand who can read, write, or execute a file.
Use chmod with u, g, o and +, -, = to add, remove, or set permissions for user, group, and others.
Remember: read means view, write means change, and execute means run the file.