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
  • 363,520
  • 117
  • 767
  • 871
Martin R.
  • 3
  • 1
  • What exactly are you trying to do? regardless of what it is, `diff`ing the outputs of `ls -l` is unlikely to be a robust way to do it - look at something based on `rsync`, `inotify`, or even `find -mtime` – steeldriver Jul 05 '18 at 14:43
  • I want to run a proccess every 10 minutes and proccess new or changes files. – Martin R. Jul 05 '18 at 15:00
  • 1
    find seems to be a much viable option. – Martin R. Jul 05 '18 at 15:01
  • See for example the highest-voted couple of answers at [Script to monitor folder for new files?](https://unix.stackexchange.com/questions/24952/script-to-monitor-folder-for-new-files) – steeldriver Jul 05 '18 at 15:09

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
  • 320,670
  • 36
  • 633
  • 936
  • 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