Wednesday 15 January 2014

bash - How to input clipboard to find command? -



bash - How to input clipboard to find command? -

what need pass list of file names find , have find print these files path xargs (find's -exec fine) carry out command on them.

i know find can read file of file names, reading lines:

while read line; find . -name "$line" -exec command '{}' \; ;done <file

but in case more handy have find read clipboard.

on clipboard file names new line separated, , when clipboard prints out, looks file contents of file mentioned.

i utilize xsel deal clipboard (in debian linux). carry out command on files listed on clipboard in current directory it's possible with:

xsel -b -o | xargs command

but thought of using find of course of study able search of these files on list recursively.

it nice if next worked, find reads first file on list:

xsel -b -o | while read line; find . -name "$line" -print0 | xargs -0 command ;done

if correctable solve issue.

redirecting clipboard (with <) find doesn't work because bash says no such file - find expecting file.

everything easy if find receive multiple names without needing flag each pattern (ie -name dsc456.jpg -name dsc457.jpg) or 1 bracket multiple names 1 -name pattern, coming xsel -b -o hard anyway.

so that's got , i'd know if 1 has thought this! may have write script writes clipboard file , go there.

you pipe xargs instead of find:

$ xsel -b -o | xargs -i x -r -n 1 find . -name x -exec command '{}' \;

bash find clipboard

No comments:

Post a Comment