You are not logged in.
Hi, when i get output from terminal which looks like this:
[fekal@f screenshots1]$ ls *.jpg | sxiv -tio
2022-01-10-170422_3200x1080_scrot.jpg
2022-01-10-192421_3200x1080_scrot.jpg
2022-01-10-195101_3200x1080_scrot.jpg
2022-01-11-074643_3200x1080_scrot.jpg
2022-01-11-080643_3200x1080_scrot.jpg
2022-01-11-082323_3200x1080_scrot.jpg
how can I use simple command on these files like `cp (this list) ./new-folder`?
I know you can do echo and put them to some list but I would love to know if I can use command on block like this without making list.
Offline
See the xargs command, using the -t option for cp.
aka Tamaranch: https://gitlab.xfce.org/Tamaranch
Offline
thank you lambdarch I will look in it.
Offline
this command:
`ls *.jpg | sxiv -tio | xargs -n1 -I '{}' mv '{}' pokus/`
seems to do what I need.
Offline
-n1 is implied by -I'{}' if I'm not mistaken, and it would be cleaner to use printf '%s\n' instead of ls to better preserve the filenames, although given their form above this is not necessary.
Last edited by lambdarch (2022-03-30 16:02:53)
aka Tamaranch: https://gitlab.xfce.org/Tamaranch
Offline
Offline
Why are you piping names from ls to sxiv in the first place? It can be given multiple files on the command line. This way you'd avoid all the pitfalls of using ls in this way (there are many). Further, mv can also accept multiple files. So the following should do what it seems you are trying to do:
mv $(sxiv -tio *.jpg) pokus/
If you don't like that approach, at least get rid of the useless ls:
sxiv -tio *.jpg | xargs ...
edit: actually the second version above is probably safer depending on exactly how sxiv outputs filenames (I have no experience with it).
Last edited by Trilby (2022-03-30 16:22:46)
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
ok this works best: `mkdir pokus/ | mv $(sxiv -tio *.jpg) pokus/`
but this also works: `mkdir copied/ | printf '%s\n' *.jpg| sxiv -tio | xargs -I {} cp {} copied/` and i got rid of warning.
`mkdir cop/ | sxiv -tio *.jpg | xargs -I {} cp {} cop/` this works too
this pass through shellcheck with no warning: `mkdir copy/ | sxiv -tio ./*.jpg | xargs -I {} cp {} copy/` and it works
thanks a bunch to you all that is all i need.
Ps Luke Smith made a tutorial where he uses ls *.jpg| sxiv -tio
bye
Last edited by fekalzrout (2022-03-30 17:09:43)
Offline
mkdir dir | command: Be careful, there is nothing to pipe here, and you could start using the directory before it has been created.
What you want to do is probably mkdir dir && command.
aka Tamaranch: https://gitlab.xfce.org/Tamaranch
Offline
Ps Luke Smith made a tutorial where he uses ls *.jpg| sxiv -tio
He's made a lot of other problematic stuff too.
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
*.jpg in arguments may fail on a big list of files. Args + environment size must not exceed ARG_MAX (128k).
find ... -print0 | xargs -r0 ...
is safer.
Offline