>_ IzzyLab

Hands-on task

This task is step 11 of the course “First steps in Linux”

Make a script executable and run it

easy~4 min

A colleague left the script /root/tools/backup.sh and asked you to run it. But running it gives Permission denied — the file has no execute permission.

Give the file execute permission and run the script. If all goes well, it creates the report /root/tools/report.txt by itself. Don't change the script.

What you'll practise:
  • chmod +x
  • running scripts
  • ./
  • execute permission

Topic breakdown

A script is a text file full of commands. To run it like a program, the file needs execute permission (x). New files usually don't get it — that protects against running something by accident.

ls -l hello.sh       # -rw-r--r-- ... hello.sh — no x
chmod +x hello.sh
ls -l hello.sh       # -rwxr-xr-x ... hello.sh — now it has one
./hello.sh

Why ./? When you type just a name, the shell looks for the program in system directories like /usr/bin, but not in the current one. ./ means "this file, right here".

What's checked

  1. The script has execute permission
  2. The script ran and created the report

What it looks like