For example, the feh program can delete the currently viewed image, presumably using the rm command at some point. Let's say that instead of deleting the file, we want to run a trash script, say trash.sh. Is there anyway of running feh but tricking it into running trash.sh every time it calls rm?

  • It is exceedingly unlikely that a program, like feh, would be running the system rm command.
    – terdon
    Commented Sep 18, 2023 at 14:48
  • Use the program exclusively on temporary copies of files? Unbind the Ctrl+Delete action? As terdon says, it's unlikely that it calls the external rm command for removing images.
    – Kusalananda
    Commented Sep 18, 2023 at 14:49
  • Most programs ultimately delete files using the unlink(2) system call. It is possible to intercept this using function interposition, but that's almost never the correct answer (and it may not be 100% effective, and may have lots of edge cases around properly dealing with temporary files, etc).
    – larsks
    Commented Sep 18, 2023 at 16:40

1 Answer 1


You need to modify the sources of feh and run an arbitrary script instead of unlink() system call in C language, then compile new code:

git clone https://github.com/derf/feh.git
cd feh
cat<<EOF > trashbin.patch
--- src/filelist.c  2023-09-18 23:19:53.444892742 +0200
+++ src/filelist_new.c  2023-09-18 23:19:11.293556737 +0200
@@ -112,7 +112,11 @@
 gib_list *feh_file_rm_and_free(gib_list * list, gib_list * l)
-   unlink(FEH_FILE(l->data)->filename);
+   //unlink(FEH_FILE(l->data)->filename);
+    char command[255];
+    sprintf(command, "/usr/local/bin/trashbin.sh %s", FEH_FILE(l->data)->filename);
+    system(command);
    return(feh_file_remove_from_list(list, l));

patch src/filelist.c < trashbin.patch
sudo make install

Then, create:


with what you want, like


mkdir -p ~/.local/trashbin
/bin/mv -- "$@" ~/.local/trashbin

You must log in to answer this question.

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