Login
You're viewing the discuss.systems public feed.
  • Sep 29, 2026, 10:58 AM

    Something that can seem purely cosmetic but is actually really cool: ANSI escape codes.

    Today: I need to execute a script in a while loop, and see the output, but I don't care about previous output: only real-time info is important.
    So instead of filling my terminal with too much useless output, I execute this on every iteration:

    > print "\x1B[3A"

    This moves the cursor 3 lines up.
    Then the script erases previous output.
    Seems like live-refresh.

    Got help from there: gist.github.com/fnky/458719343

    💬 1🔄 0⭐ 0

Replies

  • Sep 29, 2026, 11:10 AM

    For more fun (and my current example), here's my script:

    echo "" ; while [ true ] ; do ls -l backup.tar.gz ; ls -lh transfer.tar.gz ; df /var/backup ; df -h /var/backup | tail -n 1 ; print "\x1B[6A" ; sleep 0.5; done

    That's my "comfort monitoring tool": seeing bytes values rise to have an idea of the current bandwidth, but also the "human-readable size" of these backups, and the space it occupies.

    Using "sleep" after it helps in making the process less greedy on cpu+disk resources.

    💬 1🔄 0⭐ 0
  • Sep 30, 2026, 8:16 PM

    @pierstoval Thanks for the share, I've seen it many many times on various CLI tools without taking the time to understand how it was done.

    For your special use case I often use the `pv` command.
    `progress -m` can also help.

    💬 0🔄 0⭐ 0