0% found this document useful (0 votes)
5 views5 pages

Le 1

Lab exercises comp sci

Uploaded by

xnyygrskkb
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views5 pages

Le 1

Lab exercises comp sci

Uploaded by

xnyygrskkb
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

CMPT 214: Programming Principles and Practice

Lab Exercise 1

September 4, 2024

Due Date: September 16, 2024, 6:00 pm


Total points: 100

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.

Git repository setup


We will start by creating a new le1 branch, branching out of the main branch, using the
following commands:
$ git switch main
$ git switch -c le1

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.

1 Organizing files with bash [90 Points]


Shell Script
Create a bash script called org.sh that takes as an argument a directory name, and
organizes the files in that directory into buckets. All files are named ‘n.txt’, where n is
a number between 1 and 100 inclusive. The buckets are just directories through which we
organize these files, and we want 5 buckets for values 1-20, 21-40, 41-60, 61-80, 81-100.
To keep your directory structure clean, put these buckets in a directory called buckets.
For visual aid, this is an example of an unorganized directory:

$ ˜/ 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.

2 Committing our work to git [10 Points]


Practice incremental development by committing your work as you complete significant por-
tions of your script. For example, commit your work before testing. If your tests reveal
bugs, fix them, and commit your fixes. If your code lacks documentation, add the neces-
sary documentation and commit again, etc,. For more complex programs in later labs and
assignments, you should commit your work after finishing a function, writing a makefile, or
whatever else you deem to be significant progress. Use your knowledge from using Git in
CMPT145. See Files to hand in for creating a git log.
$ git add org . sh
$ git commit -m " Finished implementing org . sh "

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:

git log main..le1 > git.log

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:

tar -cvf le1.tar my file1 my file2 ...

Minimum Credible Submission


The following commands must work for your submission to be graded (i.e. Write these into
a terminal to test).

$- test -s git.log; echo $?


$ test -s org.sh; echo $?

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

You might also like