LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 924|回复: 0

国外UNIX硕士课程英文原版题(转)

[复制链接]
发表于 2005-4-24 22:34:49 | 显示全部楼层 |阅读模式
国外UNIX硕士课程英文原版题,希望大家讨论一下,

The aim of this assignment is to develop a working (shell) script called archive to perform the following functions.

Part 1: Individual directory archive function: This function archives in tar format the files in a given directory that qualify for archiving (see below the complete specification for qualification) and stores the tar file in the back_up sub-directory which is located in the home directory of the user. The name of the tar file will be current date.tar. The current_date is specified as ddmmyy.
Part 2: Directory and their subdirectories: This function archives in tar format the files that qualify for archiving in a given directory and their sub-directories (if exists). The name of the tar file is the directory name_current_date.tar. . The current_date is specified as ddmmyy. This function is achieved by a –r option in the command line when you invoke the script.
Part 3: Perform either part 1 or part 2 and archive those files that are modified from the last date when archiving was performed. The information about when was the last time the archive was done can be stored in a file, if required.  

The files that qualify for archiving are determined based on the options that are provided to the script. Each option (a single character) is prefixed by a minus sign (the Unix convention) and a value will follow the option (if applicable). You can assume one or more spaces between the option and the value. Parsing and error messages need to be provided by the script if the option value is not valid. Multiple options (some can repeat – see the examples below) can be provided and you have to decide the semantics of the interpretation.

1. Those files whose modification date is before the specified date are archived. There are two ways by which the date can be specified – (i) -d mmyy (ii) -m mm –y yy . In the former option, the date is specified as a 2 digit month and 2 digit year together, while in the latter the month and year are specified separately. Note the spaces between the option and the value. In the latter option it is possible that one of the options (either –m or –y ) may not be specified, in which case you have to assume a default value (such as the current month or current year depending on what is not specified) or provide appropriate error message(s). The current year and month to be used as the default value if the date option is not specified.

2. The directory is specified by –d dir_name option and the files from this directory (and its sub-directories for Part 2) will be archived. If the directory is not specified, then the current (present working) directory is used.

3. –r option performs the part 2 functionality while the absence of –r performs the part 1 functionality of the script.

4. In addition to the above options other three options may be specified to the script and they are:
o -i option with no argument asks the user whether to archive the file or not by displaying the first 5 lines of its contents (what happens when the file is a binary file?).
o –n option prints a final count of number of files being archived.
o –v option invokes the script in the verbose mode. In the verbose mode one line of information that contains the name of the file, possible date of last modification in some format for each of the archived file is displayed.
o -? Option prints a help screen on how to use your script.

Some Examples (In the following examples, the command is given in bold, the output in courier and the comments enclosed in between / # :
$ archive -n –y 04 –d Tutorial
/# archive all file in the Tutorial sub-directory whose modification date is before March (the current month) 2004 and provide a count at the end of the execution #/
10 files archived
$ archive –v –d 0205 –d Tutorial
/# archive files from the Tutorial sub-directory whose modification date is before Feb 2005 in a verbose mode – meaning display a line of information about each file that is being archived #/
exercise1: last modified 2001 MAY
trial: last modified 2002 JAN
core: last modified 2003 FEB
exercise5: last modified 2004 JAN
$ archive -d 0304 –n ./Tutorial
/# archive files in the Tutorial sub-directory whose modification date is before March 2004 and provide a count at the end of the execution #/
10 files archived
$ archive –m 02 –y 04 –m 03 –r –y 03 –d Tutorial
/# here the same option is specified more than once. It is left to you to decide whether to accept this or reject this. If you decide to accept this, then you need to decide which date to use. I will use the latest date in the input - i.e the date will be March (03), 2003. The –r options requires that the scripts has to scan all the files in Tutorial sub-directory as well as its sub-directories #/
$ archive –h
/# will list some help on how to use the script #/
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表