0

I'm running a script on synology (NAS) that is deleting files older than x days on certain folders.

The problem is that I want these files to be deleted after X days of being uploaded on the folder.

So I thought of using ctime, mtime, or atime, but the problem is that these are based on file change time, file modify time or file accessed time. Accessed time doesn't work for me, and modify time doesn't work because the files that I am uploading on Synology "import" the modify file time from Windows (sometimes very old times).

Does anyone know a solution?

2
  • 3
    Shouldn't ctime be relatively unchanging, if the files aren't modified or moved? If the timestamps don't work, you could see if you can touch the files while uploading, or save them in directories named after the date?
    – ilkkachu
    Commented Jul 27, 2016 at 17:28
  • Yes ctime should be the time when the file was uploaded. Could you run this and have a look: for F in *; do stat -c %z\ %n $F ; done | sort -r
    – hschou
    Commented Jul 27, 2016 at 23:14

1 Answer 1

2

Since you cannot use any of the file timestamps, you have to use another approach. These are the usual alternatives:

  • use a naming convention (embedding the timestamp in either the filenames, or the directory names), or
  • storing a timestamp in a related file, e.g., a hidden (dot-file) in the same directory which can be checked with a script
  • maintain a database which records the date on which files are uploaded, and use that to control when they expire
2
  • The timestamp could also be stored in an extended attribute on the file upon upload which would ensure it stays with the inode/file (follows renames, are gone when the file is removed). Commented May 9, 2017 at 14:21
  • Here, the OP could also use the birth time (stored on most native filesystems on Linux, but you need a very recent version of Linux (4.11) to get an API to retrieve it (though, it is possible offline with some debugfs tools with older versions)). Commented May 9, 2017 at 14:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .