Homework 1
The shell and linux HW
Create a new directory and execute the following bash script. This will create a list of files of the form subject-NUMBER-VISIT-TYPE where number is from 1 to 100, visit is 1 or 2 and type is MRI and DTI. Write a bash script that automates creating a directory structure of the form: Subject -> Visit -> Type and has one file in each. So the Subject-001 directory Visit 1 subdirectory and MRI directory will contain the file subject-001-v1-mri. Execute your script and reorganize the files.
#!/bin/bash
# Create a directory to store the files, if it doesn't exist
mkdir -p generated_files
cd generated_files
for i in $(seq -w 001 100); do
for v in v1 v2; do
touch "subject-${i}-${v}_mri"
touch "subject-${i}-${v}_dti"
done
done
echo "Generated 200 files in the 'generated_files' directory."
echo "Each subject has two versions (v1, v2) and two types (mri, dti)."
echo "Total files generated: 100 subjects * 2 versions * 2 types = 400 files."Requirements and submission
Your script must use set -euo pipefail, accept input and output directories as arguments, be safe to re-run, and report the number of files it organized. Add a verification command that proves there are exactly 400 files in the expected subject/visit/type layout. Submit the script, a short README.md with the command used, and terminal output (not only screenshots).
You may use an AI agent to explain shell syntax or draft a first version. Include the prompt(s), inspect every file-moving command before running it, and describe one test or correction you made. Do not use destructive commands on directories outside this homework workspace.