echo/printf incomplete command at bash terminal












1















At the BASH prompt I can find files then append xargs to do further stuff. e.g. find ... | xargs rm {}



However, sometimes there is a manual intermediate step: I use fzf to refine the find results.



I would like to use this filtered list of files to create an incomplete xargs command at the terminal.



For example, if my find command produces
file1 file2 file3, and my fzf narrows this down to file2 file3, I would like the script to create an incomplete line at the terminal like this:



file2 file3 |xargs -0 --other-standard-options



but i don't want the command to flush (I don't know what the correct term is) as if I had pressed enter. I want to be able to complete the command myself (e.g. rm {}), after seeing the list of files printed on the line.



The find command will need to use the print0 option.



I suppose the script would look something like this:



find . | fzf -m | *echo incomplete xargs command*.



the echo -n command is not what I want: it still passes the command to BASH shell.



Maybe there is a better way of using find, then manually checking and filtering, then executing a command like rm or mv, and if so, that would be an acceptable answer.



The number of files I need to be able to deal with after the filtering is small (<100).










share|improve this question



























    1















    At the BASH prompt I can find files then append xargs to do further stuff. e.g. find ... | xargs rm {}



    However, sometimes there is a manual intermediate step: I use fzf to refine the find results.



    I would like to use this filtered list of files to create an incomplete xargs command at the terminal.



    For example, if my find command produces
    file1 file2 file3, and my fzf narrows this down to file2 file3, I would like the script to create an incomplete line at the terminal like this:



    file2 file3 |xargs -0 --other-standard-options



    but i don't want the command to flush (I don't know what the correct term is) as if I had pressed enter. I want to be able to complete the command myself (e.g. rm {}), after seeing the list of files printed on the line.



    The find command will need to use the print0 option.



    I suppose the script would look something like this:



    find . | fzf -m | *echo incomplete xargs command*.



    the echo -n command is not what I want: it still passes the command to BASH shell.



    Maybe there is a better way of using find, then manually checking and filtering, then executing a command like rm or mv, and if so, that would be an acceptable answer.



    The number of files I need to be able to deal with after the filtering is small (<100).










    share|improve this question

























      1












      1








      1








      At the BASH prompt I can find files then append xargs to do further stuff. e.g. find ... | xargs rm {}



      However, sometimes there is a manual intermediate step: I use fzf to refine the find results.



      I would like to use this filtered list of files to create an incomplete xargs command at the terminal.



      For example, if my find command produces
      file1 file2 file3, and my fzf narrows this down to file2 file3, I would like the script to create an incomplete line at the terminal like this:



      file2 file3 |xargs -0 --other-standard-options



      but i don't want the command to flush (I don't know what the correct term is) as if I had pressed enter. I want to be able to complete the command myself (e.g. rm {}), after seeing the list of files printed on the line.



      The find command will need to use the print0 option.



      I suppose the script would look something like this:



      find . | fzf -m | *echo incomplete xargs command*.



      the echo -n command is not what I want: it still passes the command to BASH shell.



      Maybe there is a better way of using find, then manually checking and filtering, then executing a command like rm or mv, and if so, that would be an acceptable answer.



      The number of files I need to be able to deal with after the filtering is small (<100).










      share|improve this question














      At the BASH prompt I can find files then append xargs to do further stuff. e.g. find ... | xargs rm {}



      However, sometimes there is a manual intermediate step: I use fzf to refine the find results.



      I would like to use this filtered list of files to create an incomplete xargs command at the terminal.



      For example, if my find command produces
      file1 file2 file3, and my fzf narrows this down to file2 file3, I would like the script to create an incomplete line at the terminal like this:



      file2 file3 |xargs -0 --other-standard-options



      but i don't want the command to flush (I don't know what the correct term is) as if I had pressed enter. I want to be able to complete the command myself (e.g. rm {}), after seeing the list of files printed on the line.



      The find command will need to use the print0 option.



      I suppose the script would look something like this:



      find . | fzf -m | *echo incomplete xargs command*.



      the echo -n command is not what I want: it still passes the command to BASH shell.



      Maybe there is a better way of using find, then manually checking and filtering, then executing a command like rm or mv, and if so, that would be an acceptable answer.



      The number of files I need to be able to deal with after the filtering is small (<100).







      bash terminal echo






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Dec 29 '18 at 10:33









      TimTim

      1577




      1577
























          3 Answers
          3






          active

          oldest

          votes


















          1














          So it looks like fzf has some evn settings that can be used to filter the set of data that comes back. There is also options env as well. I would take a look at the following evn variables:
          FZF_DEFAULT_COMMAND and FZF_DEFAULT_OPTS.



          FZF_DEFAULT_COMMAND will allow you to use a different command to filter down your file set. Check out the following here



          Meaning you may not need to use find and pipe that to the fzf command. You could just start with the fzf command itself and set the proper evn variable.



          To use the interactive mode to remove and review files on the same line you could do something like the following.



          find . -type f -name '*test*' | fzf -m | xargs rm





          share|improve this answer


























          • the environmental variables sure do help; but I'd like to write the xargs after I have seen the list (unlike your example), because I won't know the command until I see the files which are selected.

            – Tim
            Dec 30 '18 at 6:09











          • I would look at the External Programs bindings, and see if you can call fzf in interactive mode slect the files and execute a move or delete command.

            – John Babb
            Dec 30 '18 at 12:46



















          0














          for f in $(find . -type f -name '*test*' | fzf -m); do 
          read -p ".... ${f} Enter command to insert on the dots "
          echo "$REPLY ${f}"
          $REPLY "${f}"
          done





          share|improve this answer
























          • 1) this requires me to type in the command for each file. I would like to do the same command for all files 2) it needs to cope with print0 because of n in some filenames. 3) by way of explanation: is there no way to type an incomplete command (i.e. what bash does when you select a previous command from history, but allows you to edit it)?

            – Tim
            Dec 30 '18 at 6:05













          • I don't know about the history. When you want one command for all files, can you ask for that command before you call find .. print0 .. | xargs .. $REPLY .. ?

            – Walter A
            Dec 30 '18 at 9:40











          • I'd like to see the results of the find before I determine the command.

            – Tim
            Dec 30 '18 at 22:00











          • You can call find first before processing the data, ask for the command and call find again, now with the for-loop or xargs. Use a mtime flag when you only want to process files you have seen before entering the command.

            – Walter A
            Jan 2 at 15:42



















          0














          The following seems to work, leaving the user to complete the command at the prompt:



          out=$(find . |fzf -m )
          prefix="echo ";
          suffix="| xargs ";
          files="$(echo "${out}" | sed -e 's:^.:".:g' -e 's:$:":g'|tr 'n' ' ' )";
          cmd="${prefix}${files}${suffix}" ;
          read -e -i "$cmd"; eval "$REPLY";


          Explanation: fzf outputs filenames which I wrap in double quotes for the sake of safety; the terminal command I want to create looks like this:



          echo "file1" "file2" "file3"|xargs ....



          All the real credit goes to @meuh here






          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            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',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            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
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53968735%2fecho-printf-incomplete-command-at-bash-terminal%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            3 Answers
            3






            active

            oldest

            votes








            3 Answers
            3






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            So it looks like fzf has some evn settings that can be used to filter the set of data that comes back. There is also options env as well. I would take a look at the following evn variables:
            FZF_DEFAULT_COMMAND and FZF_DEFAULT_OPTS.



            FZF_DEFAULT_COMMAND will allow you to use a different command to filter down your file set. Check out the following here



            Meaning you may not need to use find and pipe that to the fzf command. You could just start with the fzf command itself and set the proper evn variable.



            To use the interactive mode to remove and review files on the same line you could do something like the following.



            find . -type f -name '*test*' | fzf -m | xargs rm





            share|improve this answer


























            • the environmental variables sure do help; but I'd like to write the xargs after I have seen the list (unlike your example), because I won't know the command until I see the files which are selected.

              – Tim
              Dec 30 '18 at 6:09











            • I would look at the External Programs bindings, and see if you can call fzf in interactive mode slect the files and execute a move or delete command.

              – John Babb
              Dec 30 '18 at 12:46
















            1














            So it looks like fzf has some evn settings that can be used to filter the set of data that comes back. There is also options env as well. I would take a look at the following evn variables:
            FZF_DEFAULT_COMMAND and FZF_DEFAULT_OPTS.



            FZF_DEFAULT_COMMAND will allow you to use a different command to filter down your file set. Check out the following here



            Meaning you may not need to use find and pipe that to the fzf command. You could just start with the fzf command itself and set the proper evn variable.



            To use the interactive mode to remove and review files on the same line you could do something like the following.



            find . -type f -name '*test*' | fzf -m | xargs rm





            share|improve this answer


























            • the environmental variables sure do help; but I'd like to write the xargs after I have seen the list (unlike your example), because I won't know the command until I see the files which are selected.

              – Tim
              Dec 30 '18 at 6:09











            • I would look at the External Programs bindings, and see if you can call fzf in interactive mode slect the files and execute a move or delete command.

              – John Babb
              Dec 30 '18 at 12:46














            1












            1








            1







            So it looks like fzf has some evn settings that can be used to filter the set of data that comes back. There is also options env as well. I would take a look at the following evn variables:
            FZF_DEFAULT_COMMAND and FZF_DEFAULT_OPTS.



            FZF_DEFAULT_COMMAND will allow you to use a different command to filter down your file set. Check out the following here



            Meaning you may not need to use find and pipe that to the fzf command. You could just start with the fzf command itself and set the proper evn variable.



            To use the interactive mode to remove and review files on the same line you could do something like the following.



            find . -type f -name '*test*' | fzf -m | xargs rm





            share|improve this answer















            So it looks like fzf has some evn settings that can be used to filter the set of data that comes back. There is also options env as well. I would take a look at the following evn variables:
            FZF_DEFAULT_COMMAND and FZF_DEFAULT_OPTS.



            FZF_DEFAULT_COMMAND will allow you to use a different command to filter down your file set. Check out the following here



            Meaning you may not need to use find and pipe that to the fzf command. You could just start with the fzf command itself and set the proper evn variable.



            To use the interactive mode to remove and review files on the same line you could do something like the following.



            find . -type f -name '*test*' | fzf -m | xargs rm






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Dec 29 '18 at 11:58

























            answered Dec 29 '18 at 11:53









            John BabbJohn Babb

            8771018




            8771018













            • the environmental variables sure do help; but I'd like to write the xargs after I have seen the list (unlike your example), because I won't know the command until I see the files which are selected.

              – Tim
              Dec 30 '18 at 6:09











            • I would look at the External Programs bindings, and see if you can call fzf in interactive mode slect the files and execute a move or delete command.

              – John Babb
              Dec 30 '18 at 12:46



















            • the environmental variables sure do help; but I'd like to write the xargs after I have seen the list (unlike your example), because I won't know the command until I see the files which are selected.

              – Tim
              Dec 30 '18 at 6:09











            • I would look at the External Programs bindings, and see if you can call fzf in interactive mode slect the files and execute a move or delete command.

              – John Babb
              Dec 30 '18 at 12:46

















            the environmental variables sure do help; but I'd like to write the xargs after I have seen the list (unlike your example), because I won't know the command until I see the files which are selected.

            – Tim
            Dec 30 '18 at 6:09





            the environmental variables sure do help; but I'd like to write the xargs after I have seen the list (unlike your example), because I won't know the command until I see the files which are selected.

            – Tim
            Dec 30 '18 at 6:09













            I would look at the External Programs bindings, and see if you can call fzf in interactive mode slect the files and execute a move or delete command.

            – John Babb
            Dec 30 '18 at 12:46





            I would look at the External Programs bindings, and see if you can call fzf in interactive mode slect the files and execute a move or delete command.

            – John Babb
            Dec 30 '18 at 12:46













            0














            for f in $(find . -type f -name '*test*' | fzf -m); do 
            read -p ".... ${f} Enter command to insert on the dots "
            echo "$REPLY ${f}"
            $REPLY "${f}"
            done





            share|improve this answer
























            • 1) this requires me to type in the command for each file. I would like to do the same command for all files 2) it needs to cope with print0 because of n in some filenames. 3) by way of explanation: is there no way to type an incomplete command (i.e. what bash does when you select a previous command from history, but allows you to edit it)?

              – Tim
              Dec 30 '18 at 6:05













            • I don't know about the history. When you want one command for all files, can you ask for that command before you call find .. print0 .. | xargs .. $REPLY .. ?

              – Walter A
              Dec 30 '18 at 9:40











            • I'd like to see the results of the find before I determine the command.

              – Tim
              Dec 30 '18 at 22:00











            • You can call find first before processing the data, ask for the command and call find again, now with the for-loop or xargs. Use a mtime flag when you only want to process files you have seen before entering the command.

              – Walter A
              Jan 2 at 15:42
















            0














            for f in $(find . -type f -name '*test*' | fzf -m); do 
            read -p ".... ${f} Enter command to insert on the dots "
            echo "$REPLY ${f}"
            $REPLY "${f}"
            done





            share|improve this answer
























            • 1) this requires me to type in the command for each file. I would like to do the same command for all files 2) it needs to cope with print0 because of n in some filenames. 3) by way of explanation: is there no way to type an incomplete command (i.e. what bash does when you select a previous command from history, but allows you to edit it)?

              – Tim
              Dec 30 '18 at 6:05













            • I don't know about the history. When you want one command for all files, can you ask for that command before you call find .. print0 .. | xargs .. $REPLY .. ?

              – Walter A
              Dec 30 '18 at 9:40











            • I'd like to see the results of the find before I determine the command.

              – Tim
              Dec 30 '18 at 22:00











            • You can call find first before processing the data, ask for the command and call find again, now with the for-loop or xargs. Use a mtime flag when you only want to process files you have seen before entering the command.

              – Walter A
              Jan 2 at 15:42














            0












            0








            0







            for f in $(find . -type f -name '*test*' | fzf -m); do 
            read -p ".... ${f} Enter command to insert on the dots "
            echo "$REPLY ${f}"
            $REPLY "${f}"
            done





            share|improve this answer













            for f in $(find . -type f -name '*test*' | fzf -m); do 
            read -p ".... ${f} Enter command to insert on the dots "
            echo "$REPLY ${f}"
            $REPLY "${f}"
            done






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Dec 29 '18 at 15:07









            Walter AWalter A

            10.6k21031




            10.6k21031













            • 1) this requires me to type in the command for each file. I would like to do the same command for all files 2) it needs to cope with print0 because of n in some filenames. 3) by way of explanation: is there no way to type an incomplete command (i.e. what bash does when you select a previous command from history, but allows you to edit it)?

              – Tim
              Dec 30 '18 at 6:05













            • I don't know about the history. When you want one command for all files, can you ask for that command before you call find .. print0 .. | xargs .. $REPLY .. ?

              – Walter A
              Dec 30 '18 at 9:40











            • I'd like to see the results of the find before I determine the command.

              – Tim
              Dec 30 '18 at 22:00











            • You can call find first before processing the data, ask for the command and call find again, now with the for-loop or xargs. Use a mtime flag when you only want to process files you have seen before entering the command.

              – Walter A
              Jan 2 at 15:42



















            • 1) this requires me to type in the command for each file. I would like to do the same command for all files 2) it needs to cope with print0 because of n in some filenames. 3) by way of explanation: is there no way to type an incomplete command (i.e. what bash does when you select a previous command from history, but allows you to edit it)?

              – Tim
              Dec 30 '18 at 6:05













            • I don't know about the history. When you want one command for all files, can you ask for that command before you call find .. print0 .. | xargs .. $REPLY .. ?

              – Walter A
              Dec 30 '18 at 9:40











            • I'd like to see the results of the find before I determine the command.

              – Tim
              Dec 30 '18 at 22:00











            • You can call find first before processing the data, ask for the command and call find again, now with the for-loop or xargs. Use a mtime flag when you only want to process files you have seen before entering the command.

              – Walter A
              Jan 2 at 15:42

















            1) this requires me to type in the command for each file. I would like to do the same command for all files 2) it needs to cope with print0 because of n in some filenames. 3) by way of explanation: is there no way to type an incomplete command (i.e. what bash does when you select a previous command from history, but allows you to edit it)?

            – Tim
            Dec 30 '18 at 6:05







            1) this requires me to type in the command for each file. I would like to do the same command for all files 2) it needs to cope with print0 because of n in some filenames. 3) by way of explanation: is there no way to type an incomplete command (i.e. what bash does when you select a previous command from history, but allows you to edit it)?

            – Tim
            Dec 30 '18 at 6:05















            I don't know about the history. When you want one command for all files, can you ask for that command before you call find .. print0 .. | xargs .. $REPLY .. ?

            – Walter A
            Dec 30 '18 at 9:40





            I don't know about the history. When you want one command for all files, can you ask for that command before you call find .. print0 .. | xargs .. $REPLY .. ?

            – Walter A
            Dec 30 '18 at 9:40













            I'd like to see the results of the find before I determine the command.

            – Tim
            Dec 30 '18 at 22:00





            I'd like to see the results of the find before I determine the command.

            – Tim
            Dec 30 '18 at 22:00













            You can call find first before processing the data, ask for the command and call find again, now with the for-loop or xargs. Use a mtime flag when you only want to process files you have seen before entering the command.

            – Walter A
            Jan 2 at 15:42





            You can call find first before processing the data, ask for the command and call find again, now with the for-loop or xargs. Use a mtime flag when you only want to process files you have seen before entering the command.

            – Walter A
            Jan 2 at 15:42











            0














            The following seems to work, leaving the user to complete the command at the prompt:



            out=$(find . |fzf -m )
            prefix="echo ";
            suffix="| xargs ";
            files="$(echo "${out}" | sed -e 's:^.:".:g' -e 's:$:":g'|tr 'n' ' ' )";
            cmd="${prefix}${files}${suffix}" ;
            read -e -i "$cmd"; eval "$REPLY";


            Explanation: fzf outputs filenames which I wrap in double quotes for the sake of safety; the terminal command I want to create looks like this:



            echo "file1" "file2" "file3"|xargs ....



            All the real credit goes to @meuh here






            share|improve this answer




























              0














              The following seems to work, leaving the user to complete the command at the prompt:



              out=$(find . |fzf -m )
              prefix="echo ";
              suffix="| xargs ";
              files="$(echo "${out}" | sed -e 's:^.:".:g' -e 's:$:":g'|tr 'n' ' ' )";
              cmd="${prefix}${files}${suffix}" ;
              read -e -i "$cmd"; eval "$REPLY";


              Explanation: fzf outputs filenames which I wrap in double quotes for the sake of safety; the terminal command I want to create looks like this:



              echo "file1" "file2" "file3"|xargs ....



              All the real credit goes to @meuh here






              share|improve this answer


























                0












                0








                0







                The following seems to work, leaving the user to complete the command at the prompt:



                out=$(find . |fzf -m )
                prefix="echo ";
                suffix="| xargs ";
                files="$(echo "${out}" | sed -e 's:^.:".:g' -e 's:$:":g'|tr 'n' ' ' )";
                cmd="${prefix}${files}${suffix}" ;
                read -e -i "$cmd"; eval "$REPLY";


                Explanation: fzf outputs filenames which I wrap in double quotes for the sake of safety; the terminal command I want to create looks like this:



                echo "file1" "file2" "file3"|xargs ....



                All the real credit goes to @meuh here






                share|improve this answer













                The following seems to work, leaving the user to complete the command at the prompt:



                out=$(find . |fzf -m )
                prefix="echo ";
                suffix="| xargs ";
                files="$(echo "${out}" | sed -e 's:^.:".:g' -e 's:$:":g'|tr 'n' ' ' )";
                cmd="${prefix}${files}${suffix}" ;
                read -e -i "$cmd"; eval "$REPLY";


                Explanation: fzf outputs filenames which I wrap in double quotes for the sake of safety; the terminal command I want to create looks like this:



                echo "file1" "file2" "file3"|xargs ....



                All the real credit goes to @meuh here







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Dec 31 '18 at 11:50









                TimTim

                1577




                1577






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53968735%2fecho-printf-incomplete-command-at-bash-terminal%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

                    Monofisismo

                    Angular Downloading a file using contenturl with Basic Authentication

                    Olmecas