COMP2718 Lab 5

Your Name -- Your Student Number

Complete this assignment by downloading this HTML file and editing it (using a text editor---not a special HTML editor). Wherever you see emphasized text (e.g. "Your name" and "Your Student Number" above) you should insert your own text, as appropriate. Submit via D2L at the end of the lab period.

~/bin

Using pico write a shell script that counts the number of processes owned by the user. The output of the script should look like:

User your-id has 23 processes.

where your-id is replaced by your user id, and 23 is replaced by the actual number of processes. What is the source of the script?

*Change this with your answer*

Call the script myprocs.sh, make it executable and move it into your ~/bin directory. Create the directory if is not there. List the commands you used.

*Change this with your answer*

.bashrc

Write the following commands to accomplish the goals described below and add the commands to the end of the ~/.bashrc file.

  1. Add ~/bin to the front of the PATH variable.

    Change this with your answer

  2. Add an alias called dt that displays the date and time similar to the following:

    The day is Wed and the time is 07:46 PM.
    

    Change this with your answer

  3. Add an alias called protect that removes all of the other/group read/write/execute permission for all the files and directories in the current directory.

    Change this with your answer

Exit status

Determine if the exit status of the following commands can be non zero. Try illegal arguments or arguments that would cause a file permission error. Provide the command and exit status (use echo $? to see the status).

  1. mv

    Change this with your answer

  2. mkdir

    Change this with your answer

  3. ps

    Change this with your answer

  4. type

    Change this with your answer

  5. ls

    Change this with your answer

  6. cd

    Change this with your answer

Test Command

Exploring the test command.

  1. Determine the command and execute the command to do each of the following in sequence.

When creating files/directories, please create one per command.

*Change this with your answer*
  1. Using the test command, write and execute a command to determine if d1 is writable by the user (use echo $?).

    Change this with your answer

  2. Using the test command, write and execute a command to determine if f1 is newer than f2 (use echo $?).

    Change this with your answer

  3. Using the test command, write and execute a command to determine if f1 is a symbolic link (use echo $?).

    Change this with your answer

Scripts with test

These questions will use the contents of /tmp/test from the previous exercise. First set the current directory to /tmp/test. Write bash scripts to do the following:

  1. Write a script called, t1.sh that prints d1 is writable if d1 is writable by the user. Show the source of t1.sh.

Change this with your answer

Show the test output of t1.sh.

Change this with your answer

  1. Write a script called, t2.sh that renames d2 to d3 if d2 contains f1, otherwise prints no rename Show the source of t2.sh.

Change this with your answer

Show the output of the script.

Change this with your answer

  1. Write a script called, t3.sh that makes f1 readable by everyone if f2 is readable by the user, otherwise prints no permission change Show the source of t3.sh.

Change this with your answer

Show the output of the script (if any).

Change this with your answer

  1. Write a script called, t4.sh that deletes the older of d1 or d2. Show the source of t4.sh.

Change this with your answer

Show the directory listing of /tmp/test.

Change this with your answer