Imagine you've started a long-running process that involves piping data,
but you forgot to add the progress-bar option to a command.
e.g.
xz -dc bigdata.xz | complicated-processing-program > summary
.
This command uses lsof to see how much data xz has read from the file.
lsof -o0 -o -Fo FILENAME
Display offsets (-o), in decimal (-o0), in parseable form (-Fo)
This will output something like:
.
p12607
f3
o0t45187072
.
Process id (p), File Descriptor (f), Offset (o)
.
We stat the file to get its size
stat -c %s FILENAME
.
Then we plug the values into awk.
Split the line at the letter t: -Ft
Define a variable for the file's size: -s=$(stat...)
Only work on the offset line: /^o/
.
Note this command was tested using the Linux version of lsof.
Because it uses lsof's batch option (-F) it may be portable.
.
Thanks to @unhammer for the brilliant idea.
Show Sample Output

update the output of rsync after completing a file but don't create newlines, just overwrite the last line, this looks a lot better in scripts where you do want to see a progress-indicator, but not the lengthy logs
this option is available since rsync 3.1.0
Show Sample Output

If you're running a command with a lot of output, this serves as a simple progress indicator.
This avoids the need to use `/dev/null` for silencing. It works for any command that outputs lines, updates live (`fflush` avoids buffering), and is simple to understand.
Show Sample Output

While a dd is running in one terminal, open another and enter the while loop. The sample output will be displayed in the window running the dd and the while loop will exit when the dd is complete. It's possible that a "sudo" will need to be inserted before "pkill", depending on your setup, for example:
while pgrep ^dd; do sudo pkill -INFO dd; sleep 10; doneShow Sample Output

This line unbuffers the interactive output of rsync's --progress flag
creating a new line for every update.
This output can now be used within a script to make actions (or possibly piped into a GUI generator for a progress bar)

What happens here is we tell tar to create "-c" an archive of all files in current dir "." (recursively) and output the data to stdout "-f -". Next we specify the size "-s" to pv of all files in current dir. The "du -sb . | awk ?{print $1}?" returns number of bytes in current dir, and it gets fed as "-s" parameter to pv. Next we gzip the whole content and output the result to out.tgz file. This way "pv" knows how much data is still left to be processed and shows us that it will take yet another 4 mins 49 secs to finish.
Credit: Peteris Krumins http://www.catonmat.net/blog/unix-utilities-pipe-viewer/Show Sample Output

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again.
That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and
voted up or down.

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted
to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning,
there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.