Please type out and post No pictures, please. Write a Perl script to calculate t
ID: 3749129 • Letter: P
Question
Please type out and post No pictures, please. Write a Perl script to calculate the following.
Write a Perl script to do a little file count report for a given directory, as shown in the following figure. a) You may use a command argument to supply the directory you want to report b) Hint: use ls, grep, wc, regex, and pipe " root@ubuntuo:-/Documents/script Eile Edit View Serch erminal Help root@ubuntue:-/Documents/script bash dir-stat.sh Files in /root: Number of all items: 45 Number of all directories: 28 Number of all ordinary files: 17 Number of hidden items: 31 Number of hidden directories: 20 Number of hidden files: 11 root@ubuntu:/Documents/scriptaExplanation / Answer
$n1=$ARGV[0];
#The above is used for perl command line argument
$command = "ls -l $n1|grep -E '^-|^d'|wc -l";
print "Number of all items: ";
$count = system($command)-1;
#The above is used to dipslay files or directories(grep -E '^-|^d'|wc -l) and count them(wc -l)
#$command is used to execute linux command in perl
$command = "ls -l $n1|grep '^d'|wc -l";
print "Number of all directories are: ";
$count = system($command);
$command = "ls -l $n1|grep '^-'|wc -l";
print "Number of all ordinary files: ";
$count = system($command);
$command = "cd $n1;ls -d .[^.]*|wc -l;cd 2>&1";
print "Number of hidden items: ";
$count = system($command);
$command = "cd $n1;ls -ld .[^.]*|grep '^d'|wc -l;cd";
print "Number of hidden directories: ";
$count = system($command);
$command = "cd $n1;ls -ld .[^.]*|grep '^-'|wc -l;cd";
print "Number of hidden files: ";
$count = system($command);