1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Natalka [10]
3 years ago
14

Write a Bash script that takes the name of a file or directory as an argument, 1. reports if it is a directory or a file, and if

the user has read, write and execute permission on the file or directory, and 2. if it is a file, reports the size of the file and the category of the file based on its size. If the file size is greater than 1MB (1048576B), the file is a large file; if the file size is less than or equal to 1MB (1048576B) and the file size is greater than 100KB (102400B), the file is a medium file; otherwise, it is a small file. Use a sequence of if statements on the file name or file size to determine the information. To get the file size, use command du -b and command cut. Read their manual for how to use them.

Computers and Technology
1 answer:
Alla [95]3 years ago
4 0

Answer:

see explaination

Explanation:

#!/bin/bash

mkdir sampleDir #I am just creating sample Directory

touch sampleFile #Creating sampleFile

echo 'Adding some information' >> sampleFile

cat sampleFile

echo "Listing the contents of the current directory:"

ls

file_size_kb=`du -k sampleFile | cut -f1` #Stores file size in KB, 1024KB = 1MB

echo $file_size_kb

if [ -d $1 ]; then

echo "It is a directory"

if [ -w $1 ]; then

echo "It has write permission"

fi

if [ -x $1 ]; then

echo "It has execute permission"

fi

if [ -r $1 ]; then

echo "It has read permission"

fi

if [ $file_size_kb -lt 1024 ]; then

echo "Small file"

elif [ $file_size_kb -gt 1024 ]; then

echo "Large file"

elif [ $file_size_kb -le 1024 && $file_size_kb -ge 1024 ]; then

echo "Medium file"

fi

elif [ -f $1 ]; then

echo "It is a file"

if [ -w $1 ]; then

echo "It has write permission"

fi

if [ -x $1 ]; then

echo "It has execute permission"

fi

if [ -r $1 ]; then

echo "It has read permission"

fi

if [ $file_size_kb -lt 1024 ]; then

echo "Small file"

elif [ $file_size_kb -gt 1024 ]; then

echo "Large file"

elif [ $file_size_kb -le 1024 && $file_size_kb -ge 1024 ]; then

echo "Medium file"

fi

fi

Check attachment for output and screenshot

You might be interested in
It is safe to use your bright headlights if there is a car ahead of you within 300 feet
11Alexandr11 [23.1K]
The answer to that would be no
3 0
4 years ago
Read 2 more answers
If you were looking for a record in a very large database and you knew the ID number, which of the following would be the most d
dezoksy [38]

Answer:

By the record ID

Explanation:

5 0
4 years ago
Write the definition of a function that takes as input the three numbers. The function returns true if the first number to the p
sattari [20]

Answer:

I am writing a C++ program.

Here is the function CheckPower() which is a bool return type function which means it will return either true of false. This function has three double type parameters. This function returns true if the first number to the power of the second number equals the third number; otherwise, it returns false.

bool CheckPower(double number1, double number2, double number3)

{

   double power; // stores value of number1 to the power number2

   power = pow(number1,number2); // pow() function to computer power

   if (power==number3) // if the value of power is equal to third no number3

       return true; // returns true

   else // if above condition evaluate to false then returns false

       return false;

}

Explanation:

Lets take the values of number1 = 3, number2 = 2 and number3 = 9 to understand the above function.

The pow() function is a power function to calculate the result of number1 raised to the power of number2. Here number1 is the base number and number2 is exponent number. As number1 = 3 and number2 = 2 so this is equivalent to 3² . So 3 raise to the power 2 is 9. The value stored in power is 9.

power = 9

Next, the if condition checks if the value in power is equal to the value of number3. The value of number3 is 9 and the value in power variable is also 9 so the If condition evaluates to true. So the if part is executed which returns true.

If the value of number3 is, lets say, 10 then the If condition evaluates false as the value of power is not equal to value of number3. So the else part is executed which returns false.

If you want to see the output of this function you can write a main() function as following:

int main()

{   double num1, num2, num3;

   cout << "enter first number: ";

   cin >> num1;

   cout << "enter second number: ";

   cin >> num2;

   cout << "enter third number: ";

   cin >> num3;

   if(CheckPower(num1, num2, num3))

   { cout<<"True";    }

   else

   { cout<<"False";  }    }

This is a main() function which asks the user to enter the values of three numbers num1, num2 and num3. The if condition calls CheckPower() function to check if the first number to the power of the second number equals the third number. If this condition evaluates to true, the message True is displayed on the screen otherwise message False is displayed on output screen.

The screen shot of program along with its output is attached.

3 0
3 years ago
Why is statistics important?
kenny6666 [7]

The answer is A.؜؜؜؜؜؜؜؜؜؜؜؜؜؜؜؜؜؜

7 0
3 years ago
write an algorithm that gets the price for item A plus the quantity purchased. The algorithm prints the total cost, including a
I am Lyosha [343]

Answer:

<u>Algorithm() </u>

1. p = Enter the price of item A.

2. c = Enter the number of A’s purchased.

3. Now the price per item with tax is:

              t= p+(p*6/100)

4. The total cost of c items:  

             ct= t * c.

5. Print ct.

In this algorithm, we are taking the price per item and counting it’s cost including tax. Then we are multiplying the price per item with tax with the number of items we purchase, to find the overall cost with tax.

You may calculate the overall cost without tax as (p*c). Then you can find the overall cost with tax as ((p*c)+(p*c*6/100)), as in both way, we will get the same result.

4 0
3 years ago
Other questions:
  • ACCOUNTING
    13·2 answers
  • What is the purpose of a title slide on power point
    14·2 answers
  • If you want to emphasize the Greek root of a word in a document, which tool in Microsoft® Word could you use?
    6·2 answers
  • Service that connects on-premises software appliances with cloud based storage is ______
    10·1 answer
  • Write a program that prompts the user for the name of two files each containing a single line that represents a decimal integerc
    11·1 answer
  • Three common risk factors for young drivers and how you plan to minimize these factors.
    13·1 answer
  • Your company just installed a new web server within your DMZ. You have been asked to open up the port for secure web browsing on
    5·1 answer
  • You send a friend a private message about something personal that is going on with you. Without permission, she forwards your te
    10·1 answer
  • Describe how you will lunch a web browser using the start menu​
    6·2 answers
  • Cable inside the computer transferring data between the mother board and storage devices.
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!