Is it possible to intercept calls to unlink and redirect files to /trash?











up vote
1
down vote

favorite












I would like to know if there is a way to create a trash by intercepting calls to unlink. Theoretically files would be timestamped and deleted after set time period.










share|improve this question









New contributor




Stuperfied is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
























    up vote
    1
    down vote

    favorite












    I would like to know if there is a way to create a trash by intercepting calls to unlink. Theoretically files would be timestamped and deleted after set time period.










    share|improve this question









    New contributor




    Stuperfied is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.






















      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      I would like to know if there is a way to create a trash by intercepting calls to unlink. Theoretically files would be timestamped and deleted after set time period.










      share|improve this question









      New contributor




      Stuperfied is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      I would like to know if there is a way to create a trash by intercepting calls to unlink. Theoretically files would be timestamped and deleted after set time period.







      trash






      share|improve this question









      New contributor




      Stuperfied is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question









      New contributor




      Stuperfied is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question








      edited yesterday









      Rui F Ribeiro

      38.2k1475123




      38.2k1475123






      New contributor




      Stuperfied is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked yesterday









      Stuperfied

      63




      63




      New contributor




      Stuperfied is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      Stuperfied is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      Stuperfied is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          1
          down vote













          Yes, there is. The general mechanism for this type of thing (overriding a standard function) is called LD_PRELOAD. The general idea is pretty simple, when loading libraries into memory for a program, whichever one is the first to define a given symbol name defines what that symbol does. So, LD_PRELOAD lets you tell the dynamic linker to load specific libraries before all others (including libc), meaning that they can override specific functions from libraries which would be loaded later.



          Examples of widely used projects that make use of LD_PRELOAD include:





          • jemalloc Can be pre-loaded to let you use the jemalloc memory allocator with programs that don't explicitly use it themselves.


          • datefudge Lets you fake the system time and date.


          • libeatmydata Overrides sync() and related calls to do nothing, improving performance of some applications at the cost of data safety.


          • dante Includes a command that uses LD_PRELOAD to enable SOCKS protocol usage for applications which don't natively support it.


          There's also a library that does exactly what you're asking about called libtrash. The official web-page can be found here. I'm not sure if it works or not as I've never used it myself, but there was a recent release of a new version so it looks like the author is at least still maintaining it.






          share|improve this answer





















            Your Answer








            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "106"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });






            Stuperfied is a new contributor. Be nice, and check out our Code of Conduct.










             

            draft saved


            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f482079%2fis-it-possible-to-intercept-calls-to-unlink-and-redirect-files-to-trash%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            1
            down vote













            Yes, there is. The general mechanism for this type of thing (overriding a standard function) is called LD_PRELOAD. The general idea is pretty simple, when loading libraries into memory for a program, whichever one is the first to define a given symbol name defines what that symbol does. So, LD_PRELOAD lets you tell the dynamic linker to load specific libraries before all others (including libc), meaning that they can override specific functions from libraries which would be loaded later.



            Examples of widely used projects that make use of LD_PRELOAD include:





            • jemalloc Can be pre-loaded to let you use the jemalloc memory allocator with programs that don't explicitly use it themselves.


            • datefudge Lets you fake the system time and date.


            • libeatmydata Overrides sync() and related calls to do nothing, improving performance of some applications at the cost of data safety.


            • dante Includes a command that uses LD_PRELOAD to enable SOCKS protocol usage for applications which don't natively support it.


            There's also a library that does exactly what you're asking about called libtrash. The official web-page can be found here. I'm not sure if it works or not as I've never used it myself, but there was a recent release of a new version so it looks like the author is at least still maintaining it.






            share|improve this answer

























              up vote
              1
              down vote













              Yes, there is. The general mechanism for this type of thing (overriding a standard function) is called LD_PRELOAD. The general idea is pretty simple, when loading libraries into memory for a program, whichever one is the first to define a given symbol name defines what that symbol does. So, LD_PRELOAD lets you tell the dynamic linker to load specific libraries before all others (including libc), meaning that they can override specific functions from libraries which would be loaded later.



              Examples of widely used projects that make use of LD_PRELOAD include:





              • jemalloc Can be pre-loaded to let you use the jemalloc memory allocator with programs that don't explicitly use it themselves.


              • datefudge Lets you fake the system time and date.


              • libeatmydata Overrides sync() and related calls to do nothing, improving performance of some applications at the cost of data safety.


              • dante Includes a command that uses LD_PRELOAD to enable SOCKS protocol usage for applications which don't natively support it.


              There's also a library that does exactly what you're asking about called libtrash. The official web-page can be found here. I'm not sure if it works or not as I've never used it myself, but there was a recent release of a new version so it looks like the author is at least still maintaining it.






              share|improve this answer























                up vote
                1
                down vote










                up vote
                1
                down vote









                Yes, there is. The general mechanism for this type of thing (overriding a standard function) is called LD_PRELOAD. The general idea is pretty simple, when loading libraries into memory for a program, whichever one is the first to define a given symbol name defines what that symbol does. So, LD_PRELOAD lets you tell the dynamic linker to load specific libraries before all others (including libc), meaning that they can override specific functions from libraries which would be loaded later.



                Examples of widely used projects that make use of LD_PRELOAD include:





                • jemalloc Can be pre-loaded to let you use the jemalloc memory allocator with programs that don't explicitly use it themselves.


                • datefudge Lets you fake the system time and date.


                • libeatmydata Overrides sync() and related calls to do nothing, improving performance of some applications at the cost of data safety.


                • dante Includes a command that uses LD_PRELOAD to enable SOCKS protocol usage for applications which don't natively support it.


                There's also a library that does exactly what you're asking about called libtrash. The official web-page can be found here. I'm not sure if it works or not as I've never used it myself, but there was a recent release of a new version so it looks like the author is at least still maintaining it.






                share|improve this answer












                Yes, there is. The general mechanism for this type of thing (overriding a standard function) is called LD_PRELOAD. The general idea is pretty simple, when loading libraries into memory for a program, whichever one is the first to define a given symbol name defines what that symbol does. So, LD_PRELOAD lets you tell the dynamic linker to load specific libraries before all others (including libc), meaning that they can override specific functions from libraries which would be loaded later.



                Examples of widely used projects that make use of LD_PRELOAD include:





                • jemalloc Can be pre-loaded to let you use the jemalloc memory allocator with programs that don't explicitly use it themselves.


                • datefudge Lets you fake the system time and date.


                • libeatmydata Overrides sync() and related calls to do nothing, improving performance of some applications at the cost of data safety.


                • dante Includes a command that uses LD_PRELOAD to enable SOCKS protocol usage for applications which don't natively support it.


                There's also a library that does exactly what you're asking about called libtrash. The official web-page can be found here. I'm not sure if it works or not as I've never used it myself, but there was a recent release of a new version so it looks like the author is at least still maintaining it.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered 22 hours ago









                Austin Hemmelgarn

                5,59311016




                5,59311016






















                    Stuperfied is a new contributor. Be nice, and check out our Code of Conduct.










                     

                    draft saved


                    draft discarded


















                    Stuperfied is a new contributor. Be nice, and check out our Code of Conduct.













                    Stuperfied is a new contributor. Be nice, and check out our Code of Conduct.












                    Stuperfied is a new contributor. Be nice, and check out our Code of Conduct.















                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f482079%2fis-it-possible-to-intercept-calls-to-unlink-and-redirect-files-to-trash%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Accessing regular linux commands in Huawei's Dopra Linux

                    Can't connect RFCOMM socket: Host is down

                    Kernel panic - not syncing: Fatal Exception in Interrupt