Temporary directories

5.4 Special Directories and Filesย (Weight: 1)

๐Ÿ“˜Linux Essentials (LPI 010-160)


1. File Ownership in Linux

Every file and directory in Linux has an owner and a group.

Owner

The owner is usually the user who created the file.

Example:

-rw-r--r-- 1 student staff 1200 Mar 10 notes.txt

Here:

  • student โ†’ file owner
  • staff โ†’ group owner

Group

A group is a collection of users. Files can be assigned to a group so that multiple users can share access.

For example:

  • Developers group may access application code
  • Administrators group may access system configuration files

2. File Permission Types

Linux permissions define what actions are allowed on a file or directory.

There are three basic permission types.

PermissionSymbolMeaning
ReadrView file content
WritewModify file content
ExecutexRun file as a program

3. Permission Categories

Permissions are assigned to three different user categories.

CategorySymbolDescription
OwneruUser who owns the file
GroupgUsers in the file’s group
OthersoAll other users

Example permission output:

-rwxr-xr--

Breakdown:

SectionMeaning
rwxowner permissions
r-xgroup permissions
r–others permissions

4. Viewing File Permissions

To view file permissions, use:

ls -l

Example output:

-rw-r--r-- 1 admin developers 845 Mar 12 script.sh

Explanation:

FieldMeaning
file type
rw-r–r–permissions
adminowner
developersgroup

5. Changing File Ownership

Ownership can be changed using the chown command.

Basic syntax

chown owner file

Example:

sudo chown admin report.txt

This changes the owner of report.txt to admin.

Changing owner and group together

chown owner:group file

Example:

sudo chown admin:developers project.txt

Now:

  • owner = admin
  • group = developers

Changing only the group

chown :group file

Example:

sudo chown :developers project.txt

6. Changing Group Ownership

Group ownership can also be changed using the chgrp command.

Syntax

chgrp group file

Example:

chgrp developers project.txt

This assigns the file to the developers group.


7. Changing Permissions

Permissions are changed using the chmod command.

chmod permissions file

There are two methods:

  1. Symbolic method
  2. Numeric method

8. Symbolic Method

The symbolic method uses letters to modify permissions.

Structure

chmod [user][operation][permission] file

Users:

SymbolMeaning
uowner
ggroup
oothers
aall users

Operations:

SymbolMeaning
+add permission
remove permission
=set exact permission

Permissions:

SymbolMeaning
rread
wwrite
xexecute

Examples

Add execute permission for owner:

chmod u+x script.sh

Remove write permission from group:

chmod g-w file.txt

Add read permission for everyone:

chmod a+r document.txt

Set owner permissions exactly:

chmod u=rwx file.sh

9. Numeric (Octal) Method

Linux also supports a numeric method for permissions.

Each permission has a number:

PermissionValue
Read4
Write2
Execute1

The values are added together.

Example calculations:

PermissionCalculationValue
rwx4+2+17
rw-4+26
r–44
00

Example

chmod 755 script.sh

Meaning:

CategoryValuePermission
Owner7rwx
Group5r-x
Others5r-x

Result:

-rwxr-xr-x

Another example

chmod 644 file.txt

Permissions:

CategoryValuePermission
Owner6rw-
Group4r–
Others4r–

Result:

-rw-r--r--

10. Changing Permissions Recursively

When working with directories containing many files, permissions can be changed recursively.

chmod -R permissions directory

Example:

chmod -R 755 webapp/

This changes permissions for:

  • directory
  • all files inside it

11. Special Permissions

Linux supports special permission bits that provide advanced access control.

The three special permissions are:

PermissionPurpose
setuidRun program with owner’s privileges
setgidRun program with group privileges
sticky bitRestrict file deletion in shared directories

12. SetUID (Set User ID)

SetUID allows a program to run with the permissions of the file owner.

Example command:

chmod u+s program

Example permission display:

-rwsr-xr-x

The s indicates SetUID.

Example IT usage

Some administrative utilities require elevated privileges to access system information. SetUID allows a standard user to run the program while the program temporarily uses the owner’s permissions.


13. SetGID (Set Group ID)

SetGID allows programs to run with the group’s permissions.

Command:

chmod g+s directory

Example display:

drwxr-sr-x

Example IT usage

In a shared project directory:

  • files created automatically inherit the same group
  • useful for development teams sharing project files

14. Sticky Bit

The sticky bit is used on shared directories.

Command:

chmod +t directory

Example display:

drwxrwxrwt

What it does

Users can only delete:

  • files they own
  • files owned by root

Example IT usage

Used in shared temporary directories to prevent users from deleting other users’ files.

A well-known example directory is:

/tmp

15. File Types in Permission Display

The first character in ls -l shows the file type.

SymbolType
regular file
ddirectory
lsymbolic link
ccharacter device
bblock device

Example:

drwxr-xr-x

The d indicates a directory.


16. Best Practices in IT Environments

In professional Linux environments:

Restrict permissions

Files should only allow necessary access.

Example:

Configuration files:

chmod 600 config.conf

Use groups

Teams working on shared resources should use group permissions.

Avoid giving write access to everyone

Permissions like:

chmod 777

should be avoided because they allow any user to modify files.


17. Commands You Must Know for the Exam

CommandPurpose
ls -lView permissions
chmodChange permissions
chownChange owner
chgrpChange group
chmod -RChange permissions recursively

18. Quick Exam Summary

For the Linux Essentials exam, remember:

  • Every file has owner, group, and others permissions
  • Permissions include read (r), write (w), execute (x)
  • ls -l displays permissions
  • chmod changes permissions
  • chown changes file ownership
  • chgrp changes group ownership
  • Permissions can be set using symbolic or numeric methods
  • Special permissions include setuid, setgid, and sticky bit
Buy Me a Coffee