Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7013369
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:22:41+00:00 2026-05-27T22:22:41+00:00

Is it possible to get the output of a command – for example tar

  • 0

Is it possible to get the output of a command – for example tar – to write each line of output to one line only?

Example usage:

tar -options -f dest source | [insert trickery here]

and the output would show every file being processed without making the screen move: each output overwrites the last one. Can it be done?


Edit: we seem to have a working answer, but lets take it further:
How about doing the same, but over 5 lines? You see a scrolling output that doesn’t affect the rest of the terminal. I think I’ve got an answer, but I’d like to see what you guys think.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T22:22:41+00:00Added an answer on May 27, 2026 at 10:22 pm

    Replace the newlines with carriage returns.

     tar -options -f dest source | cut -b1-$(tput cols) | sed -u 'i\\o033[2K' | stdbuf -o0 tr '\n' '\r'; echo
    

    Explanation:

    • cut -b1-$(tput cols): Truncates the output of tar if it is longer than the terminal is wide. Depending on how little you want your terminal to move, it isn’t strictly necessary.

    • sed -u 'i\\o033[2K': Inserts a line blank at the beginning of each line. The -u option to sed puts it in unbuffered mode. stdbuf -oL sed 'i\\033[2K' would work equally as well.

    • stdbuf -o0 tr '\n' '\r': Uses tr to exchange newlines with carriage returns. Stdbuf makes sure that the output is unbuffered; without the \n‘s, on a line buffered terminal, we’d see no output.

    • echo: Outputs a final newline, so that the terminal prompt doesn’t eat up the final line.

    For the problem your edit proposes:

    x=0; 
    echo -e '\e[s'; 
    tar -options -f dest source | while read line; do
          echo -en "\e[u" 
          if [ $x gt 0 ]; then echo -en "\e["$x"B"; fi;
          echo -en "\e[2K"
          echo -n $line | cut -b1-$(tput cols);
          let "x = ($x+1)%5";
    done; echo;
    

    Feel free to smush all that onto one line. This actually yields an alternative solution for the original problem:

    echo -e '\e[s'; tar -options -f dest source | while read line; do echo -en "\e[u\e2K"; echo -n $line | cut -b1-$(tput cols); done; echo
    

    which neatly relies on nothing except VT100 codes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to get the output of some command line argument (which I'm
Is it possible to get PowerShell to always output / instead of \ ?
Given the output of inspect.stack() , is it possible to get the function objects
Possible Duplicate: Get output from a process Executing DOS commands from Java I am
Possible Duplicate: Copy to Output Directory copies folder structure but only want to copy
Here's an example of the command I'm using: rsync --list-only --include *2012*.xml -exclude *.xml
I am trying to write a wrapper script for a command line program (svnadmin
Is it possible to execute shell script in command line like this : counter=`ps
I am writing a command line tool to convert Markdown text to html output,
Possible Duplicate: Capturing multiple line output to a bash variable I have what is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.