Question
The Linux mv command has, more or less, the following behavior (taken from https://linux.die.net/man/1/mv) [I have simplified and modified]: mv [ OPTION ]... SOURCE ...
The Linux mv command has, more or less, the following behavior
(taken from https://linux.die.net/man/1/mv) [I have simplified and modified]:
mv [OPTION]... SOURCE... DIRECTORY
mv [OPTION]... -t DIRECTORY SOURCE
mv SOURCEFILE DESTFILE
Rename SOURCEFILE to DESTFILE, or move SOURCE(s) to DIRECTORY.
Options:
-b[=CONTROLFILE]
make a backup of each existing destination file.
Take backup directives from stdin or from file CONTROLFILE which is optionally given
-f
(standing for force) do not prompt before overwriting
-i
(standing for interactive) prompt before overwrite
-n
(standing for no-clobber) do not overwrite an existing file
If you specify more than one of -i, -f, -n, only the final one takes effect. Default: -n
-t DIRECTORY
move all SOURCE arguments into DIRECTORY
-u
(standing for update) move only when the SOURCE file is newer than the destination file or when the destination file is missing
-h
display the following help and exit. Do not process any other options.
mv [OPTION]... SOURCEFILE... DIRECTORY
mv [OPTION]... -t DIRECTORY SOURCEFILE
mv SOURCEFILE DESTFILE
Rename SOURCEFILE to DESTFILE, or move SOURCEFILE(s) to DIRECTORY.
-b[=CONTROLFILE] make a backup of each existing destination file. Take backup
directives from stdin or from a file CONTROLFILE which is optionally given
-f do not prompt before overwriting
-i prompt before overwrite
-n do not overwrite an existing file.
If you specify more than one of -i, -f, -n, only the final one takes effect. Default: -n
-t DIRECTORY move all SOURCE arguments into DIRECTORY
-u move only when the SOURCE file is newer than the destination file or when
the destination file is missing
-h display help and exit
You are to write the option processing part of this command according to these specs. (You do not need to implement the actual command except for the -h option.) Your program should simply claim, (falsely, of course,) that it is doing so and so, according to the invoking options.
Invalid invocations should get a message:
mv: invalid usage
type mv -h for help
mv -h should display usage as above, overriding and ignoring any other options
Otherwise, the output from your program should be reprinting the command line as entered by the user and reporting the [alleged] behavior of the program in response to those options.
Examples:
input:
mv -b=ctrlFile -t file0 file1 file2 file3
output:
mv -b=ctrlFile -t file0 file1 file2 file3
moving files file1 file2 file3 to directory file0
control file ctrlFile
input:
mv -f -u file0 file1 file2 file3
output:
mv -f -u file0 file1 file2 file3
moving files file0 file1 file2 to directory file3
forcing unless later date
input:
mv -u -t drctry file1 file2 file3
output:
mv -u -t drctry file1 file2 file3
moving files file1 file2 file3 to directory drctry
unless later date
input:
mv -i file1 file2
output:
mv -i file1 file2
moving file1 to file2
interactive
input:
mv -n file1 file2
output:
mv -n file1 file2
moving file1 to file2
no-clobber
input:
mv file1 file2
output:
mv file1 file2
moving file1 to file2
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started