17
simple sorting programm for Linux
(github.com)
Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!
Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.
Hope you enjoy the instance!
Rules
Follow the wormhole through a path of communities !webdev@programming.dev
It doesn't sort them in the programming sense, it's just moving files to another directory based on the filename
is equivalent to
Btw, you should not pipe ls. It's unsafe.
lscan be piped safely if you use--zero:While the above is a pretty silly example, one reason why you might want to do this is that
xargshas a-P/--max-procsargument, that runs N commands in parallel. So you could do something like the following to gzip four files in parallel:This is a bit simpler than using the equivalent
While the later is more reliably available. Use this in scripts you distribute. And also finds
-execinstead of|xargs.Both
findandxargsare POSIX commands, so there's something wrong with your OS if you are missing either, andfinddoes not have an equivalent of-P. Granted,-Pis an extension, but it is supported by GNU's, OpenBSD's, FreeBSD's, and BusyBox'sxargscommands, and probably also by others, so it is reasonable to assume that it is available unless you are targeting some obscure OSSource? I tried searching for it and found nothing.
I think the other user meant that
lsoutput is not supposed to be treated as parsable, because the tool doesn't offer any guarantees in that regards.Shells have built-in support for globbing files anyway.
xargsis also not needed. If someone is allergic to using a shellforloop,findalways had-execwith;instead+which wouldn't trip on too many arguments.