Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo

BSD Cafe Billboard

  1. Home
  2. Linux
  3. If you really know your GNU coreutils, you probably don't need as many extra tools as you think.

If you really know your GNU coreutils, you probably don't need as many extra tools as you think.

Scheduled Pinned Locked Moved Linux
linuxunixcoreutilsgnu
9 Posts 5 Posters 161 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • r1w1s1@snac.bsd.cafeR This user is from outside of this forum
    r1w1s1@snac.bsd.cafeR This user is from outside of this forum
    r1w1s1@snac.bsd.cafe
    wrote on last edited by
    #1
    If you really know your GNU coreutils, you probably don't need as many extra tools as you think. 🐧

    KISS isn't just a design principle — it's already built into your system.

    A comprehensive review of every coreutils command, with examples and honest opinions. The lobste.rs discussion is also worth reading.

    Article: https://ratfactor.com/slackware/pkgblog/coreutils
    Discussion: https://lobste.rs/s/xqf5ex/coreutils_comprehensive_review_2023

    #linux #unix #coreutils #gnu
    1 Reply Last reply
    4
    • restorante@social.linux.pizzaR This user is from outside of this forum
      restorante@social.linux.pizzaR This user is from outside of this forum
      restorante@social.linux.pizza
      wrote on last edited by
      #2

      @r1w1s1 If I am not mistaken grep and sed are not parts of coreutils, isn't it?

      I am not really sure whether these can be replaced with coreutils.

      r1w1s1@snac.bsd.cafeR 1 Reply Last reply
      1
      • pgeorgiP Offline
        pgeorgiP Offline
        pgeorgi
        wrote on last edited by
        #3

        On a tangent: For the specific task of (what's now called) word processing, there's a mighty fine book showing how the tools on a UNIX system can add up to something greater than the sum of the parts. See https://www.oreilly.com/openbook/utp/

        1 Reply Last reply
        2
        • restorante@social.linux.pizzaR restorante@social.linux.pizza

          @r1w1s1 If I am not mistaken grep and sed are not parts of coreutils, isn't it?

          I am not really sure whether these can be replaced with coreutils.

          r1w1s1@snac.bsd.cafeR This user is from outside of this forum
          r1w1s1@snac.bsd.cafeR This user is from outside of this forum
          r1w1s1@snac.bsd.cafe
          wrote on last edited by
          #4
          True — but also interesting how some tools are rarely used or replaced by others (awk, diff, etc).
          Knowing when to use coreutils is just as important as knowing them.
          1 Reply Last reply
          1
          • mason@partychickens.netM This user is from outside of this forum
            mason@partychickens.netM This user is from outside of this forum
            mason@partychickens.net
            wrote on last edited by
            #5
            This post is deleted!
            r1w1s1@snac.bsd.cafeR 1 Reply Last reply
            1
            • mason@partychickens.netM mason@partychickens.net

              This post is deleted!

              r1w1s1@snac.bsd.cafeR This user is from outside of this forum
              r1w1s1@snac.bsd.cafeR This user is from outside of this forum
              r1w1s1@snac.bsd.cafe
              wrote on last edited by r1w1s1@snac.bsd.cafe
              #6
              Slackware also uses another implementation.

              https://mirrors.slackware.com/slackware/slackware64-current/source/a/hostname/
              1 Reply Last reply
              1
              • rozenglass@fedi.dreamscape.linkR This user is from outside of this forum
                rozenglass@fedi.dreamscape.linkR This user is from outside of this forum
                rozenglass@fedi.dreamscape.link
                wrote last edited by
                #7
                @r1w1s1@snac.bsd.cafe Thank you so much for this article, it was a really fun read, and I learned about csplit which is much nicer than the awk state machines I usually write to handle multi-line pattern-separated records, I wish csplit patterns can be multi-line though; it doesn't seem possible. I also use the paste command (e.g. paste - - -) to work around this if the multi-line record has a set number of lines. I found ptx fascinating, and I'm having lots of fun using it over all my writings and journals. Anyway, what follows are some random thoughts, comments, and ideas I had while reading the article 🙂

                One aspect I would suggest looking into is the atomicity of mv and how useful it can be for writing reliable scripts or for deploying new versions of running services without down-time. Especially, `mv -T --exchange deployment-standby deployment-current' which would swap the two directories atomically. I think I will also be using it soon as part of a script to "garbage collect" millions of files, roughly something like:

                1. mkdir store2

                2. for each file we want to remain, we hardlink with ln store1/filename store2/

                3. when all the files we want are hard-linked, mv -T --exchange store2 store1

                4. rm -r store2

                This way, we "garbage collect" all the files that we don't have references to in our list, atomically, deleting them without the store itself being "offline" for reads at any point, and without using any extra disk space for copies of the files. If the garbage collection process is interrupted at any point, store1 remains as is without any change.

                Additionally, nproc --ignore=N is useful for Make build scripts, passing it to make -j, especially when using those make files on many computers with different numbers of cores, make -j $(nproc --ignore=2) for example, would guarantee that a build would use the maximum number of cores on that machine, leaving at least 2 free cores as to not overload the machine and deteriorate its service. Of course, nproc at least returns 1 if the machine has only 1 or 2 cores 🙂

                printf is a lot more flexible than people think. I use it for making separators for example, combined with tr, like this:

                printf '+%78s+\n' | tr ' ' -

                Or, to pad and surround text for example, with the help of xargs, like this:

                cat my.txt | xargs -L1 -d '\n' printf " | %-52s|\n"

                Where my.txt is a pre-formatted text, hard-wrapped at 50 columns (I usually use par for this, instead of fmt, as it allows me to justify text, and is smarter about indention and line prefixes of various kinds, but none of those CLI formatting tools seems to handle multi-byte UTF-8 text).

                seq is nice for doing loops with a specific number of iterations in a POSIX-y way. for i in $(seq 10); to loop 10 times. The form {1..10} is not POSIX sh compliant.

                The shuf command is indeed fun, try the following for some random words; helps with brainstorming names and cool nonsense phrases sometimes, with:

                shuf /usr/share/dict/words | head

                I came up with those just now:

                tight ambiguity
                unsound lavender
                despairing ravages
                median ocean
                delegate troll

                The sleep command is nice for reminders, if you have a notification daemon. On Slackware I put /usr/lib64/xfce4/notifyd/xfce4-notifyd& in my .xinitrc to use it with my tiling window manager:

                sleep 5m && notify-send -u critical 'The Tea' "It's boiling!"

                sort is nice with du -sh, when cleaning up some disk
                space, I use this shell function:

                cdd () { cd "$1" && du -sh ./* | sort -h; }

                Example:

                cdd ~/Downloads/

                120M ./palemoon
                147M ./renpy-8.5.2-sdk.tar.bz2
                173M ./slack-wallpapers-1.0.tar.gz
                181M ./slack-wallpapers-deviantart-1.0.tar.gz

                On a network with good bandwidth but very high packet loss, I used the split combined with lftp parallel downloads over sftp, to speed up downloads of big files greatly, as each file downloaded resets the TCP slow-start algorithm, thus starting with a full 15K of data. So, instead of the download speed grinding to a halt due to packet loss, the link was almost saturated instead. All it took was to split the big file into 14K chunks, and a new TCP connection for each of the chunks 🙂

                I think your example of stdbuf doesn't work because you used echo, which ends with a newline, and newlines flush the output, processes exiting and closing the their pipe / their redirection also flushes, if I recall correctly. So, you need a process that doesn't exit, and doesn't newline, but keeps writing to the file. Apache logs may do that, but I noticed it with other things too, like netstat in continuous mode. In such cases, you may find the last line in the log partially missing, because some chunks of it haven't flushed yet. I've seen cases where newlines are not even used at all in the stream, so buffering was really annoying when you're trying to tail -f for debugging.

                Anyway, thanks again for this interesting article, a lot of effort went into this, your site is now on my RSS feed 🙂

                1 Reply Last reply
                0
                • r1w1s1@snac.bsd.cafeR This user is from outside of this forum
                  r1w1s1@snac.bsd.cafeR This user is from outside of this forum
                  r1w1s1@snac.bsd.cafe
                  wrote last edited by r1w1s1@snac.bsd.cafe
                  #8
                  Thanks so much for the detailed comment, lots of great tips here!
                  The mv -T --exchange pattern for atomic GC is really elegant, I hadn't thought of using hardlinks that way. And the TCP slow-start trick with split + parallel downloads is wild 🙂

                  Just one quick clarification: the blog isn't mine, I just shared the link because I enjoyed the article. The author is Dave (ratfactor.com), and he's on Mastodon at @ratfactor@mastodon.art If you have corrections or things you'd like to see added to the article itself, reaching out to him there would be the best way.

                  But please keep the comments coming here, I'm learning a lot from them!
                  1 Reply Last reply
                  0
                  • rozenglass@fedi.dreamscape.linkR This user is from outside of this forum
                    rozenglass@fedi.dreamscape.linkR This user is from outside of this forum
                    rozenglass@fedi.dreamscape.link
                    wrote last edited by
                    #9
                    @ratfactor@mastodon.art @r1w1s1@snac.bsd.cafe ah, oops, thanks for the correction, and thanks for sharing anyway 🙂
                    1 Reply Last reply
                    0

                    Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                    Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                    With your input, this post could be even better 💗

                    Register Login
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    Powered by NodeBB Contributors
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups