Le 1
Le 1
Lab Exercise 1
September 4, 2024
Instructions
All source files (Makefile, .c, .sh, ...) should be bundled in a single tarball (named
‘le1.tar’)
Verify that your tar file is not corrupted (can happen sometimes when updating the contents
of an existing tarball in an incorrect manner) by extracting it (using ‘tar -xvf le1.tar’) in a
different directory and checking its contents before submitting. Do not submit binaries;
i.e. no ‘.o’ or executable object files of any kind. You should always run ‘make clean’
before running ‘tar’ to clean all binaries.
Your code must include comments describing what it does, and how. Code with syntax
errors will receive no credit.
You should always develop your solutions incrementally on Git and show your
progress as you are developing your solutions; i.e. you should commit every single
complete change you make as you work on your solution. You must submit a git.log which
is the output of git log showing your incremental progress.
To submit your work, you should upload your tar file to Canvas.
1
To complete this lab, you must complete the gitlab setup from lab0.
Overview
In this lab, you will practice manipulating the Linux file system by organizing files in a
programatic way using bash shell scripting. If you are not comfortable with working in the
linux environment, make use of the tutorial sessions and the help-desk hours provided to you
by your instructors. You may also wish to review lab0.
The goal of this lab will be to organize a collection of files into directories based on a naming
criteria. An example of where this common organization task will be useful is organizing
datasets to use in machine learning models. This toy example is not so sophistocated. This
labs covers how to create a directory, how to copy, move and delete files, and how to use
control flow expressions in bash (if conditions and loops).
Each lab exercise will build on previous lab exercises and assignments, so make sure you
understand all the things being done. If you have questions, please ask your TA. Do not
forget to make an initial commit with the provided files before starting your work.
$ ˜/ cmpt214> l s unorg
100. txt 13. txt 20. txt 24. txt 34. txt 46. txt 54. txt 68. txt 79. txt 84. txt
11. txt 15. txt 23. txt 28. txt 3. txt 47. txt 60. txt 78. txt 81. txt 88. txt
And this is an example after organizing into buckets after calling ./org.sh:
$ ˜/ cmpt214> l s b u c k e t s /∗
buckets /100:
100. txt 81. txt 84. txt 88. txt
buckets /20:
11. txt 13. txt 15. txt 20. txt 3. txt
2
buckets /40:
23. txt 24. txt 28. txt 34. txt
buckets /60:
46. txt 47. txt 54. txt 60. txt
buckets /80:
68. txt 78. txt 79. txt
Make use of some of the following commands: cp, mv, rm, mkdir, ls, echo, basename
Know the following bash scripting constructs: shebang, loops, conditionals, conditional
operators, argument captures
Note: Make use of man pages when you don’t know how to use a command.
Testing
To help generate random files to test your script, we have provided you with a script called
gen-rand-files.sh. Use the randomly generated files from this script to test your org.sh
script.
3
Files to hand in
All source files must be on git. The following files are to be packaged into a tarball le1.tar
and submitted to canvas:
- git.log
- org.sh
You can generate the git.log file with the following command:
Your tarball should be flat (contain no subdirectories), and should not contain any files not
listed above. Remember the command to generate a tarball will be like the following:
4
All files must include Name, NSID, Student Number, and Course & section number at the
top (i.e. before any other content) of the every file, these must have the following formats
(Remove angle brackets and replace with your information):
$• Bash
# !/ bin / bash
# Name : <Last , First >
# NSID : < abc123 >
# Student Number : <##### >
# Course : CMPT214 - <## > 2024
• C
/*
Name : <Last , First >
NSID : <abc123 >
Student Number : <##### >
Course : CMPT214 - <## > 2024
*/
• Makefile
# Name : <Last , First >
# NSID : < abc123 >
# Student Number : <##### >
# Course : CMPT214 - <## > 2024