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
What are the correct answers to the following questions?
Lena [83]

Answer:

1. analog sound

2. digital sound

3. pixels

4.  local area network

5.bus

6. slots

Explanation:

4 0
2 years ago
What does NBT stand for?​
Zanzabum

Answer:

National Benchmark Test

Explanation:

7 0
3 years ago
hãy soạn thảo một bản hợp đồng chuyển giao hoặc thu thập thông tin nhằm bán/ mua/ trao đổi thông tin/ tài liệu giữa hai tổ chức.
mariarad [96]

Explanation:

wuwhwhwhshahahabahsgsgagsgshshshsjeushsjsjsiajausudid

idirieieirieeie

iep

7 0
2 years ago
1. W jaki sposób można wyrównać tekst po wstawieniu tabulatora?
Advocard [28]
I would say the correct answer is #1.
5 0
3 years ago
Add three methods to the Student class that compare twoStudent objects. One method (__eq__) should test for equality. A second m
shusha [124]

Answer:

class Student(object):

def __init__(self, name, number):

self.name = name

self.scores = []

for count in range(number):

self.scores.append(0)

 

def getName(self):

 

return self.name

 

def setScore(self, i, score):

 

self.scores[i - 1] = score

 

def getScore(self, i):

 

return self.scores[i - 1]

 

def getAverage(self):

 

return sum(self.scores) / len(self._scores)

 

def getHighScore(self):

 

return max(self.scores)

def __eq__(self,student):

return self.name == student.name

 

def __ge__(self,student):

return self.name == student.name or self.name>student.name

 

def __lt__(self,student):

return self.name<student.name

 

def __str__(self):

return "Name: " + self.name + "\nScores: " + \

" ".join(map(str, self.scores))

 

 

def main():

student = Student("Ken", 5)

print(student)

for i in range(1, 6):

student.setScore(i, 100)

print(student)

 

print("\nSecond student")

student2 = Student("Ken", 5)

print(student2)

 

print("\nThird student")

student3 = Student("Amit", 5)

print(student3)

 

print("\nChecking equal student1 and student 2")

print(student.__eq__(student2))

 

print("\nChecking equal student1 and student 3")

print(student.__eq__(student3))

 

print("\nChecking greater than equal student1 and student 3")

print(student.__ge__(student3))

 

print("\nChecking less than student1 and student 3")

print(student.__lt__(student3))

if __name__ == "__main__":

5 0
3 years ago
Other questions:
  • An email message form includes all of the following main areas except
    11·2 answers
  • When you select the data range for a pie chart, you should be sure to include the total cell on the worksheet?
    13·1 answer
  • What is the exact number of bits in a memory that contains (a) 128k bits?
    9·1 answer
  • _______ allow(s) you to apply colorful, eye catching designs to a presentation all at once. A. Themes B. Slide orientation C. Th
    10·2 answers
  • If you are writing an article on your favorite cuisine, which form of illustration would best fit the article?
    15·2 answers
  • Select the correct answer.
    15·1 answer
  • "What is the capital of Belarus?" is an example of what type of search query
    10·2 answers
  • A file name extension provides what information about a file?
    6·1 answer
  • Which of the following statements is true about biometrices as an authentication method
    6·1 answer
  • Select the correct answer.
    7·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!