As part of my OS class I am exposing students to Linux and some coding. Students are submitting their program in a specified directory and name in their own account (e.g., ~/Prog1/Prog1.java). They can submit programs up to two days late.

I want to be able to avoid them modifying their programs after their "submission". My first thought is to disable or hide the touch command so that they can't fudge the time stamp for the file when I check with ls -l, but is that sufficient? Are there other relatively simple ways for them to sneak in a modification in their source without me being able to detect it? They are new to Linux - so not very knowledgeable.

Or is there a way for me to create a write-only directory so that they can copy their programs into it, but not modify the time stamp? Is there an easier way I'm not considering?

This is the RedHat 7.5 flavor of Linux.

I thought about posting in https://superuser.com/ or https://cseducators.stackexchange.com/ and I'd be happy to move my question there if that's more appropriate, though it fundamentally strikes me as a Linux question.

Would examining the change/modification time that stat gives me be a fool-proof way for me to make sure files hadn't been messed with after submission?

  • 1
    A non-answer / work-around suggestion: capture the ls -l output of the directories on the due date and/or 2 days later; then you'll know who had their files in, and when. – Jeff Schaller Sep 29 '17 at 1:38
  • Are you admin on the machine? Are they? – Stéphane Chazelas Sep 29 '17 at 14:44

You could easily take ownership of the specified folder, and in the same time allow them to check there work.

To take ownership of the folder: chown teacher /path/to/file.java

And, to disallow any changes by non-owner account: chmod go-w /path/to/file.java

Now, to automate this, use the command at to run a code job, For example:

at 10am Jul 31, then you will be present with a new command line at>. From there just input the previous chmod & chown commands, and they will run from there.

Just a note, run at command with super user root.

| improve this answer | |

You may be looking for the chattr command that can make a file immutable. From man chattr:

A file with the 'i' attribute cannot be modified: it cannot be deleted or renamed, no link can be created to this file and no data can be written to the file. Only the superuser or a process possessing the CAP_LINUX_IMMUTABLE capability can set or clear this attribute.

  • to set the immutable attribute:

    chattr +i ~/Prog1/Prog1.java
  • to remove the immutable attribute:

    chattr -i ~/Prog1/Prog1.java
  • to see the current attributes, you can use lsattr (note that your students could also use this command to see that the immutable attribute is set):

    lsattr ~/Prog1/Prog1.java

You will also need to add a cron job to monitor the submission folders for new files during your 2-day submission time interval.

| improve this answer | |
  • Note that the immutable flag doesn't prevent modification via file descriptors that had been opened to the file prior to the flag being added. – Stéphane Chazelas Sep 29 '17 at 14:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.