Linux / UNIX PATH, ls Command and File Access Permissions (Security)

Share via:

Linux / UNIX PATH, ls Command and File Access Permissions (Security)

Introduction
Linux and UNIX are powerful open-source operating systems widely used in servers, cloud platforms, development environments, and academic institutions.
To work efficiently in Linux/UNIX, it is very important to understand PATH concepts, the ls command, and File Access Permissions.
This article explains:
PATH in Linux/UNIX
● ls command with options
● Linux File Access Permissions (Security)
● chmod and umask commands
All topics are explained in a simple, detailed, and beginner-friendly manner using clear definitions, syntax, and examples.
PATH in Linux / UNIX
Definition:
A path is the location or address of a file or directory in the Linux/UNIX file system.
It tells the operating system where a file or directory exists.
Types of Paths
There are two types of paths in Linux/UNIX:
Absolute Path
Definition:
An absolute path specifies the complete location of a file or directory starting from the root directory (/).
If a path starts with /, it is an absolute path.
Syntax: /starting/from/root
Examples:
/home/user/Documents/file.txt
/etc/passwd
Key Points:
● Always starts with /
● Gives the full location
● Works from anywhere in the system
Relative Path
Definition:
A relative path specifies the location of a file or directory relative to the current working directory.
If a path does not start with /, it is usually a relative path.
Syntax:
directoryname/file
Examples:
Documents/file.txt
../Downloads
Home Directory Symbol (~)
Definition:
The symbol ~ represents the home directory of the current user.
Examples:
~/Documents
~/Downloads/file.txt
Special Path Symbols
Symbol
Meaning
/
Root directory
.
Current directory
..
Parent directory
~
Home directory
ls Command (List Command)
Definition:
The ls command is used to list files and directories.
It displays the contents of the current directory or a specified directory.
Syntax
ls [options] [file/directory]
Basic Usage Examples
ls – Lists files and directories in the current directory.
ls /home/user – Lists contents of a specific directory.
ls Command Options
ls -a – Displays all files and directories, including hidden files (files starting with .).
ls -A- Displays all files and directories except: Current directory (.) & Parent directory (..)
ls -B- Displays all files and directories except backup files (files ending with ~).
ls -l-Displays files and directories in long listing format .
Understanding ls -l Output
drwxr-xr-x 4 user user 4096 Dec 20 07:35 dir1
Field
Description
d
Directory (- for file)
rwxr-xr-x
Permissions
4
Number of links
user
Owner
user
Group
4096
Size (bytes)
Dec 20
Last modified date
07:35
Last modified time
dir1
Name
ls -m-Displays files and directories separated by commas.
ls -n-Displays user ID (UID) and group ID (GID) instead of username and group name.
ls -o-Displays long listing format without the group name.
ls -Q-Displays file and directory names within double quotes.
ls -i-Displays the inode number of each file and directory.
ls -r-Displays files and directories in reverse order.
ls -s-Displays the size of files and directories (in blocks).
ls -sh-Displays file and directory sizes in a human-readable format (KB, MB, GB).
ls –full-time-Displays complete date and time (timestamp) of files and directories.
Combining Multiple Options
Multiple options can be combined in one command.
Example:
ls -alh ➡ Shows hidden files, long listing format, and human-readable sizes.
Importance of PATH and ls
Helps navigate the Linux file system
Essential for beginners and interns
Frequently asked in exams and interviews
Used daily by Linux administrators and developers

 

Linux / UNIX File Access Permissions (Security)

Introduction
Linux/UNIX is a multi-user operating system.
To protect files and directories from unauthorized access, Linux uses File Access Permissions.
Linux Security Levels
Linux security works at different levels:
Level
Description
Hardware Level
Physical security of hardware
Operating System Level
Kernel and OS protection
Login Level
User authentication (username & password)
File Level
File and directory permissions
File Access Permissions belong to the File Level, which controls file security.
File Access Permissions define who can access a file or directory and what actions they can perform (read, write, execute).
Every file and directory has permissions for three user categories.
User Categories
Category
Symbol
Meaning
Owner
u
User who owns the file
Group
g
Group associated with the file
Others
o
All remaining users
All
a
Owner + Group + Others
Permission Types
Permission
Symbol
Meaning
Read
r
Read file content
Write
w
Modify or delete content
Execute
x
Run file as a program
Permissions for Directories
Permission
Symbol
Meaning
Read
r
List directory contents
Write
w
Create/delete files
Execute
x
Enter/access directory
Important Concept:
Without execute (x) permission on a directory, you cannot access files inside it, even if read permission is available.
Understanding Permission Structure (ls -l)
Example: drwxr-xr–
Part
Meaning
d
Directory (- means file)
rwx
Owner permissions
r-x
Group permissions
r–
Others permissions
File Types in Permission Field
Symbol
Type
Regular file
d
Directory
l
Link file
b
Block special file
c
Character special file
Permission Positions
Linux permissions contain 10 fields:
Position
Meaning
1st
File type
2–4
Owner permissions
5–7
Group permissions
8–10
Others permissions
Numeric (Octal) Permissions
Permission
Value
Read (r)
4
Write (w)
2
Execute (x)
1
Common Values
Number
Permission
7
rwx
6
rw-
5
r-x
4
r–
0
chmod Command
chmod (change mode) is used to change permissions of existing files and directories.
chmod – Numeric Mode
Syntax: chmod XYZ file_or_directory
X → Owner
Y → Group
Z → Others
Example 1: Full Access to Owner
chmod 700 script.sh
Result: -rwx——
Example 2: Common Program Permission
chmod 755 program.sh
Owner → rwx
Group → r-x
Others → r-x
Example 3: Read-Only File
chmod 444 file.txt
Example 4: Directory Permission
chmod 750 project
Only owner and group can access.
chmod – Symbolic Mode
Symbol
Meaning
u
Owner
g
Group
o
Others
a
All
+
Add
Remove
=
Assign exactly
Symbolic Examples
Add execute permission to owner: chmod u+x file.sh
Remove write permission from others: chmod o-w file.txt
Set exact permissions: chmod u=rwx,g=rx,o=r file.txt
Equivalent numeric: chmod 754 file.txt
chmod on Directories
chmod 644 mydir
Cannot enter directory (no execute permission)
Correct: chmod 755 mydir
Recursive Permission Change
chmod -R 755 project
Applies to all files and subdirectories.
umask
umask controls the default permissions assigned to newly created files and directories.
It does not affect existing files.
Default Permissions
Type
Default
File
666 (rw-rw-rw-)
Directory
777 (rwxrwxrwx)
Formula: Final Permission = Default Permission − umask
Check Current umask
umask
Example 1: Default umask (022)
umask 022
Type – Result
File   – 644 (rw-r–r–)
Directory – 755 (rwxr-xr-x)
Example 2: umask 000
umask 000
Everyone gets full access (not secure).
Example 3: umask 077 (High Security)
umask 077
| File | 600 |
| Directory | 700 |
Used in secure environments.
Example 4: Real-World Example
umask 027
touch demo.txt
mkdir testdir
Results:
File → 640 (rw-r—–)
Directory → 750 (rwxr-x—)
Note
umask values cannot exceed 7
Files never get execute permission by default
Directories get execute permission by default
Conclusion
This article provided a complete and beginner-friendly explanation of:
● PATH
● ls command
● File Access Permissions
● chmod and umask

 

 

Author    : Lavanya Nandairi
LinkedIn : https://www.linkedin.com/in/lavanya-nandagiri-817194375/
Thank you for giving your valuable time to read the above information. Please click here to subscribe for further updates.
KTExperts is always active on social media platforms.
Facebook  : https://www.facebook.com/ktexperts
LinkedIn    : https://www.linkedin.com/company/ktexperts/
Twitter       : https://twitter.com/ktexpertsadmin
YouTube   :  https://www.youtube.com/c/ktexperts
Instagram  : https://www.instagram.com/knowledgesharingplatform
Share via:
Note: Please test scripts in Non Prod before trying in Production.
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading...

Add Comment