Files, permissions and ownership

Learning objectives

Read Linux permissions, identify file ownership, make a script executable, and protect engineering files without using excessive access.

1 Objective→ 2 Learn→ 3 Example→ 4 Practice→ 5 Verify→ 6 Continue
How to study this lessonUnderstand the idea first. Use the example to see the behaviour, practise where provided, then make sure you can explain the result before continuing.

Explanation

Read a permission string

ls -l may show -rwxr-x---. The first character describes the object type. The next three permissions belong to the owner, the next three to the group, and the last three to everyone else.

Permission File meaning Directory meaning Number
r Read file contents. List entry names. 4
w Change file contents. Create or remove entries. 2
x Execute the file. Enter or traverse the directory. 1

Mode 750 therefore gives the owner rwx, the group r-x, and others no access. Use the smallest access required by the task.

Commands you will use

Command What it does Example
whoami Prints your login name. whoami
id Shows your user ID and groups. id
groups Lists your groups. groups
ls -l Shows permissions and ownership. ls -l scripts/run.sh
stat Shows detailed metadata. stat scripts/run.sh
chmod Changes permissions on files you own. chmod u+x scripts/run.sh
umask Shows or sets which default permissions are removed. umask
chown / chgrp Changes owner or group when authorized. chgrp project rtl/dut.sv

sudo runs an authorized command with elevated privileges. It is not required for these exercises and should not be used to hide a path or permission mistake.

Worked example

mkdir -p "$HOME/asic-linux-practice/scripts"
printf '#!/usr/bin/env bash\nprintf "run complete\\n"\n' > "$HOME/asic-linux-practice/scripts/run.sh"
ls -l "$HOME/asic-linux-practice/scripts/run.sh"
chmod u+x "$HOME/asic-linux-practice/scripts/run.sh"
ls -l "$HOME/asic-linux-practice/scripts/run.sh"
"$HOME/asic-linux-practice/scripts/run.sh"

Expected result: the owner execute position changes from - to x, and the script prints run complete.

Common mistakes

  • Using chmod 777 instead of deciding who needs access.
  • Treating directory permissions as if they mean the same as file permissions.
  • Applying recursive permission changes before checking the target.
  • Changing ownership on a shared project without authorization.

Check yourself

What does chmod 640 report.txt allow for the owner, group, and others?

Engineering practice

Practice: Files, permissions and ownership

Task→Run / reason→Check result→Explain why

Create a private report, record its original mode, change it to owner read/write only with chmod 600, and verify the result with stat.

Practice work is non-certified and is not stored by ASIC Campus.