How to pipe kldstat output to a file in console

Polytropon freebsd at
Thu Oct 24 06:45:04 UTC 2019

On Wed, 23 Oct 2019 21:00:07 -0500, Clay Daniels Jr. wrote:
> Bingo!
> create /root/kldstat_file with vi
> #kldstat -v >  /root/kldstat_file
> It's all there!

There is no no need to create the file beforehand. The > redirection
will do one of the following automatically:

	a) file not there ---> file will be created

	b) file there ---> file content will be overwritten

So a command like

	# kldstat -v > /root/kldstat.txt

will work no matter if the output file is already there or not.
This is the shell's default behaviour.


If you want to append to a file, use >> instead of >.

Sidenote 2:

The easiest way to create an (empty) file is to use the "touch"
program, for example if you want to add the output of several
commands to a file:

	# touch /root/stuff.txt
	# ls / >> /root/stuff.txt
	# kldstat -v >> /root/stuff.txt
	# dmesg >> /root/stuff.txt

Sidenote 3:

In case you want to record a whole terminal session, including
commands and their outputs, use the "script" program:

	# script /root/session.txt
	. . . your commands here . . .
	# exit

This is very convenient if you want to document the command _and_
their outputs.

Magdeburg, Germany
Happy FreeBSD user since 4.0
Andra moi ennepe, Mousa, ...

More information about the freebsd-questions mailing list