samedi 29 novembre 2014

unix Write a program that takes any number of directory names as command line arguments?


Write a program that takes any number of directory names as command line arguments and an output filename as a last argument. The program checks that there are at least 2 command line arguments, at least one directory name and one output file name. The program produces one number for each directory -- the total number of bytes of all files in that directory, or zero if the directory could not be opened. Warn the user if a directory could not be opened and then move on to the next directory. Print all good output to the output file. Sample output:



$ lab6.pl dir1 ../dir2 dir3 outf
cannot open dir3:No such file or directory
$ cat outf
dir1: 4310 total bytes.
../dir2: 6579 total bytes.
dir3: 0 bytes.
$ ls -la dir1 | awk '{b += $5} END {print b}'
4310
$ ls -la ../dir2 | awk '{b += $5} END {print b}'
6579


Aucun commentaire:

Enregistrer un commentaire