CT320: Network and System Administration

Fall 2018

Python

CT320: Python

Python Programming Lab

The purpose of this assignment is to learn how write basic scripts using the Python programming language.

Documentation

Part 1 — Simple Python Script

Here is a program named “walk“. Your TA will discuss it.

    #! /usr/bin/python3

    import os

    for dirpath, directories, files in os.walk("."):
        for f in files:
            fpath = dirpath + '/' + f
            st = os.stat(fpath)
            mode = st.st_mode & 0o777
            print("%o" % mode, fpath)
  1. What does import do?
  2. What does os.walk return?
  3. What does 0o777 mean?
  4. What does the % operator do?

Part 2 — Run it

Copy & paste the script, above, to your system (beware of tabs) and make sure that it runs properly.

Part 3 — Ignore dot-files

Add code to ignore files that begin with a dot, e.g., .bashrc.

Part 4 — ls-like output

Add code to print the file protection bits in the style of ls -l, e.g., -rwxr-xr--

Part 5 — Privacy

You’re concerned about others reading your secret files. Add code to complain, to standard error, for each file that is publicly readable, writable, or executable.

Part 6 — Less privacy

Add code to not complain (see above) if the file .public exists in the same directory as the file that is publicly readable/writable/executable.

Part 7 — Directories, too

Hey, we’re only listing plain files, not directories! Modify your program to also list directories.

Part 8 — Modification time

Show the modification time for the files.

Part 9 — Credit

Show your work to the TA.

User: Guest

Check: HTML CSS
Edit History Source

Modified: 2017-10-28T15:54

Apply to CSU | Contact CSU | Disclaimer | Equal Opportunity
Colorado State University, Fort Collins, CO 80523 USA
© 2018 Colorado State University
CS Building