Linux Directory Management & Permissions
Linux Directory Management & Permissions
1
Objective
2
Hidden Directories and Files
Any file/dir starting with . is hidden (e.g., .config/, .ssh/).
View with ls –a
Create hidden directory: mkdir .myhidden
Useful for configs, system settings
[Link]
3
Permissions in Linux
4
Access Types
Each file and directory in Linux has three fundamental permission types:
1. r -- Read:
For files: Allows viewing the file's contents
For directories: Allows listing the contents of the directory.
2. w – Write
For files: Allows modifying or deleting the file.
For directories: Allows creating, deleting, or renaming files within
the directory.
3. x -- Execute
For files: Allows running the file as a program or script.
For directories: Allows entering and navigating into the directory.
5
Permission Groups
These permissions are assigned to three distinct categories of users:
Owner (u): The user who created the file or directory.
Group (g): The group that the file or directory belongs to.
Others (o): All other users on the system who are not the owner or
members of the assigned group.
[Link]
6
Viewing/Checking Permissions
The ls -l command displays detailed information about files and
directories, including their permissions.
[Link]
orials/an-introduction-to-linux-permissions
7
Viewing/Checking Permissions
[Link]
[Link]/linux-file-
permissions-groups-
and-users/
Mr. Rajesh Kumar, Dr. Surbhi Computer Science Fundamentals and Pathways 8
Numeric Permissions
Numerical permissions in Linux, also known as octal permissions,
offer a concise way to represent file and directory access rights for the
owner, group, and others. Each permission type (read, write, execute) is
assigned a specific numerical value:
Read (r): 4
Write (w): 2
Execute (x): 1
These values are then summed to represent the desired permissions.
Each digit corresponds to the sum of the permission values for the
owner, group, and others, respectively.
Examples:
7 (rwx): Read (4) + Write (2) + Execute (1) = 7 (Full permissions)
6 (rw-): Read (4) + Write (2) = 6 (Read and write)
5 (r-x): Read (4) + Execute (1) = 5 (Read and execute)
9
Numeric Permissions
[Link]
orials/how-to-set-permissions-linux
Mr. Rajesh Kumar, Dr. Surbhi Computer Science Fundamentals and Pathways 10
Changing Permissions
The chmod command is used to modify file and directory permissions.
It can be used in two primary modes:
1. Symbolic Mode:
Uses letters and symbols to add, remove, or set permissions.
chmod u+x filename: Adds execute permission for the owner.
chmod go-w directoryname: Removes write permission for the
group and others.
chmod a=rwx filename: Sets read, write, and execute permissions
for all (owner, group, others).
Mr. Rajesh Kumar, Dr. Surbhi Computer Science Fundamentals and Pathways 11
Changing Permissions
2. Numeric (Octal) Mode:
Uses Octal Numbers to add, remove, or set permissions.
chmod 755 directoryname: Gives owner read, write, execute
(4+2+1=7), and group/others read, execute (4+1=5).
chmod 644 filename: Gives owner read, write (4+2=6), and
group/others read only (4).
Mr. Rajesh Kumar, Dr. Surbhi Computer Science Fundamentals and Pathways 12
Changing Ownership
chown: Changes the owner of a file or directory.
Syntax: chown newowner filename
13
Changing Ownership
Changing the Group Owner:
To change only the group owner of a file, use a colon (:) before the
new group name, followed by the file name.
[Link]
14
Example: Directory Permissions
mkdir lab
chmod 700 lab # only owner can access
chmod 755 lab # owner full, others can read/enter
Best Practice:
Never use chmod 777 unless necessary
Use principle of least privilege
Regularly check permissions with ls -l
15
Group exercise
16
Test Your Knowledge
17
Test Your Knowledge: Mini Quiz
18
Test Your Knowledge: Mini Quiz
19
Session 23
User Management Commands
Objective
21
Introduction to User Management
User management in Linux is a fundamental aspect of system
administration, enabling control over access to system resources and
maintaining.
Linux is a multi-user operating system.
Every user has:
A username
A User ID (UID)
A home directory
A default shell
Mr. Rajesh Kumar, Dr. Surbhi Computer Science Fundamentals and Pathways 22
Types of Users
Linux is a multi-user operating system, meaning multiple users can
access and operate the system simultaneously.
The following table provides an overview of user account types in
Linux, their access levels, and uses:
Root User
Standard User
Sudo User
System Account
Guest User
User Groups
23
Types of Users
1. Root User:
Access to the entire Linux system.
Root users can initiate any command, modify system settings, edit
files, or install software without restrictions.
Primarily used to perform system administration tasks.
The root account is identified by a special User ID (UID) of 0 in
the /etc/passwd file.
Any user with a UID of 0 will inherently have root privileges.
While the UID is the defining characteristic, the account is
conventionally named "root.“
The root user's home directory is typically located at /root, distinct
from the root directory of the filesystem, which is simply /.
24
Types of Users
1. Standard User
User privileges are limited.
Standard users cannot perform actions that affect core system
settings or other user accounts.
Basic access for utilizing various system resources.
25
Types of Users
3. Sudo User:
A standard user who has been granted permissions to execute
certain commands as the root user.
Every command that requires root privileges must be preceded
with the sudo command.
Before using sudo, you need to ensure it is set up correctly.
Typically, sudo is pre-installed on most Linux distributions. If it’s
not installed, you can install it using your package manager.
[Link]
unix/sudo-command-in-linux-with-examples/
26
Types of Users
4. System Account
User accounts for applications or automated services that need to
perform specific tasks on the Linux system.
System accounts operate with restricted permissions to enhance
security and control over system operations.
27
Types of Users
5. Guest User:
Temporary accounts with restricted and controlled privileges.
Users that need access for a limited time and do not require
personal files and settings.
6. User Groups
Permissions are assigned to a collection of users who are
organized into logical groups with identical permissions.
Admins can manage permissions for an entire user group instead
of managing individual user accounts.
28
A User ID (UID)
UID stands for User Identifier. It is a unique numerical value assigned to
each user account. The UID is used by the system to identify and
differentiate between different users. The uses of UID are,
Determining user permissions and access levels
Process management to associate running processes
Each file and directory in Linux has an associated UID that identifies
its owner.
UID is interconnected with Group Identifier (GID), which represents
a specific user group.
Mr. Rajesh Kumar, Dr. Surbhi Computer Science Fundamentals and Pathways 29
A User ID (UID)
Mr. Rajesh Kumar, Dr. Surbhi Computer Science Fundamentals and Pathways 30
A User ID (UID)
Mr. Rajesh Kumar, Dr. Surbhi Computer Science Fundamentals and Pathways 31
Delete User in Linux
To delete a user in Linux, use the userdel command followed by the
user's username.
Step 1: Log in to the Linux system using the root account or an
account with sudo privileges.
Step 2: To delete a user account, use the userdel command.
Mr. Rajesh Kumar, Dr. Surbhi Computer Science Fundamentals and Pathways 32
Security & Best Practices
33
Test Your Knowledge
34
Test Your Knowledge
35
Test Your Knowledge: Mini Quiz
Q3. A user has been locked using passwd -l username. What happens if
they try to log in?
They can log in but cannot run commands
b) They cannot log in at all
c) They can log in only as root
d) They can log in only via SSHAnswer: B. .config
36
Test Your Knowledge: Mini Quiz
37
Session 24
Process Monitoring: top, ps, kill
38
Objective
39
What is a Process?
A process = program in execution
Each process has:
PID (Process ID)
PPID (Parent PID)
UID (User ID)
Mr. Rajesh Kumar, Dr. Surbhi Computer Science Fundamentals and Pathways 41
The ps Command
Lists running processes: In contrast to top's real-time display, ps
(process status) provides a static snapshot of the currently running
processes.
❑ Options:
ps → current shell’s processes
ps -e → all processes
ps -ef → full details
ps aux → BSD style, CPU/memory view
Mr. Rajesh Kumar, Dr. Surbhi Computer Science Fundamentals and Pathways 42
The ps Command
ps Output Fields:
PID → Process ID
TTY → Terminal used
TIME → CPU time used
CMD → Command name
[Link]
Mr. Rajesh Kumar, Dr. Surbhi Computer Science Fundamentals and Pathways 43
The top Command
This command provides a dynamic, real-time view of the running
processes:
It displays system summary information, including uptime, load
average, and CPU/memory usage, alongside a list of processes sorted
by default based on CPU utilization.
Users can interact with top to sort by other criteria (e.g., memory
usage using M) and even kill processes by pressing k and entering the
Process ID (PID).
44
The top Command
Understanding top Output
Load Average → system load over 1, 5, 15 mins
Tasks → total, running, sleeping, zombie
CPU% → user/system/idle time
Memory Usage → used vs free
[Link]
command-in-linux-with-examples/
45
The kill Command
This command is used to terminate processes by sending signals to
them:
The kill command requires the PID of the target process.
46
The kill Command
Common signals:
SIGTERM (15) → request termination (default)
SIGKILL (9) → force kill
SIGHUP (1) → restart
Mr. Rajesh Kumar, Dr. Surbhi Computer Science Fundamentals and Pathways 47
Hands-On Demo
Tasks for Students:
Use ps -ef to list all processes
Run sleep 1000 & in background, find PID
Use top to monitor it
Kill process with kill
Verify it is terminated with ps
48
Common Scenarios
49
Test Your Knowledge
50
Test Your Knowledge
51
Test Your Knowledge: Mini Quiz
52
Session 25
Network Commands: ping, wget, curl
53
Objective
54
Why Networking Commands?
The network commands ping, wget, and curl are fundamental tools
used for network diagnostics, data retrieval, and web interaction.
Mr. Rajesh Kumar, Dr. Surbhi Computer Science Fundamentals and Pathways 55
The ping Command
Purpose: Check network connectivity
Uses ICMP (Internet Control Message Protocol)
$ ping <hostname or IP>
Options:
-c <count> → Limit number of pings
-i <interval> → Set interval between pings
-t (Windows) or -w <sec> (Linux) → Timeout
Mr. Rajesh Kumar, Dr. Surbhi Computer Science Fundamentals and Pathways 56
The ping Command
Example:
ping [Link]
ping -c 4 [Link]
ping -i 2 [Link]
ping -w 5 localhost
[Link]
Mr. Rajesh Kumar, Dr. Surbhi Computer Science Fundamentals and Pathways 57
The wget Command (Theory)
Purpose: Download files from web servers
The wget command is a free utility for non-interactive downloading
of files from the web. It supports HTTP, HTTPS, and FTP protocols,
as well as retrieval through HTTP proxies.
It supports HTTP, HTTPS, and FTP protocols, as well as retrieval
through HTTP proxies.
Purpose:
To download files from web servers or FTP servers.
To recursively download entire websites for offline browsing.
To resume interrupted downloads.
58
The wget Command
Features:
Resume downloads (-c)
Quiet mode (-q)
Save with a new name (-O filename)
Download entire website (with recursion -r)
[Link]
Mr. Rajesh Kumar, Dr. Surbhi Computer Science Fundamentals and Pathways 59
The curl Command
The curl command is a versatile command-line tool for transferring data
with URLs. It supports a wide range of protocols, including HTTP,
HTTPS, FTP, FTPS, SCP, SFTP, TFTP, DICT, TELNET, LDAP,
LDAPS, FILE, IMAP, SMTP, POP3, and more.
Purpose:
Mr. Rajesh Kumar, Dr. Surbhi Computer Science Fundamentals and Pathways 60
The curl Command
Features:
[Link]
unix/curl-command-in-linux-with-examples/
Mr. Rajesh Kumar, Dr. Surbhi Computer Science Fundamentals and Pathways 61
Comparison: ping vs wget vs curl
Comman
Use Case Protocol Output
d
Download HTTP,
wget Files
files/websites HTTPS, FTP
Mr. Rajesh Kumar, Dr. Surbhi Computer Science Fundamentals and Pathways 62
Hands-On Demo
Tasks for Students:
Use ping to test connectivity with [Link]
Download a file using wget
Fetch a webpage using curl
Try curl -I <URL> to fetch only headers
63
Best Practices
64
Test Your Knowledge
65
Test Your Knowledge
66
Test Your Knowledge
67
Summary
68
Session 26
Shell Scripting Basics: Writing Simple Bash Scripts
69
Objective
70
What is a Shell Script?
Shell scripting is an important part of process automation in Linux.
Scripting helps you write a sequence of commands in a file and then
execute them.
Features
A text file containing commands
Executes commands sequentially
Automates repetitive tasks
Commonly uses Bash (Bourne Again Shell)
Mr. Rajesh Kumar, Dr. Surbhi Computer Science Fundamentals and Pathways 71
Writing Your First Script
Create a file with .sh extension → nano [Link]
Scripts start with a bash bang.
Scripts are also identified with a shebang.
Shebang is a combination of bash # and bang ! followed is the bash
shell path.
This is the first line of the script. Shebang tells the shell to execute it
via bash shell. Shebang is simply an absolute path to the bash
interpreter.
Example: #! /bin/bash
Mr. Rajesh Kumar, Dr. Surbhi Computer Science Fundamentals and Pathways 72
Writing Your First Script
Mr. Rajesh Kumar, Dr. Surbhi Computer Science Fundamentals and Pathways 73
Write the command in Script
First Script:
#! /usr/bin/bash
echo "Hello World"
Provide execution rights to your user.
Modify the file permissions and allow execution of the script by using
the command below:
chmod u+x hello_world.sh
chmod modifies the existing rights of a file for a particular user. We are
adding +x to user u.
Mr. Rajesh Kumar, Dr. Surbhi Computer Science Fundamentals and Pathways 74
Run the script.
You can run the script in the following ways:
You can run the script in the following ways:
./hello_world.sh
bash hello_world.sh.
[Link]
scripting-crash-course-how-to-write-bash-
scripts-in-linux/
Mr. Rajesh Kumar, Dr. Surbhi Computer Science Fundamentals and Pathways 75
Variables and data types in Bash
Variables let you store data. You can use variables to read, access,
and manipulate data throughout your script.
There are no data types in Bash. In Bash, a variable is capable of
storing numeric values, individual characters, or strings of characters.
We can define a variable by using the syntax variable_name=value.
To get the value of the variable, add $ before the variable.
Mr. Rajesh Kumar, Dr. Surbhi Computer Science Fundamentals and Pathways 76
Arithmetic Expressions
Below are the operators supported by bash for mathematical
calculations:
Numerical expressions can also be calculated and stored in a variable
using the syntax below:
var=$((expression))
Oper Usage
+ addition
- subtraction
* multiplication
/ division
** exponentiation
% modulus
Mr. Rajesh Kumar, Dr. Surbhi Computer Science Fundamentals and Pathways 77
How to read user input
In bash, we can take user input using the read command.
read variable_name
To prompt the user with a custom message, use the -p flag.
read -p "Enter your age" variable_name
Mr. Rajesh Kumar, Dr. Surbhi Computer Science Fundamentals and Pathways 78
Numeric Comparison logical operators
Mr. Rajesh Kumar, Dr. Surbhi Computer Science Fundamentals and Pathways 79
Numeric Comparison logical operators
Example:
Let's compare two numbers and find their relationship:
Mr. Rajesh Kumar, Dr. Surbhi Computer Science Fundamentals and Pathways 80
Conditional Statements (if)
if [[ condition ]]
then
statement
elif [[ condition ]]; then
statement
else
do this by default
fi
Mr. Rajesh Kumar, Dr. Surbhi Computer Science Fundamentals and Pathways 81
Looping and skipping
Looping in shell scripts allows for the repeated execution of a block of
commands until a certain condition is met or for a specified number of
iterations.
While loop:
Executes commands as long as a condition is true: Ideal for scenarios
where the number of iterations is unknown beforehand.
Mr. Rajesh Kumar, Dr. Surbhi Computer Science Fundamentals and Pathways 82
While loop
#!/bin/bash
i=1
while [[ $i -le 10 ]] ; do
echo "$i"
(( i += 1 ))
done
Mr. Rajesh Kumar, Dr. Surbhi Computer Science Fundamentals and Pathways 83
for loop
#!/bin/bash
for i in {1..5}
do
echo $i
Done
Mr. Rajesh Kumar, Dr. Surbhi Computer Science Fundamentals and Pathways 84
Useful Script Examples
Backup Script:
cp [Link] backup_file.txt
echo "Backup completed!“
Debugging Scripts:
bash -x [Link]
Mr. Rajesh Kumar, Dr. Surbhi Computer Science Fundamentals and Pathways 85
Hands-On Demo
86
Best Practices
87
Test Your Knowledge
Answer: A) $()
88
Test Your Knowledge
Q.2 Which line should always be included at the top of a Bash script to
specify the interpreter?
A) #!/bin/python
B) #!/bin/bash
C) #bash
D) bash start
Answer: B) #!/bin/bash
89
Test Your Knowledge
Answer: C) ./[Link]
90
Summary
91
Session 27
Open-Source Philosophy & Licensing
92
Objective
93
What is Open Source?
Open-source philosophy is a collaborative development model where
users have access to source code to study, modify, and distribute,
fostering transparency and community-driven innovation.
Open-source licenses, defined by entities like:
Open-Source Initiative (OSI) and
based on the Open-Source Definition (OSD),Automates repetitive
tasks
serve as legal frameworks that grant these freedoms while often
imposing conditions,
Mr. Rajesh Kumar, Dr. Surbhi Computer Science Fundamentals and Pathways 94
Open-Source vs Proprietary Software
Mr. Rajesh Kumar, Dr. Surbhi Computer Science Fundamentals and Pathways 95
Philosophy of Open Source
Freedom to use (no restrictions on usage)
Freedom to study & modify (learn & improve code)
Freedom to share (collaboration & distribution)
Freedom to improve & contribute (innovation through community)
Mr. Rajesh Kumar, Dr. Surbhi Computer Science Fundamentals and Pathways 96
Philosophy of Open Source
Mr. Rajesh Kumar, Dr. Surbhi Computer Science Fundamentals and Pathways 97
Open-Source Licenses
[Link]
507/open-source-presentation
Mr. Rajesh Kumar, Dr. Surbhi Computer Science Fundamentals and Pathways 98
Major Open-Source Licenses
GNU General Public License (GPL)
Strong "copyleft" → modifications must also be open source
MIT License
Very permissive, minimal restrictions
Apache License 2.0
Allows commercial use, explicit patent rights
BSD License
Flexible, fewer restrictions, similar to MIT
Mr. Rajesh Kumar, Dr. Surbhi Computer Science Fundamentals and Pathways 99
Major Open-Source Licenses
Mr. Rajesh Kumar, Dr. Surbhi Computer Science Fundamentals and Pathways 100
Major Open-Source Licenses
Mr. Rajesh Kumar, Dr. Surbhi Computer Science Fundamentals and Pathways 101
Copyleft vs Permissive Licenses
Copyleft (e.g., GPL):
Derivative works must remain open-source
Permissive (e.g., MIT, Apache):
Derivatives can be closed-source
[Link]
Mr. Rajesh Kumar, Dr. Surbhi Computer Science Fundamentals and Pathways 102
Why Licensing Matters
Mr. Rajesh Kumar, Dr. Surbhi Computer Science Fundamentals and Pathways 103
Real-World Examples
Mr. Rajesh Kumar, Dr. Surbhi Computer Science Fundamentals and Pathways 104
Hands-On Demo
105
Test Your Knowledge
106
Test Your Knowledge
107
Test Your Knowledge
108
Summary
109