Aliases - CSCI 330
50 points

Due Friday 9 October 2015, 5PM Friday.

What to hand in:

Email the file containing the aliases designed to solve problems described below. Also, bring to class the hard copy.

You are to create a set of aliases that act according to the descriptions listed below.

The easist way to create and edit aliases is to put them in a text file. You can then source this file to assign the aliases to the current login shell.

To source the alias file, create a text file containing the aliases you wish to use. If you named the file myaliases, then to activate the aliases, at the prompt, type:

. myaliases

The source command will read each line of the file and enter it into the command line buffer as if you were typing it in yourself. Note the commands must conform to the c-shell command line syntax.

The aliases will now be loaded into your current login shell. Test your aliases. If you find mistakes, simply edit your "myaliases" file, fix your mistakes and save. When you are ready to try the changes, run the source command again on your file and the new version of the aliases defined in the file will be loaded.

You may create intermediate aliases to help with debugging and printout.

To prepare for this assignment, do the following.

Put comments in the myaliases file before each alias. Give the problem number, a general description ( you don't have to copy the problem verbatum ) and any comments to help yourself. Put # at the beginning of the comment line. To figure out what comments to use, pretend that you were going to be a TA next year for this course and that you were going to use your assignment as a key to counsel any students asking for help. How would you describe your answers so you could understand it after a year.

When creating an alias, if possible use the environmental and local variables instead of specific values to make the aliases portable. For example, if you need to access your home directory, use the variable $HOME instead of /usr2/your_z9. This will allow your ta to test your aliases on her/his account.

Be careful to notice whether the alias has caps in its name.

1. Write the following simple aliases.

2. Write an alias called What that determines the type of file that a filename points to and if the filename itself is a symbolic link and prints the appropriate messages about what it found. What should recognize regular, directory, an or other filetypes. If it does not recognize the filetype, it should also say so. It should also recognize if the filename does not exist or points to (symbolic) a non-existant file.

This problem is best done by combining several small aliases.

The above logic order is a suggestion. Keep in mind that the order of the tests can simplify the logic.

To test What:

3.(6) Write an alias called Rm that will remove filename specified if it is a regular file. Before removing the file, RM should check the link count of the file and the link count is greater than one, inform user and run the interactive version of rm.

The Rm alias must do the following steps. (remember aliases are one line command sequences, DO NOT use the c-shell script code)

Test for the existence of the file as a regular file. (use test)
If it exists as a regular file,

Endif

Remember one of the short comings of hard linking was that a file with multiple links is not destroyed until all links are deleted. This alias will warn you if a file may have more names associated with it.

To test for the link count, do a long listing and cut the columns (do at least two columns) containing the link count. If the value in those columns is greater than one, then do the conditional remove after informing the user.

You may want to create two additional aliases. One just to test of the link count of the specified file. And the other to print the message and run the conditional delete.

4.(7) Write an alias called Del that removes a file by moving its hard link to the junk directory under a new name. This new name consists of the name of the original file (discard the path info) and an added extension consisting of a number. The filename supplied to del may include path info which must be removed when copied to junk. To generate the number for the extension, call the tstamp alias

To run this alias, you must have a directory called junk in your home directory. If it does not exist, create it and make it fully accessable only to you.

You will be using one or more of the aliases created in problem 1.

The Del alias must perform the following actions.

When you test for your junk directory, use $HOME variable for name of the home directory , DON'T hard code path, append junk to the contents of $HOME

If the junk directory is not in user's home directory or is not usable (use dirchk and possibly rearrange the logic).

Otherwise endif

The filename specified may be path qualfied, so you will have to use the history mechanism to slice and dice.

5.(6) Write an alias called capit that converts all the letters in lower case to upper case. Use tr to translate characters. Because tr creates a new file, you need to do the following.

(Note in the following, "original" represents the name specified as the first argument of the alias, Do not hard code the word "original" in the alias )

Use rfilechk to check that "original" is a regular file and accessable.
If accessable regular file

endif

6.(6) Write an alias called findit that uses find to search from the directory specified as the 1st argument on the command line and looks for the file specified as the 2nd argument on the command line. Redirect find's output to to the screen, pausing between screens. However, redirect any error messages to /dev/null

7.(6) Write an alias called dups that finds the inode of the file specified as the 2nd argument on the command line and looks for any other filenames linked to the same inode number. The 1st argument on the command line is to specify the directory it is to start looking in. If a match is found, offer to delete it. (see the -ok option of find)

To simplify the dups alias, create an alias called cutit that gets the inode of the specified file. Make dups invoke cutit when you need the inode id.