User Tools

Site Tools


Sidebar

projects

ntr0 (due 20200826)
pct1 (bonus; due 20200821)
wcp1 (due 20200821)
pct2 (due 20200826)
wcp2 (due 20200826)
adm0 (due 20200902)
pct3 (bonus; due 20200902)
wcp3 (due 20200902)
pbx0 (due 20200909)
pct4 (bonus; due 20200909)
wcp4 (due 20200909)
pbx1 (due 20200916)
pct5 (bonus; due 20200916)
wcp5 (due 20200916)
pbx2 (due 20200923)
pct6 (due 20200923)
wcp6 (due 20200923)
usr0 (due 20200930)
pct7 (bonus; due 20200930)
wcp7 (due 20200930)
gfo0 (due 20201007)
pct8 (due 20201007)
wcp8 (due 20201007)
upf0 (due 20201014)
pct9 (bonus; due 20201014)
wcp9 (due 20201014)
upf1 (due 20201021)
pctA (due 20201021)
wcpA (due 20201021)
wpa0 (due 20201028)
pctB (bonus; due 20201028)
wcpB (due 20201028)
pctC (due 20201104)
wcpC (due 20201104)
pctD (bonus; due 20201111)
wcpD (bonus; due 20201111)
pctE (bonus; due 20201118)
wcpE (bonus; due 20201118)
eoce (due 20201125)
haas:fall2020:unix:cs:cs3


Corning Community College


UNIX/Linux Fundamentals



Case Study 0x3: The Puzzle Box

~~TOC~~

Objective

To become familiar with another useful utility, and to develop some basic debugging/diagnostic abilities.

Background

The filetype of a file can be extremely important when determining what application is used to open it.

Most of the time a file is named correctly, for instance a file ending in .c can be assumed to be the source code of a C program, or .gz to be a gzipped file.

With the dircolors(1) utility colorizing specific files, it is further assuming that files which end in .mpg are really MPEG files and colors them accordingly, and the same for .zip files, etc.

In other operating systems, a file's extension determines what application is used to open the particular file. If a file that ends in .mp3 is really a .png file, the default MP3 player is going to have difficulties.

Sometimes files are not always named properly, either due to a web browser mangling an extension or for whatever reason. When a file is more than meets the eye, we must rely on the various tools available to use to determine what in fact it is.

The file utility

In UNIX there is a nifty little utility called file that attempts to determine the actual type of a file by checking a series of properties. From the file(1) man page:

There are three sets of tests, performed in this order:

  1. filesystem tests,
  2. magic number tests,
  3. and language tests.

The first test that succeeds causes the file type to be printed.

A filesystem test checks to see if the file is non-ordinary (such as a socket, symbolic link, or other special file).

The magic number test is a check of files conforming to existing fixed formats, typically by examining the file at the binary level. If using a hex editor, you will find that .gz files should always start with the same sequence of hexadecimal values.

Finally, if the file is determined to be a simple ASCII file, it will attempt to analyze whether or not it conforms to some language (ie C source code vs. an HTML document).

Note that file is not always perfect, but for most cases will get the job done. Try checking files in your home directory or elsewhere on the system and see the results.

Refer to the file(1) manual page or your textbook for more information.

Exercise

For this assignment, files are located in the file/ subdirectory of the UNIX Public Directory.

1. Do the following, and discuss the results in your Opus:
a.Copy file.txt into your home directory.
b.Using file(1), what type of file does this appear to be?
c.View the contents of this file using cat(1). Is it what it appears to be?
d.Using gzip(1), compress this file with default compression. What does file(1) say?
e.Uncompress the file, and recompress using arguments for fastest (not highest) compression. What does file(1) report now?

As in many puzzles, one's visual comprehension of the scenario plays a vital role. Where something doesn't necessarily meet the eye, or is not behaving as you would expect- just try reading any messages or output. Sometimes the clues are right under your nose.

Try your hand at the following puzzle, where things are not necessarily as they should be:

2. Do the following:
a.Locate the file abcd.txt and copy it into your home directory.
b.Being a file that ends in .txt, you might try opening it in a text editor (or simply using the cat(1) utility. Does it appear to be a text file?
c.Use the file(1) utility to determine the actual file type.
d.Unravel this puzzle in order to find some plain ASCII directions that will instruct you how to finish this assignment.

As is the case many investigations, just observing how things behave can lead to recognition of an object's true state, or the recognition of a pattern, which can be used to solve the task at hand.

Conclusions

This assignment has activities which you should tend to- document/summarize knowledge learned on your Opus.

As always, the class mailing list and class IRC channel are available for assistance, but not answers.

haas/fall2020/unix/cs/cs3.txt · Last modified: 2013/09/17 06:40 by 127.0.0.1