CSE 2031 - Lab Test 2 question

What to do

Requirements

Your script will receive 0 or 1 arguments. If there is an argument, then you can assume that it represents an accessible directory (you do not have to validate that it is indeed an accessible directory). If there is no argument, then the directory to work with will be the current working directory. Any extraneous arguments to the script are ignored.

The first task of your script is to determine the number of pairs of identical files in the provided directory. For the purposes of this test, if files a.txt and b.txt are identical, then this counts as two pairs: a.txt - b.txt, and b.txt - a.txt. See the sample run below for another example. Ignore any subdirectories. Your script must then output a message showing the number of identical pairs as in the sample run below. This is followed by a list of the pairs in alphabetical order (one pair per line). The two filenames are separated by a single SPACE.

You can assume that the filenames in the provided directory do not contain SPACES or any other special characters.

The second task of your script is to output the name of the largest file in the provided directory. Ignore any subdirectories. If there is more than one file tied for largest size, you may output any of them. If there are no files in the directory the output must be as in the second sample run.

Following are two sample runs that first show the contents of the provided directory and then the output of your script:


% ls -l dir2
total 20
-rw------- 1 bil faculty  108 Nov 30 12:53 copyoffile1
-rw------- 1 bil faculty  108 Nov 30 12:53 file1
-rw------- 1 bil faculty  108 Nov 30 12:53 sameasfile1
-rw------- 1 bil faculty 2761 Nov 30 12:52 someotherfile
drwx------ 2 bil faculty 4096 Nov 30 12:52 subdir/
% lt2m.sh dir2
Found 6 pairs of identical files
dir2/copyoffile1 dir2/file1
dir2/copyoffile1 dir2/sameasfile1
dir2/file1 dir2/copyoffile1
dir2/file1 dir2/sameasfile1
dir2/sameasfile1 dir2/copyoffile1
dir2/sameasfile1 dir2/file1
Largest file: dir2/someotherfile

% ls -l emptyd
total 0
% lt2m.sh emptyd
Found 0 pairs of identical files
There are no files in emptyd