Bird
Raised Fist0
Linux CLIscripting~20 mins

chown (change ownership) in Linux CLI - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Chown Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
What is the output of this chown command?
You run the command chown alice file.txt on a file owned by user bob. What will happen?
Linux CLI
ls -l file.txt
chown alice file.txt
ls -l file.txt
AThe owner and group of file.txt both change to alice.
BThe owner remains bob; the group changes to alice.
CThe command fails with 'Operation not permitted' error.
DThe owner of file.txt changes to alice; group remains unchanged.
Attempts:
2 left
💡 Hint
Think about what happens when you specify only a user in chown.
💻 Command Output
intermediate
2:00remaining
What does this chown command do?
What is the effect of chown alice:developers file.txt?
Linux CLI
ls -l file.txt
chown alice:developers file.txt
ls -l file.txt
AChanges group to developers; owner remains unchanged.
BChanges owner to alice; group remains unchanged.
CChanges owner to alice and group to developers.
DFails because developers group does not exist.
Attempts:
2 left
💡 Hint
Look at the syntax user:group in chown.
💻 Command Output
advanced
2:00remaining
What error does this chown command produce?
You run chown alice: file.txt but get an error. What is the error?
Linux CLI
chown alice: file.txt
Achown: invalid user: 'alice:'
Bchown: invalid group: ''
CNo error; owner changes to alice, group unchanged.
Dchown: missing operand after 'alice:'
Attempts:
2 left
💡 Hint
Check the syntax when specifying user and group with a colon.
💻 Command Output
advanced
2:00remaining
What is the effect of this recursive chown command?
What happens when you run chown -R alice:staff /home/alice?
Linux CLI
chown -R alice:staff /home/alice
AChanges owner to alice and group to staff for /home/alice and all files inside.
BChanges owner and group only for /home/alice directory, not files inside.
CFails because recursive option is invalid.
DChanges owner to alice but group remains unchanged for all files.
Attempts:
2 left
💡 Hint
What does the -R option do in chown?
💻 Command Output
expert
3:00remaining
What is the output of this chown command with symbolic link?
Given a symbolic link link.txt pointing to file.txt, what does chown -h alice link.txt do?
Linux CLI
ls -l link.txt
chown -h alice link.txt
ls -l link.txt
ls -l file.txt
AChanges owner of the symbolic link link.txt to alice; target file.txt owner unchanged.
BChanges owner of the target file.txt to alice; link.txt owner unchanged.
CChanges owner of both link.txt and file.txt to alice.
DFails with 'Operation not permitted' because of symbolic link.
Attempts:
2 left
💡 Hint
The -h option affects symbolic links differently than normal files.

Practice

(1/5)
1. What does the chown command do in Linux?
easy
A. Deletes a file or directory
B. Changes the owner of a file or directory
C. Changes the permissions of a file or directory
D. Copies a file or directory

Solution

  1. Step 1: Understand the purpose of chown

    The chown command is used to change the ownership of files or directories in Linux.
  2. Step 2: Compare with other commands

    Changing permissions is done with chmod, deleting with rm, and copying with cp. So these are not correct.
  3. Final Answer:

    Changes the owner of a file or directory -> Option B
  4. Quick Check:

    chown changes ownership [OK]
Hint: Remember: chown = change owner [OK]
Common Mistakes:
  • Confusing chown with chmod
  • Thinking chown deletes files
  • Mixing chown with copy commands
2. Which of the following is the correct syntax to change the owner of a file named file.txt to user alice?
easy
A. chown -owner alice file.txt
B. chown file.txt alice
C. chown alice file.txt
D. chown -u alice file.txt

Solution

  1. Step 1: Recall the basic syntax of chown

    The correct syntax is chown USER FILE, so the user comes first, then the file.
  2. Step 2: Check each option

    chown alice file.txt matches the syntax. Options A, B, and C use incorrect order or invalid flags.
  3. Final Answer:

    chown alice file.txt -> Option C
  4. Quick Check:

    Syntax: chown USER FILE [OK]
Hint: User name comes before file name in chown [OK]
Common Mistakes:
  • Swapping user and file order
  • Using invalid flags like -u or -owner
  • Forgetting to specify the user
3. What will be the output of the command ls -l file.txt after running chown bob file.txt assuming file.txt was owned by user alice before?
medium
A. -rw-r--r-- 1 bob users 0 Apr 1 12:00 file.txt
B. -rw-r--r-- 1 alice users 0 Apr 1 12:00 file.txt
C. chown: invalid user: 'bob'
D. Permission denied

Solution

  1. Step 1: Understand what chown bob file.txt does

    This command changes the owner of file.txt to user bob.
  2. Step 2: Predict the ls -l output

    The owner field will show bob instead of alice. Permissions and group remain the same.
  3. Final Answer:

    -rw-r--r-- 1 bob users 0 Apr 1 12:00 file.txt -> Option A
  4. Quick Check:

    Owner changes to bob after chown [OK]
Hint: ls -l shows updated owner after chown [OK]
Common Mistakes:
  • Expecting group to change automatically
  • Thinking ownership stays the same
  • Assuming error if user exists
4. You run chown alice file.txt but get the error: chown: changing ownership of 'file.txt': Operation not permitted. What is the most likely cause?
medium
A. You are not running the command as root or with sudo
B. The file file.txt does not exist
C. The username alice does not exist
D. The file is already owned by alice

Solution

  1. Step 1: Understand permission requirements for chown

    Changing ownership usually requires root privileges or sudo because normal users cannot change file owners.
  2. Step 2: Analyze the error message

    "Operation not permitted" means permission denied, not file missing or user missing.
  3. Final Answer:

    You are not running the command as root or with sudo -> Option A
  4. Quick Check:

    chown needs root privileges [OK]
Hint: Use sudo with chown to avoid permission errors [OK]
Common Mistakes:
  • Ignoring need for root privileges
  • Assuming file or user missing causes this error
  • Trying to chown without sudo
5. You want to change the owner to carol and the group to staff for all files and folders inside /data/project recursively. Which command should you use?
hard
A. chown -r carol:staff /data/project
B. chown carol staff /data/project -R
C. chown carol:staff /data/project
D. chown -R carol:staff /data/project

Solution

  1. Step 1: Understand recursive ownership change

    The -R option applies ownership changes to all files and folders inside the given directory recursively.
  2. Step 2: Check correct syntax for user and group

    Use user:group format to set both owner and group at once.
  3. Step 3: Verify options order and spelling

    chown -R carol:staff /data/project uses -R correctly and the right syntax. chown carol staff /data/project -R has wrong order and missing colon. chown carol:staff /data/project misses recursive flag. chown -r carol:staff /data/project uses lowercase -r which is invalid.
  4. Final Answer:

    chown -R carol:staff /data/project -> Option D
  5. Quick Check:

    Use -R and user:group for recursive ownership [OK]
Hint: Use -R and user:group to change ownership recursively [OK]
Common Mistakes:
  • Forgetting the -R flag for recursion
  • Using lowercase -r instead of -R
  • Separating user and group without colon
  • Placing options after the path
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard