echo/printf incomplete command at bash terminal
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
add a comment |
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
add a comment |
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
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
bash terminal echo
asked Dec 29 '18 at 10:33
TimTim
1577
1577
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
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
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
add a comment |
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
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 callfind .. print0 .. | xargs .. $REPLY ..
?
– Walter A
Dec 30 '18 at 9:40
I'd like to see the results of thefind
before I determine the command.
– Tim
Dec 30 '18 at 22:00
You can callfind
first before processing the data, ask for the command and callfind
again, now with the for-loop orxargs
. Use amtime
flag when you only want to process files you have seen before entering the command.
– Walter A
Jan 2 at 15:42
add a comment |
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
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
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
add a comment |
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
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
add a comment |
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
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
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
add a comment |
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
add a comment |
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
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 callfind .. print0 .. | xargs .. $REPLY ..
?
– Walter A
Dec 30 '18 at 9:40
I'd like to see the results of thefind
before I determine the command.
– Tim
Dec 30 '18 at 22:00
You can callfind
first before processing the data, ask for the command and callfind
again, now with the for-loop orxargs
. Use amtime
flag when you only want to process files you have seen before entering the command.
– Walter A
Jan 2 at 15:42
add a comment |
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
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 callfind .. print0 .. | xargs .. $REPLY ..
?
– Walter A
Dec 30 '18 at 9:40
I'd like to see the results of thefind
before I determine the command.
– Tim
Dec 30 '18 at 22:00
You can callfind
first before processing the data, ask for the command and callfind
again, now with the for-loop orxargs
. Use amtime
flag when you only want to process files you have seen before entering the command.
– Walter A
Jan 2 at 15:42
add a comment |
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
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
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 callfind .. print0 .. | xargs .. $REPLY ..
?
– Walter A
Dec 30 '18 at 9:40
I'd like to see the results of thefind
before I determine the command.
– Tim
Dec 30 '18 at 22:00
You can callfind
first before processing the data, ask for the command and callfind
again, now with the for-loop orxargs
. Use amtime
flag when you only want to process files you have seen before entering the command.
– Walter A
Jan 2 at 15:42
add a comment |
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 callfind .. print0 .. | xargs .. $REPLY ..
?
– Walter A
Dec 30 '18 at 9:40
I'd like to see the results of thefind
before I determine the command.
– Tim
Dec 30 '18 at 22:00
You can callfind
first before processing the data, ask for the command and callfind
again, now with the for-loop orxargs
. Use amtime
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
add a comment |
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
add a comment |
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
add a comment |
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
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
answered Dec 31 '18 at 11:50
TimTim
1577
1577
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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