0

To keep track of newly added files in a directory (and it's subdirs) I want to use entr

ls -d /tmp/*  | entr -p notify-send "new file added."

But when I add new files to /tmp/ or /tmp/foo/ nothing happens. What am I doing wrong?

xcy7e
  • 159
  • 1
  • 9

3 Answers3

0

Is there a particular use case for using entr ? It is generally strongly discouraged to parse ls:
Why *not* parse `ls` (and what do to instead)?

I think in your case you would be better off using incrond:
https://www.howtoforge.com/tutorial/trigger-commands-on-file-or-directory-changes-with-incron/ (IN_CREATE would be of particular interest to your situation)

To my knowledge incrond is not able to watch subdirectories, so if you need to also watch all subdirectories of /tmp, maybe watcher is more suited to your situation:
https://stackoverflow.com/questions/44088179/watch-a-subdirectory-with-incron

Word of caution, without knowing your special use case: /tmp is used by all kinds of processes. It may not be very wise/practical to try and track all of its changes.

  • I want to get notified about incoming email (offlineimap). ls is not a must, but entr seems to be easier to setup on screen notifications – xcy7e May 01 '19 at 17:22
0

Type

ls -d /tmp/* | entr -p echo "New File"

on one pane.Then on another pane type

echo "hello" > /tmp/test123456.txt

Notice that 'New File' is echoed on the first pane

0

I am using this to update an html version of a markdown text:

# Preview a comment written in Markdown
cpv() {
    echo ">INFO> Refreshing preview"
    find | entr -d generate_comment_preview.sh
}
cpvr() {
    cpv
    if [[ $? > 0 ]]; then
        echo ">INFO> Launching cpvr again"
        cpvr
    fi
}

Then I open the file with Epiphany (gnome-web) and it refreshes automagically.

pabgan
  • 1
  • 1