Using hardware related commands in your scripts can be handy.
In this article we will review a few of them.
If you identify others which can be useful, don't hesitate to put a comment at the end:)
Command | Description |
top | Displays real-time CPU along with running processes |
listdev | Shows detailed information about all recognized hardware devices (PCI, ACPI, etc.) |
listusb | Lists all connected USB devices with identifiers and class descriptions |
sysinfo | Displays detailed system information, including CPU cores, memory usage, and system architecture. |
df | Displays disk usage and available space for each mounted volume |
nproc | Returns the number of logical processors available on the system |
eject | Ejects removable storage devices like USB drives or optical media |
bfsinfo | Displays detailed information about BFS volumes |
checkfs | Verifies and optionally repairs a BFS file system for integrity issues. |
iroster | Lists input devices recognized by the Input Server, including type (keyboard, pointing device) and current state |
This command is useful when you need to identify the CPU usage on your system per process.
In a Terminal type:
top
The above screenshot is from UTM on my MacBook Pro (Intel 12 Core).
We can see these information:
Hence GLTeapot is using 15,5% of the CPU if we do the sum of all the threads attached to this process.
The system is not overloaded because 79.9% is in idle mode, while 19.7% is used by all the current processes which are running in the system.
This command can be useful in case you need to identify processes which are using too much of your CPU.
As the top command is on interactive mode by default, you can use the below option to deactivate this mode:
top -n 1 > processes.txt
lpe processes.txt
In the above example, you will have the current list of processes in a text file.
This command will give you information relative to your devices.
In a Terminal type :
listdev
For instance, the display device is identified as an Intel Iris Graphics 540.
Which is confirmed, if I open the Devices application :
This command list all the connected USB devices with their identifiers and class descriptions.
listusb
It can be useful if you need to make the link between an USB device and how to identify it like "/dev/bus/usb/4/0"
This is a great command when you need to have information like CPU cores, memory usage, and system architecture.
To retrieve all the possible options of this command type:
sysinfo -h
If you need to have information relative to the CPU :
sysinfo -cpu
You can also check for the memory available :
sysinfo -mem
Really useful command:)
This command stand for "disk free" and it displays disk usage and available space for each mounted volume.
In a Terminal type :
df
On this BFS volume of 20 Gb, 11.8 Gb are free.
The device identifier is also given (ie /dev/disk/scsi/0/1/0/raw)
A simple but nice command to return the number of logical processors available on the system.
nproc
This is the number of core available via UTM on my MacBookPro :)
In case you need to eject devices like USB drives or optical media, this command is for you!
Let's suppose you have connected a Haiku live USB stick as below :
To eject it, type :
eject /Haiku_Live1
When you hit return to launch the command, the live stick will be ejected :
This command displays detailed information about BFS volumes.
In a Terminal type :
bfsinfo /boot
In this example, "boot" is the name of the BFS volume to check.
This command is only needed to verify and optionally repairs a BFS file system.
In a Terminal type:
checkbfs /boot
In case you need to know which input devices are recognized by the Input Server, the iroster command is the one to use :)
In a Terminal type :
iroster
On this system, three USB devices are recognized :
I hope you have found this article useful, the series on the scripting commands will continue in the coming weeks:)