SD 212 Spring 2024 / Homeworks


hw08: Icons

  • Due before the beginning of class on Friday, January 26

For today’s homework you will write a small bash script that identifies icon files whose name contains the word “face” and which are formatted as PNG images.

Files download

Follow this link to download icons.tgz, or run the following on the command line:

wget "https://roche.work/courses/s24sd212/hw/bash/icons.tgz"

You should know how to extract this kind of file now! (Or look back to the previous homework if you need a reminder.)

When you extract the file, it should create a folder called icons which contains a number of .icon files.

The file command

The file command can be used to identify the type of data in a file, even if the file is named with an incorrect extension.

For example, if I have a file called mydoc and I don’t know what it is, I might try using the file command and see something like this:

roche@ubuntu$ file mydoc
mydoc: PDF document, version 1.5

This output tells me that the document is actually a PDF file.

Your task

Given a folder called icons which contains icon files, write a bash program pngs.sh that prints the names of all files in that folder where the filename contains the word “face” and which are PNG images according to the file command. Your script should print these filenames in alphabetical order.

For example, here is the correct output if you extract the icons.tgz download from above:

icons/crying-face.icon
icons/face-with-tongue.icon
icons/nerd-face.icon

Hints:

  • Try running the file command on some files to see what it looks like when you get an actual PNG.
  • You will probably end up using file, grep, and cut, and perhaps find or a for loop.

Submit command

To submit files for this homework, run one of these commands:

submit -c=sd212 -p=hw08 pngs.sh
club -csd212 -phw08 pngs.sh