How to Manage Files, Directories, and Permissions in Linux

Linux is a multi-user operating system, so it uses a strong permission model to control who can read, write, or execute files and directories.

Permission Structure in Linux

Every file and directory has three permission levels:

LevelDescription
User (u)  Owner of the file
Group (g)  Group associated with the file
Others (o)All other users

Each level supports three permission types:

PermissionSymbolMeaning
ReadrView file content / list directory
WritewModify file / create-delete files
ExecutexRun file / access directory

Viewing File and Directory Permissions

Use ls -l:

ls -l file.txt

Example output:

-rwxr-xr–

Breakdown:
SectionMeaning
File type (d= directory)
rwxOwner permissions
r-xGroup permissions
r–Others permissions

File vs Directory Permissions (Important Difference)

📄 File Permissions
PermissionEffect
rRead file content
wModify file
xExecute file
📁 Directory Permissions
PermissionEffect
rList directory content (ls)
wCreate/delete files
xEnter directory (cd)

Changing Permissions Using chmod

Linux provides two ways to assign permissions:

Method 1: Symbolic Mode (Human-Readable)

Syntax:

chmod [u/g/o/a][+/-/=][rwx] file

Examples:

chmod u+x file.sh        # Add execute to owner

chmod g+w file.txt      # Add write to group

chmod o-r file.txt      # Remove read from others

chmod a+r file.txt      # Add read to all

Directory Example:

chmod u+rwx mydir

Method 2: Numeric (Octal) Mode

NumberPermission
0
1–x
2-w-
3-wx
4r–
5r-x
6rw-
7rwx
Common Permission Values:
PermissionMeaning
755Owner full, others read+execute
644Owner read/write, others read
700Owner only
777Full access to all (not recommended)

Examples:

chmod 755 script.sh

chmod 644 file.txt

chmod 700 private_dir

Recursive Permission Assignment

Apply permissions to directories and all contents:

chmod -R 755 /data/app

Use carefully in production systems.

Changing File Ownership (chown)

Syntax:

chown user file

chown user:group file

Examples:

chown aman file.txt

chown aman:devops file.txt

Recursive:

chown -R aman:devops /data/app

Changing Group Ownership (chgrp)

chgrp devops file.txt

Default Permissions and umask

The umask defines default permissions for new files/directories.

umask

Example:

umask 022

ObjectDefault Permission
File644
Directory755
Special Permissions (Advanced)
PermissionSymbolUse
SUIDsRun as file owner
SGIDsGroup inheritance
Sticky BittRestrict delete

Examples:

chmod 4755 file

chmod 2775 directory

chmod 1777 /tmp

Best Practices for Permissions

✔ Use least privilege principle
✔ Avoid 777 permissions
✔ Separate file and directory permissions
✔ Regularly audit using ls -l

In conclusion,
understanding how to manage files, directories, and permissions in Linux is a fundamental skill for system administrators, DevOps engineers, and beginners alike. By mastering these concepts, you can improve system security, maintain proper access control, and confidently manage Linux systems in real-world environments.