this post was submitted on 29 Jul 2026
12 points (75.0% liked)

Programming

27894 readers
214 users here now

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

Rules

  • Follow the programming.dev instance rules
  • Keep content related to programming in some way
  • If you're posting long videos try to add in some form of tldr for those who don't want to watch videos

Wormhole

Follow the wormhole through a path of communities !webdev@programming.dev



founded 3 years ago
MODERATORS
 

wrote CLI in C++ to sort files. it's very simple, just download and use. if you a photographer, video editor or just need to sort some files, you welcome (link in post)

you are viewing a single comment's thread
view the rest of the comments
[–] MonkderVierte@lemmy.zip 2 points 19 hours ago (2 children)

Btw, you should not pipe ls. It's unsafe.

[–] fruitcantfly@programming.dev 4 points 7 hours ago

ls can be piped safely if you use --zero:

ls --zero *.txt | xargs --null -I {} mv {} /home/user/Documents

While the above is a pretty silly example, one reason why you might want to do this is that xargs has a -P/--max-procs argument, that runs N commands in parallel. So you could do something like the following to gzip four files in parallel:

ls --zero *.txt | xargs --null -n1 -P4 gzip

This is a bit simpler than using the equivalent

find . -maxdepth 1 -name '*.txt' -print0 | xargs --null -n1 -P4 gzip
[–] bobo@lemmy.ml 4 points 18 hours ago (1 children)

Source? I tried searching for it and found nothing.

[–] BB_C@programming.dev 4 points 17 hours ago

I think the other user meant that ls output 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. xargs is also not needed. If someone is allergic to using a shell for loop, find always had -exec with ; instead + which wouldn't trip on too many arguments.