3

Sometime if you run the follow on terminal, it can take some time, depend on the space which will be trimmed.

sudo fstrim -v /

How to get a progressbar for this.

Result of my research:

Progressbar are possible in some other cases:

1 Answer 1

4

You can make your own function that draws a progress bar while it waits for the previous job to complete:

# Function to show progbar while running command in the background
show_progbar() {
  # Uses PID of previous command, unless PID is given as 1st parameter
  if [[ -z $1 ]]
  then
    PID=$!
  else
    PID=$1
  fi
  ii=0
  jj=0
  bar="="       # Character to draw
  echo -n " [ "

  # While the process with PID is running, progbar is drawing
  while [[ -d "/proc/$PID" ]]
  do
    printf "%b" "\b${bar}]"
    (( ii++ ))
    sleep .1    # Speed of the progress bar
  done
  (( ii=ii+3 ))

  # Erases the progress bar after it is done
  while [[ $jj -lt $ii ]]
  do
    printf "\b"
    (( jj++ ))
  done
}

This must be defined or sourced in your shell (or script). To use it run the command like:

sudo fstrim -v / & \
show_progbar

(The backslash is needed to line break when ran from the shell - it can be omitted in a script.)

1
  • 1
    That looks cool. And allows for a lot of tweaking.
    – Rinzwind
    Sep 30 at 19:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.