Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Understanding File Permissions and Access Control
📖 Scenario: You are managing files on a computer system. To keep files safe, you need to set who can read, write, or execute each file. This is called file permissions and access control.Imagine you have a folder with important documents. You want to decide who can open, change, or run these files.
🎯 Goal: Build a simple representation of file permissions using a dictionary. Then, add a rule to check if a user has permission to perform an action on a file.
📋 What You'll Learn
Create a dictionary named files with file names as keys and their permissions as values.
Add a variable named user_action to represent the action a user wants to perform.
Write a loop to check if the user has permission for the action on each file.
Add a final statement that shows which files the user can access based on their action.
💡 Why This Matters
🌍 Real World
File permissions control who can read, write, or execute files on computers, protecting data and system security.
💼 Career
Understanding access control is essential for cybersecurity roles, system administration, and software development to ensure safe data handling.
Progress0 / 4 steps
1
Create the initial file permissions dictionary
Create a dictionary called files with these exact entries: 'report.txt': 'read', 'data.csv': 'write', 'script.sh': 'execute'.
Cybersecurity
Hint
Use curly braces {} to create a dictionary. Each key is a file name string, and each value is a permission string.
2
Add a variable for the user's desired action
Add a variable called user_action and set it to the string 'read'.
Cybersecurity
Hint
Assign the string 'read' to the variable user_action.
3
Check permissions for each file
Use a for loop with variables file and permission to iterate over files.items(). Inside the loop, write an if statement to check if permission == user_action.
Cybersecurity
Hint
Use files.items() to get file and permission pairs. Compare permission with user_action inside the loop.
4
Complete by listing accessible files
Inside the if block, add the file name to a list called accessible_files. Before the loop, create accessible_files as an empty list.
Cybersecurity
Hint
Create an empty list before the loop. Use append() to add files inside the if block.
Practice
(1/5)
1. What does the read permission allow a user to do with a file?
easy
A. Modify the contents of the file
B. View the contents of the file
C. Execute the file as a program
D. Delete the file
Solution
Step 1: Understand the meaning of read permission
The read permission allows a user to open and see the contents of a file without changing it.
Step 2: Compare with other permissions
Write permission allows changes, execute allows running the file, and delete is a separate action.
Final Answer:
View the contents of the file -> Option B
Quick Check:
Read permission = View file contents [OK]
Hint: Read means viewing file contents only [OK]
Common Mistakes:
Confusing read with write permission
Thinking read allows file execution
Assuming read allows file deletion
2. Which of the following is the correct symbolic notation for giving the owner execute permission on a file in Unix/Linux?
easy
A. u+x
B. g+x
C. o+x
D. a+x
Solution
Step 1: Understand symbolic notation for permissions
In Unix/Linux, 'u' stands for user (owner), 'g' for group, 'o' for others, and 'a' for all.
Step 2: Identify execute permission addition
Adding execute permission is done with '+x'. So 'u+x' means add execute for owner.
Final Answer:
u+x -> Option A
Quick Check:
Owner execute permission = u+x [OK]
Hint: u means owner; +x adds execute permission [OK]
Common Mistakes:
Using g+x or o+x for owner permissions
Confusing a+x with owner only
Misunderstanding symbolic letters
3. Given the file permission string -rwxr-x---, which users can execute the file?
medium
A. Owner and group members
B. Only the owner
C. Everyone
D. Only others
Solution
Step 1: Break down the permission string
The string '-rwxr-x---' means: owner has read, write, execute; group has read and execute; others have no permissions.
Step 2: Identify who can execute
Owner (rwx) can execute, group (r-x) can execute, others (---) cannot.
Final Answer:
Owner and group members -> Option A
Quick Check:
Execute permission for owner and group [OK]
Hint: Look for 'x' in owner and group parts [OK]
Common Mistakes:
Ignoring group execute permission
Assuming others have execute
Misreading permission string
4. A user tries to write to a file but gets a 'Permission denied' error. The file permissions are -rw-r--r--. What is the most likely cause?
medium
A. User has execute permission but not write
B. File is read-only for everyone
C. User is not the owner and has no write permission
D. File is locked by another process
Solution
Step 1: Analyze the permission string
'-rw-r--r--' means owner can read and write; group and others can only read.
Step 2: Understand user's permission
If the user is not the owner, they only have read permission, so writing is denied.
Final Answer:
User is not the owner and has no write permission -> Option C
Quick Check:
Write denied if not owner with write permission [OK]
Hint: Write permission only for owner here [OK]
Common Mistakes:
Assuming read means write allowed
Confusing execute with write permission
Ignoring ownership in permissions
5. You want to allow a group of users to read and execute a script but prevent them from modifying it. Which permission setting should you apply?
hard
A. Set group permissions to ---
B. Set group permissions to rw-
C. Set group permissions to rwx
D. Set group permissions to r-x
Solution
Step 1: Understand required permissions
Users need to read and execute but not write (modify) the script.
Step 2: Match permissions to requirements
'r-x' means read and execute allowed, write denied. 'rw-' allows write, 'rwx' allows all, '---' denies all.