What does “batch mode” mean for the top command

io-redirectionterminologytop

I was reading about the top command and I came across something I don't quite understand:

top options:

-b Run in batch mode. This is useful for sending output from top to other programs or to a file. It executes the number of iterations
specified with the -n option and terminates.

What is batch mode?

Otherwise :

How -b option is useful in the following command which iterates 5 times:

top -b -n 5 > file1

What is the difference between the command above and the following command which get rid of -b option:

top -n 5 > file1

Best Answer

Batch mode refers to batch processing, which means automated processing, without human intervention. Batch is the opposite of interactive.

In batch mode, top produces output that's more sensible for collecting to a log file or for parsing (though top isn't really good at producing parseable output even in batch mode). There is no limit on the number of output lines and the output doesn't contain any escape sequences for formatting.

In interactive mode, top produces output intended for human viewing. In particular, it only displays one screenful of data. The output contains some escape sequences for formatting. Top operates in interactive mode even when its output is redirected to a file; only the presence of the -b option matters.

Related Question