User Tools

Site Tools


Sidebar

projects

wcp1 (due 20220824)
adm0 (due 20220831)
ntr0 (due 20220831)
pct1 (bonus; due 20220831)
wcp2 (due 20220831)
pbx0 (due 20220907)
pct2 (due 20220907)
pct3 (bonus; due 20220907)
wcp3 (due 20220907)
wcp4 (due 20220914)
pbx1 (due 20220915)
pct4 (due 20220915)
wcp5 (due 20220921)
pbx2 (due 20220922)
pct5 (bonus; due 20220922)
gfo0 (due 20220928)
wcp6 (due 20220928)
pct6 (due 20220929)
upf0 (due 20220929)
pct7 (bonus; due 20221005)
upf1 (due 20221005)
wcp7 (due 20221005)
bwp1 (bonus; due 20221019)
pct8 (due 20221019)
usr0 (due 20221019)
wcp8 (due 20221019)
pct9 (bonus; due 20221026)
wcp9 (due 20221026)
gfo1 (due 20221102)
pctA (due 20221102)
srf0 (due 20221102)
wcpA (due 20221102)
pctB (bonus; due 20221109)
wcpB (due 20221109)
mtf0 (due 20221110)
pctC (due 20221116)
wcpC (due 20221116)
wpa0 (due 20221117)
bwp2 (bonus; due 20221201)
pctD (bonus; due 20221201)
wcpD (bonus; due 20221201)
pctE (bonus; due 20221207)
wcpE (bonus; due 20221207)
gfo2 (due 20221208)
EoCE (due 20221219)
haas:fall2022:unix:cs:cs2


Corning Community College


UNIX/Linux Fundamentals



Case Study 0x2: Unconventional Naming

~~TOC~~

Objective

To see an importance in holding certain conventions, and how to deal with situations that deviate in some way.

Background

With the increasing popularity of “Personal Computers” and “File Sharing Services”, there has been a surplus of inappropriately named files. Characters like the space, while a valid character to use, can make for some interesting command-line issues as you will soon encounter.

As this behavior isn't likely to go away, it is important to know how to deal with such files on a UNIX system.

Copy the badname.tgz file from the naming/ subdirectory of the UNIX public directory into your home directory and extract all the files. They will go into a badname/ directory relative to your current directory.

There are three subdirectories created under the badname directory: example/, exercise/, and bonus/

Change into the various directories and list the files. Take a look at the names, and try to figure out what they are. Try and see if you can view their contents by conventional means (by manual typing.. no shortcuts :) )

For example, here are some of the files you may encounter:

Try to view: look at me.text
Try to rename: change my name.file
Try to remove: ??? can you delete me ???.abc
Try to compress: compress this file.data

More likely than not, you will experience some problems dealing with these files under normal means. A real aggravation.

What's the problem? The UNIX shell, like many other command-line oriented environments, uses the space as an argument separator. So when you try to cat, mv, gzip, or rm these troublesome files, the shell will try to interpret the single long file name as separate individual names.

look at me.text is the actual name of the file, but when given as an argument to cat, it will try to separately open the files:

  • look
  • at
  • me.text

There are ways to deal with such files. (Thank goodness!)

In the UNIX shell, there are several special characters that can be used on the command line to accomodate these awkward conditions. These characters harbor special powers that can be used to change the behavior of items typed. Some of these characters are displayed in the following table:

Character Behavior
* wildcard for zero or more of “any” character
\ escape the following character
“ ” (or ' ') quote the enclosed characters

Therefore, to take control of look at me.text with the cat utility, change into the example/ subdirectory and do the following:

lab46:~$ cd badname/example
lab46:~/badname/example$ cat look*

or…

lab46:~/badname/example$ cat "look at me.text"

or…

lab46:~/badname/example$ cat look\ at\ me.text

In each case you are properly instructing the shell how to display the file.

You should now have the ability to handle these malformed or inappropriately named files. So the best way to familiarize yourself with these new capabilities is to play with them.

Exercise

Using the three special characters outlined above, I'd like you to perform the appropriate operations on the files in the exercise/ directory. (In most cases, being able to view their contents will be sufficient).

Change into the exercise/ subdirectory and have fun.

1. Using the * wildcard:
a.Choose at least 3 files and attempt to gain access to their contents.
b.Submit the successful command-lines and detail and interesting observations you made.
2. Using the \ escape character:
a.Choose at least 3 files and attempt to gain access to their contents.
b.Submit the successful command-lines and detail and interesting observations you made.
3. Using the shell quoting facilities:
a.Attempt to do the same for the remainder of the files.
b.Show me the successful command-lines, and explain any observations you made.

NOTE: You may need to combine some of these special characters to accomplish the task. My intention is for you to give all of them a fair trial, not just rely on one. And do not use shortcuts such as “Tab Completions”. They are useful outside of the assignment, but here I want you to show me you understand the logic behind it.

4. Do the following:
a.Change into the challenge/ subdirectory.
b.Remove the file (and ONLY the file) located there.
c.Tell me how you were able to accomplish this.

NOTE: For the challenge, do NOT use the -r argument to rm(1).

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/fall2022/unix/cs/cs2.txt · Last modified: 2013/09/17 06:40 by 127.0.0.1