0

I have a remote directory with read access. I want to generate a list of files that changed since last iteration.

My idea is something like:

$ cp output.new output.old
$ ll > output.new
$ diff output.new output.old > list.files

The idea is that list.files have just the name and relative path of new files or files with different "modified timestamp" like this:

file1
files2
dir1/file3
dir2/file4

So I'm asking about diff and ls parameters.

slm
  • 369,824

1 Answers1

0
#!/bin/sh

topdir=/some/directory
stampfile="$HOME/.stamp"

if [ -f "$stampfile" ]; then
    find "$topdir" -type f -newer "$stampfile"
fi

touch "$stampfile"

This little script would maintain a timestamp file that would get updated each time the script is run. It would find all files in the $topdir directory that has a modification timestamp newer than the timestamp file in $stampfile.

The first time this script is run, the timestamp file would not exist, so the script would not output anything. On subsequent runs, the script would list modified files since the last run.

Kusalananda
  • 333,661
  • I wanted to suggest something like this, but held off at remote directory with **read** access -- might be worth clarifying whether they can touch a remote file. – Jeff Schaller Jul 05 '18 at 16:13
  • 1
    @JeffSchaller The timestamp file would be written to some place with write access. The suggested set of commands in the question actually assumes write access in the directory, and also assumes direct access to it (possibly mounted, it doesn't say). This could be a script on a remote server, executed vie ssh as well. – Kusalananda Jul 05 '18 at 16:26
  • "find -newer" works like a charm! – Martin R. Jul 05 '18 at 18:17