▲ 16 ▼ simple sorting programm for Linux (github.com) submitted 1 week ago by metw0@lemmy.world to c/programming@programming.dev 11 comments fedilink hide all child comments 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)
[–] thenextguy@sh.itjust.works 11 points 1 week ago (2 children) I don't think it is at all clear what this does. It sorts files how? permalink fedilink source hideshow 4 child comments replies: [–] bobo@lemmy.ml 4 points 1 week ago (1 child) It doesn't sort them in the programming sense, it's just moving files to another directory based on the filename qsort -w /home/user/Documents -t ext --df .txt is equivalent to ls *.txt | xargs -I {} mv {} /home/user/Documents permalink fedilink source parent hideshow 2 child comments replies: [–] MonkderVierte@lemmy.zip 3 points 1 week ago (2 children) Btw, you should not pipe ls. It's unsafe. permalink fedilink source parent hideshow 4 child comments replies: [–] fruitcantfly@programming.dev 8 points 1 week ago (1 child) 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 permalink fedilink source parent hideshow 2 child comments replies: [–] MonkderVierte@lemmy.zip 1 point 1 week ago (1 child) While the later is more reliably available. Use this in scripts you distribute. And also finds -exec instead of |xargs. permalink fedilink source parent hideshow 2 child comments replies: [–] fruitcantfly@programming.dev 2 points 1 week ago Both find and xargs are POSIX commands, so there's something wrong with your OS if you are missing either, and find does not have an equivalent of -P. Granted, -P is an extension, but it is supported by GNU's, OpenBSD's, FreeBSD's, and BusyBox's xargs commands, and probably also by others, so it is reasonable to assume that it is available unless you are targeting some obscure OS permalink fedilink source parent [–] bobo@lemmy.ml 4 points 1 week ago (1 child) Source? I tried searching for it and found nothing. permalink fedilink source parent hideshow 2 child comments replies: [–] BB_C@programming.dev 7 points 1 week 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. permalink fedilink source parent [–] metw0@lemmy.world [S] 3 points 1 week ago this is just a practice project, I shared it just so other people could take a look. you can see how it sorts files by checking out the repository permalink fedilink source parent
[–] bobo@lemmy.ml 4 points 1 week ago (1 child) It doesn't sort them in the programming sense, it's just moving files to another directory based on the filename qsort -w /home/user/Documents -t ext --df .txt is equivalent to ls *.txt | xargs -I {} mv {} /home/user/Documents permalink fedilink source parent hideshow 2 child comments replies: [–] MonkderVierte@lemmy.zip 3 points 1 week ago (2 children) Btw, you should not pipe ls. It's unsafe. permalink fedilink source parent hideshow 4 child comments replies: [–] fruitcantfly@programming.dev 8 points 1 week ago (1 child) 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 permalink fedilink source parent hideshow 2 child comments replies: [–] MonkderVierte@lemmy.zip 1 point 1 week ago (1 child) While the later is more reliably available. Use this in scripts you distribute. And also finds -exec instead of |xargs. permalink fedilink source parent hideshow 2 child comments replies: [–] fruitcantfly@programming.dev 2 points 1 week ago Both find and xargs are POSIX commands, so there's something wrong with your OS if you are missing either, and find does not have an equivalent of -P. Granted, -P is an extension, but it is supported by GNU's, OpenBSD's, FreeBSD's, and BusyBox's xargs commands, and probably also by others, so it is reasonable to assume that it is available unless you are targeting some obscure OS permalink fedilink source parent [–] bobo@lemmy.ml 4 points 1 week ago (1 child) Source? I tried searching for it and found nothing. permalink fedilink source parent hideshow 2 child comments replies: [–] BB_C@programming.dev 7 points 1 week 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. permalink fedilink source parent
[–] MonkderVierte@lemmy.zip 3 points 1 week ago (2 children) Btw, you should not pipe ls. It's unsafe. permalink fedilink source parent hideshow 4 child comments replies: [–] fruitcantfly@programming.dev 8 points 1 week ago (1 child) 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 permalink fedilink source parent hideshow 2 child comments replies: [–] MonkderVierte@lemmy.zip 1 point 1 week ago (1 child) While the later is more reliably available. Use this in scripts you distribute. And also finds -exec instead of |xargs. permalink fedilink source parent hideshow 2 child comments replies: [–] fruitcantfly@programming.dev 2 points 1 week ago Both find and xargs are POSIX commands, so there's something wrong with your OS if you are missing either, and find does not have an equivalent of -P. Granted, -P is an extension, but it is supported by GNU's, OpenBSD's, FreeBSD's, and BusyBox's xargs commands, and probably also by others, so it is reasonable to assume that it is available unless you are targeting some obscure OS permalink fedilink source parent [–] bobo@lemmy.ml 4 points 1 week ago (1 child) Source? I tried searching for it and found nothing. permalink fedilink source parent hideshow 2 child comments replies: [–] BB_C@programming.dev 7 points 1 week 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. permalink fedilink source parent
[–] fruitcantfly@programming.dev 8 points 1 week ago (1 child) 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 permalink fedilink source parent hideshow 2 child comments replies: [–] MonkderVierte@lemmy.zip 1 point 1 week ago (1 child) While the later is more reliably available. Use this in scripts you distribute. And also finds -exec instead of |xargs. permalink fedilink source parent hideshow 2 child comments replies: [–] fruitcantfly@programming.dev 2 points 1 week ago Both find and xargs are POSIX commands, so there's something wrong with your OS if you are missing either, and find does not have an equivalent of -P. Granted, -P is an extension, but it is supported by GNU's, OpenBSD's, FreeBSD's, and BusyBox's xargs commands, and probably also by others, so it is reasonable to assume that it is available unless you are targeting some obscure OS permalink fedilink source parent
[–] MonkderVierte@lemmy.zip 1 point 1 week ago (1 child) While the later is more reliably available. Use this in scripts you distribute. And also finds -exec instead of |xargs. permalink fedilink source parent hideshow 2 child comments replies: [–] fruitcantfly@programming.dev 2 points 1 week ago Both find and xargs are POSIX commands, so there's something wrong with your OS if you are missing either, and find does not have an equivalent of -P. Granted, -P is an extension, but it is supported by GNU's, OpenBSD's, FreeBSD's, and BusyBox's xargs commands, and probably also by others, so it is reasonable to assume that it is available unless you are targeting some obscure OS permalink fedilink source parent
[–] fruitcantfly@programming.dev 2 points 1 week ago Both find and xargs are POSIX commands, so there's something wrong with your OS if you are missing either, and find does not have an equivalent of -P. Granted, -P is an extension, but it is supported by GNU's, OpenBSD's, FreeBSD's, and BusyBox's xargs commands, and probably also by others, so it is reasonable to assume that it is available unless you are targeting some obscure OS permalink fedilink source parent
[–] bobo@lemmy.ml 4 points 1 week ago (1 child) Source? I tried searching for it and found nothing. permalink fedilink source parent hideshow 2 child comments replies: [–] BB_C@programming.dev 7 points 1 week 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. permalink fedilink source parent
[–] BB_C@programming.dev 7 points 1 week 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. permalink fedilink source parent
[–] metw0@lemmy.world [S] 3 points 1 week ago this is just a practice project, I shared it just so other people could take a look. you can see how it sorts files by checking out the repository permalink fedilink source parent