The ability to show progress bar of chmod/chown with pipe viewer (pv)

There’s a lots of information of how to use pv together with “dialog” as a progress indicator for a lots of different projects. For example, even pv shows an example on how to show a progress bar for taring and gzipping a file archive. But there are almost no documents that describes a similar thing for a simple chown/chmod process. Probably, in normal cases, this is not being done since such process is fast enough to not needing it. But for larger directory structures it sometimes is nices with a progress bar, rather than the verbose output of the process.

So here’s how to do it!

   #!/bin/sh
   directory="/home/myLargeHome"
   permissions="myuser:mygroup"
   # Run chown in verbose mode, but redirect the verbosity somewhere else, while pv counts the progress.
   # pv runs in line-mode instead of byte mode.
   chown -Rv $permissions $dir | \
   pv -f -c -n -l -s $(find |wc -l) 2>&1 >/dev/null | \
   dialog --gauge 'Taking ownership of $directory' 7 70 0

Adding for example “-i 0.1” to pv will make dialog update the view more often, but it might affect the performance of the process.

This entry was posted in Everything, Tech-stuff and tagged , , , by Tornevall. Bookmark the permalink.

About Tornevall

- Stories from Reality - Musician | Bedroom DJ | Tug of War | Photographer | DevOps Thomas blends a passion for music, photography, and technology. With a background in 1990s dance music, his journey evolved from early experiments with FastTracker 2 to becoming a DJ and competitor in tug of war. His creative output includes documenting tug of war competitions across Sweden, while also working as a systems developer focusing on WordPress and e-commerce platforms.

Leave a Reply

Your email address will not be published. Required fields are marked *

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