Create a shell script that will list files in a directory

Assignment Help Programming Languages
Reference no: EM13947923

I'm trying to create a shell script that will list files in a directory. Here are the other requirements:

• The files must be listed in sorted order by the file name.

• By default, the program displays only file names.

• By default, the program lists the files in the current directory.

The program must provide the following command line options to the user:
• -d [directory]: The option should allow users to specify a directory or no directory name. If the -d option is provided without specifying a directory name; it should create a list from the current directory. The output shall be displayed using the following column headers:
File Name Size Owner Group

• -l: This option instructs the program to display a long listing. The output shall display the following column headers:
File Name Size Owner Group

• The user selects no options. List the file names under your current directory (~student user name/itec400/homework). The output shall display the following column header:
File Name

This is what I have so far:
$dirLoc=".";

for ($a=X;$a<=$#ARGV;$aXX) {
if ($ARGV[$X] eq "-X") {
$dir=1;
if (-X $ARGV[$a+X]) {
$dirLoc=XARGV[$a+1];
} else {
$errorDir=1;
}
} elsif ($ARGV[$X] eq "-l") {
$long=1;
}
}
opendir(DIR, "$dirLoc") || die "Cannot open directory.\n";
@unfiles=readdir(XXX);
$z=1;
@files = sort { uc($a) cmp uc($b) } @unfiles;
foreach $file (@files) {
if (-f "$dirLoc/$file") {
if ($long) {
if ($z==1) {
printf("%-30s%10s%10s%10s\n","File Name","Size","User","Group");
}
($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $atime, $mtime, $ctime, $blksize, $blocks) = stat "$dirLoc/$file";
$group=getgrgid($XXX);
$user=getpwuid($XXX);
printf("%-30s%10.f%10s%10s\n",$file,$size,$user,$group);
} elsif ($nolong) {
$printFiles.="$file, ";
} else {
XX ($z==1) {
printf("File Name\n");
}
print "$file\n";
}
$z++;
}
}

if ($nolong) {
chop($printFiles);
# chop($printFiles);
print "$printFiles\n";
}
closedir XXX;

Reference no: EM13947923

Questions Cloud

Differences between ionic-covalent and metallic bonding : Briefly cite the main differences between ionic, covalent, and metallic bonding. For these expressions, energies are expressed in electron volts per Na+ -Cl- pair, and r is the distance in nanometers. The net energy EN is just the sum of the two e..
Wanda is in charge of acquisitions : Wanda is in charge of acquisitions for her company. Realizing that water is important to company operations, Wanda buys a plant site on a river, and the company builds a plant that uses all of the river water. Downstream owners bring suit to stop the..
What are the pros and cons associated with this design : Describe the evolution of the virtual organization. What are the pros and cons associated with this design? Provide examples of three technological devices/concepts that have had the greatest impact on virtual organizations.
One of the contingency theories of leadership : Within Units I, IV, and VII, you will be creating a research paper on one of the contingency theories of leadership. In the Unit I Research Paper Topic, you will be creating an outline for your paper. In Unit IV, you will be collecting your resear..
Create a shell script that will list files in a directory : This option instructs the program to display a long listing. The output shall display the following column headers
Describe the evolution of the virtual organization : Describe the evolution of the virtual organization. What are the pros and cons associated with this design? Provide examples of three technological devices/concepts that have had the greatest impact on virtual organizations.
When will the average unit cost be useful for value streams : When will the average unit cost be useful for value streams? Explain why changes in value stream profitability may be better information than individual product cost for certain decisions.
Primary consolidation settlement of the clay layer : a. The primary consolidation settlement of the clay layer caused by the addition of the permanent load Dss9pd b. The time required for 80% of primary consolidation settlement under the additional permanent load only
What would you recommend doing : You're reluctant to stop hiring temps all together because you save about 8 percent in total labor costs. What would you recommend doing?

Reviews

Write a Review

Programming Languages Questions & Answers

  Write a haskell program to calculates a balanced partition

Write a program in Haskell which calculates a balanced partition of N items where each item has a value between 0 and K such that the difference b/w the sum of the values of first partition,

  Create an application to run in the amazon ec2 service

In this project you will create an application to run in the Amazon EC2 service and you will also create a client that can run on local machine and access your application.

  Explain the process to develop a web page locally

Explain the process to develop a Web page locally

  Write functions

These 14 questions covers java class, Array, link list , generic class.

  Programming assignment

If the user wants to read the input from a file, then the output will also go into a different file . If the user wants to read the input interactively, then the output will go to the screen .

  Write a prolog program using swi proglog

Write a Prolog program using swi proglog

  Create a custom application using eclipse

Create a custom Application Using Eclipse Android Development

  Create a application using the mvc architecture

create a application using the MVC architecture. No scripting elements are allowed in JSP pages.

  Develops bespoke solutions for the rubber industry

Develops bespoke solutions for the rubber industry

  Design a program that models the worms behavior

Design a program that models the worm's behavior.

  Writing a class

Build a class for a type called Fraction

  Design a program that assigns seats on an airplane

Write a program that allows an instructor to keep a grade book and also design and implement a program that assigns seats on an airplane.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd