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*
Write the following commands to accomplish the goals described
below and add the commands to the end of the
~/.bashrc
file.
Add ~/bin
to the front of the
PATH
variable.
Change this with your answer
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
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
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).
mv
Change this with your answer
mkdir
Change this with your answer
ps
Change this with your answer
type
Change this with your answer
ls
Change this with your answer
cd
Change this with your answer
Exploring the test
command.
Determine the command and execute the command to do each of the following in sequence.
/tmp
called
test
/tmp/test
f1
f2
s1
to
f1
d1
d2
When creating files/directories, please create one per command.
*Change this with your answer*
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
Using the test
command, write and execute a
command to determine if f1
is newer than
f2
(use echo $?
).
Change this with your answer
Using the test
command, write and execute a
command to determine if f1
is a symbolic link
(use echo $?
).
Change this with your answer
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:
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
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
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
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