Understanding Command Syntax

209

Exercise 1: Understanding Command Syntax

  1. Use the ls command to list the files in your current directory.
  2. Now modify the behavior of the ls command by using the -l option. What differences do you notice in the output?
  3. Use the ls command with the -l option and /etc as the target argument. What does the output display?

Exercise 2: Executing Commands

  1. Define an alias for the ls -l command as ll. Use the ll command to list the files in your current directory. What does the output display?
  2. Use the type command to determine if ls is an internal or external command.
  3. Now use the type command to determine if cd is an internal or external command. What differences do you notice?

Exercise 3: The $PATH Variable

  1. Use the echo command to display the contents of the $PATH variable. What directories are listed in the $PATH variable?
  2. Create a simple bash script named myscript.sh in your current directory with the following content:

!/bin/bash

echo “Hello, world!”

Make the script executable with the chmod command:

chmod +x myscript.sh

  1. Try to run your script with the command myscript.sh. What happens?
  2. Now try to run your script with the command ./myscript.sh. What does the output display? Why is the output different from the previous step?