Corning Community College
UNIX/Linux Fundamentals
Case Study 0x2: Unconventional Naming
~~TOC~~
To see an importance in holding certain conventions, and how to deal with situations that deviate in some way.
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:
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.
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).
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.