Question

drwxr-xr-x 10 mst staff 320 Sep 18 14:58 Sites drwxr-xr-x 2 mst staff 64 May 28...

drwxr-xr-x 10 mst staff 320 Sep 18 14:58 Sites

drwxr-xr-x 2 mst staff 64 May 28 2017 VirtualBox VMs

-rw-r--r-- 1 mst staff 633 Dec 11 2019 balance.pl

drwxr-xr-x 4 mst staff 128 Oct 11 2014 bin

-rw-r--r-- 1 mst staff 473 Dec 13 2019 bitshift.py

For this problem, we are mainly concerned with the set of access permissions, which appears at the beginning of the line for each file or directory. Directories have a "d" at the beginning of their permissions list; files have a dash ("-") at the beginning of their permissions list instead. In the example above, "Sites", "VirtualBox VMs", and "bin" are directories, while the other lines/entries are files.

The list of permissions is a ten-character sequence: the first character indicates whether this item is a file or a directory, while the remaining nine characters indicate permitted actions (read, write, and execute, in that order) for three user types ("owner", "group", and "world", respectively). A letter indicates that the current category of user has that specific type of permission; dashes indicate that the current category of user does not have that type of permission. For example, "rw-" indicates that a particular category of user can read and write (modify) a particular file, but cannot execute it.

As a more complete example, the "bin" directory listed above has the permissions drwxr-xr-x. Translated:

  • The leading "d" tells us that "bin" is a directory, not a file.
  • The first three permission characters ("rwx") tell us that the directory's owner (user "mst") has read, write, and execute permissions.
  • The next three permission characters ("r-x") tell us that members of the group "staff" have read and execute permissions for this directory, but cannot write to it.
  • The final three permission characters in this case are also "r-x", indicating that "world" users (users who are not the owner and do not belong to the "staff" group) also have read and execute permissions for this directory, but cannot write to it

In the code cell below, write some Python code that reads a single line of input from the user, corresponding to a single line of output from the ls command, in the format shown above.

  1. If the line represents a directory (e.g., begins with "d"), print the exact text "X is a directory" (wthout the quotes), where X is the name of the directory. Otherwise, print the exact text "X is a file" (without the quotes), where X is the name of the directory.

Hint: The rfind() command may be useful here. Assume that the file or directory name DOES NOT contain any spaces!

  1. For each of the three characters that make up the "group" permissions, if the character is NOT a dash, print a separate line of the form "Group members have X permission", where X is replaced with the appropriate type of permission. This means that you may have anywhere from 0-3 lines of text, depending on the combination of permissions (if the permissions are ---, then you won't print anything for this part).

For example, given the following string input:

-rw-r--r-- 1 mst staff 473 Dec 13 2019 bitshift.py

your code should produce the following (exact) output:

bitshift.py is a file

Group members have read permission

and nothing else.

Homework Answers

Answer #1
Below is a screen shot of the python program to check indentation. Comments are given on every line explaining the code.

Below is the output of the program:
Output 1:

Output 2:

Below is the code to copy:
#CODE STARTS HERE----------------
#Enter input here
inp = "-rw-r--r-- 1 mst staff 473 Dec 13 2019 bitshift.py"
print("Input: ", inp,"\n") #Printing the input for reference
#Extract name by spliting the string by spaces and taking the last word
name = inp.split()[-1]
#Extract the permession by splitting the string by spaces and taking the first part
permession = inp.split()[0]
#Group permession is the 5-7 characters in "permession" string
group = permession[4:7]

if permession[0] == 'd': #Check if directory or file
   print(name,"is a directory")
else:
   print(name,"is a file")

if 'r' in group: #Check for read permession
   print("Group members have read permission")
if 'w' in group: #Check for write permession
   print("Group members have write permission")
if 'x' in group: #Check for execute permession
   print("Group members have execute permission")
#CODE ENDS HERE-----------------
Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Linux, please avocado is an empty file Q14 – Specify a single line command that gives...
Linux, please avocado is an empty file Q14 – Specify a single line command that gives the owner and group permission to execute the file avocado while giving the owner sole permission to read and write the file. Do not change any other permission, i.e., do not remove permission from others to execute the file, if they already have that permission. Q15 – File/directory permissions are subject to permissions on the parent directories. For example, consider the file /home/dv35/cs265/lab1.txt. If...
Linux Operation SECTION 2 – File and Directory Permissions: FILE PERMISSIONS: What is the command used...
Linux Operation SECTION 2 – File and Directory Permissions: FILE PERMISSIONS: What is the command used to find out which user account you are logged into?      . This command may come in handy in the following exercises. Ensure you are in your home directory of the student1 account. Use the echo command with output redirection to create a file called labfile4 and put the following text in this file: “This is the first line of labfile4”. Using the symbolic notation...
Write a command sequence or a script to insert a line “GHIJKLM” at every 10th line...
Write a command sequence or a script to insert a line “GHIJKLM” at every 10th line of a file? I am using this on Docker Quickstart Terminal version 19. I can't seem to execute it on the command line or get it to work. I'm not sure what I have to fix. This is what I have written so far. ---------------------------------------------------- JennyM07@DESKTOP-3XD60LM MINGW64 ~/CIT270/Lab_1$ ls -l total 1 -rwxr-xr-x 1 JennyM07 197121 100 Aug 26 21:41 file8.sh* -rw-r--r-- 1 JennyM07...
You will write a program that loops until the user selects 0 to exit. In the...
You will write a program that loops until the user selects 0 to exit. In the loop the user interactively selects a menu choice to compress or decompress a file. There are three menu options: Option 0: allows the user to exit the program. Option 1: allows the user to compress the specified input file and store the result in an output file. Option 2: allows the user to decompress the specified input file and store the result in an...
Chapter 8: Searching, Extracting, and Archiving Data Exercise 8.a: Using grep, find, and regular expressions (Objective...
Chapter 8: Searching, Extracting, and Archiving Data Exercise 8.a: Using grep, find, and regular expressions (Objective 3.2) Linux Distribution: Fedora (non-root user & password needed) Desktop Environment: GNOME 3 1.   If you have not already done so, boot up your computer (or virtual machine) to start the Fedora Linux distribution. 2.   When the machine has booted up, access the tty2 virtual terminal by pressing Ctrl+Alt+F2. 3.   Log on to a regular user’s account by typing in the username at the...