0
0
Linux CLIscripting~10 mins

chown (change ownership) in Linux CLI - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - chown (change ownership)
Start
User runs chown command
System checks if user has permission
Error: Permission denied
End
Yes
System changes file owner and/or group
Command completes successfully
End
The chown command changes the owner and/or group of a file if the user has permission.
Execution Sample
Linux CLI
chown alice file.txt
ls -l file.txt
Change the owner of file.txt to user alice, then list file details to show ownership.
Execution Table
StepCommandActionResultOutput
1chown alice file.txtCheck permissionsUser has permissionNo output
2chown alice file.txtChange owner of file.txt to aliceSuccessNo output
3ls -l file.txtList file detailsShow owner and group-rw-r--r-- 1 alice users 0 Apr 27 12:00 file.txt
4EndNo more commandsProcess complete
💡 Command ends after changing ownership and listing file details.
Variable Tracker
VariableStartAfter chownAfter ls -lFinal
file_owneroriginal_owneralicealicealice
file_grouporiginal_grouporiginal_grouporiginal_grouporiginal_group
Key Moments - 2 Insights
Why does chown sometimes give 'Permission denied'?
Because only the root user can change ownership. See execution_table step 1 where permission is checked.
Does chown change the file group if only owner is specified?
No, if only owner is given, group stays the same. The variable_tracker shows file_group unchanged after chown.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the output after running 'chown alice file.txt'?
AError message
BNo output
CFile details
DPermission prompt
💡 Hint
Check execution_table row 1 and 2 output columns.
At which step does the file owner change to alice?
AStep 1
BStep 3
CStep 2
DStep 4
💡 Hint
Look at the Action column in execution_table.
If the user lacks permission, what happens according to the concept_flow?
AError: Permission denied and command stops
BSystem asks for password
COwnership changes anyway
DFile is deleted
💡 Hint
See the No branch after permission check in concept_flow.
Concept Snapshot
chown changes file owner and/or group.
Syntax: chown [owner][:group] filename
Requires root or proper permissions.
No output on success.
Use ls -l to verify ownership.
If permission denied, command fails.
Full Transcript
The chown command changes the owner and optionally the group of a file. When you run chown, the system first checks if you have permission to change ownership. If you do, it changes the owner and/or group silently. If not, it shows a permission denied error. After changing ownership, you can use ls -l to see the new owner and group. Only root or authorized users can change ownership. If you specify only the owner, the group stays the same. This process helps control who can access or modify files on the system.