Tired Of Xargs?

What if you want to do something in Linux for a lot of files? [Numerator] was tired of using xarg and other ways to handle this job and created bashumerate.

Some examples in the post of the “other ways” include:

find . -name '*.log' | xargs rm
find . -name '*.sh' -exec wc -l {} \;

You can, also, use a for loop, and if you are a programmer at heart, you may well do this:

for f in *.txt; do
  wc -l "$f"
done

Bashumerate handles all of the common cases in one tool and uses the same syntax for multiple kids of enumerations.

For example, the above translates to:

enumerate -f '*.sh' -- 'wc -l {}'

The -f means enumerate files. You can also enumerate lines, numbers in a range, or lists. What’s even more interesting is that you can add your own source. As an example, there’s an add-in function that enumerates running docker containers.

The source is all in bash, so it should be very portable. Will you try it? What’s your favorite way to enumerate in shell? Let us know in the comments. You know how we love strange bash tricks.

10 thoughts on “Tired Of Xargs?

  1. Please be aware that not escaping things can lead to issues, so it’s often better to do
    find . -name ‘.log’ -print0 | xargs -0 rm
    and not
    find . -name ‘
    .log’ | xargs rm

    And you probably want a “-type f” in there because directories can end in the letters “log” It’ll just throw an error, but it’s probably not what you intended.

  2. vi ListOfFilesInRightOrder.txt
    Strg+v (visual block mode, mark the first column)
    Shift+i “mv 0 ” Esc
    Strg+v (mark the zeros)
    g Strg+a (increases the n-th number by n, the g may be omitted for an increase of one everywhere or replaced by a number for an increase of number)
    add leading zeros as needed (may this be automated? Starting with multiple zeros enumerates in octal)
    :wq
    chmod +x ListOfFilesInRightOrder.txt
    ./ListOfFilesInRightOrder.txt

    maybe not very beautiful, but useful for occasional enumerations

  3. The part that trips me up occasionally is when I want to edit a bunch of files, and do:
    ls *.txt | while read $f; do vi $f; done
    only to be told that STDIN is not a terminal.
    When I should rather do: for f in *.txt; do vi $f; done or better: vi $(ls *.txt)

Leave a Reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.