Scripting : useful system commands

Scripting : useful system commands

  • mdo  DigitalBox
  •   Scripting
  •   April 9, 2025

Last week, we have reviewed networking commands.

Today, some system commands can be useful in your Haiku's scripts.

Let's review of few of them !

Command Description
FirstBootPrompt Launches Haiku's initial setup wizard, allowing users to configure language, keyboard layout, and system preferences.
date Displays or sets the system date and time.
desklink Creates a shortcut on the deskbar to a specified file or directory.
hostname Displays or sets the system's hostname.
keymap Displays or changes the active keyboard layout.
locale Displays or modifies system-wide locale settings.
uptime Shows how long the system has been running since the last boot.
uname Displays system information such as OS name, version, and architecture.
env Prints the environment variables of the current user session.
useradd Creates a new user account (Haiku primarily operates as a single-user system, so this is limited in use).
whoami Displays the username of the current logged-in user.
groups Lists the groups that the current user belongs to.
launch_roster Manages system services and background applications, allowing users to list, start, stop, or restart services.
sysinfo Displays detailed system information, including CPU cores, memory usage, and system architecture.
top Displays a real-time overview of system resource usage, including CPU and memory consumption.

FirstBootScript

In case you need to relaunch the Haiku installation process, this command might be useful.

If you type in a Terminal :

FirstBootScript

Then the below welcome window will be displayed :

date

What about using dates in your scripts ?

Dates can have various format, that why the date command proposes to customize the date output.

You can play with the date command as per below in a Terminal :

date
date "+%Y-%m-%d"
date "+%d/%m/%Y %H:%M"

You can also indicate a specific time zone to use and compare it with your current time zone :

TZ='America/Los_Angeles' date

Now, if you need to change the date, you can type the below :

date 040414302025.00

It will change the date to 4 April 2025 at 14h30.

The format is date MMDDhhmm[[CC]YY][.ss] where :

  • MM – Month (01–12)
  • DD – Day of the month (01–31)
  • hh – Hour (00–23, 24h format)
  • mm – Minute (00–59)
  • CC – Century (e.g. 20 for 2025) (optional)
  • YY – Year (last two digits) (optional)
  • .ss – Seconds (optional)

desklink

Do you need to put a link of your favorite application or folder into the Deskbar ?

The desklink command is there for you !

In a Terminal, type :

desklink "cmd=Active window (2s):/bin/screenshot --window --border --delay 2 --silent" \
"cmd=Remove:desklink --remove=screenshot" /bin/screenshot


It will create a shortcut in order to propose a quick access to the screenshot application :

You will notice also two extra bonuses :

  • Active window (2) : it will launch a screenshot of the current window (2s of delay)
  • Remove : it will remove the link

For a folder, the command is the same :

desklink /boot/home/config/settings/

You can then click on the folder icon or right click on it to access the "settings" directory :

In case you don't any anymore the link, your can remove it :

desklink --remove=settings

Please note Deskbar links are is not saved after a reboot of the system.

hostname

Do you need to give a name to your machine ?

For that you can use hostname :

hostname Haiku

It's also a good practice to add your machine's name in the "hosts" file :

lpe /boot/system/settings/network/hosts

The format of the file is as per below :

<local IP address> <machine_name>
<local IP address> <machine_name> <alias1> <alias2> ... <aliasN>

In the screenshot above, "Haiku" was added as an alias for the local ip machine 127.0.0.1

After this change, you can try to ping it, and it should work :

ping -c 3 Haiku

keymap

If you need to work with keymaps, the keymap command is the way to go.

In order to identify the keymaps files, type:

ls /boot/system/data/Keymaps

When you have identified the keymap to use, load it with the below command:

keymap -l '/boot/system/data/Keymaps/French (Mac)'

Simple, isn't it ?

locale

The locale commands allows you to find what is the setup for the locale preferences.

Do you need to know the preferred language, the formatting preferences, or the time preferences ?

You can have all these information :

locale -l
locale -f
locale -t

uptime

The Haiku operating system is not really used as a server most of the time.

However, if you need to know since how much hours or days the system is up & running, type: 

uptime

Here, my system is up since 33 minutes :)

uname

This command is often used to identify which platform is used when building applications from sources.

Do you need to now the Operating system name or the machine hardware ?

In a Terminal type :

uname -o
uname -m

If you need to display all the available information for the platform, you can use "uname -a".

env

Another useful information for scripting is the "env" command, meaning "environment".

This command will display all the environment variables defined on your system.

Do you need to know the various PATH variables defined  ?

You can type :

env | grep PATH 

useradd

The Haiku system is not fully handling multi-users, however for specific purposes you can create new users.

For instance, the NGinx package is creating a "nginx" user during its installation.

The command used is "useradd" :

useradd -d /system/settings/nginx/ -s /bin/false -n "nginx user" nginx

When creating a user, you might also want to create a dedicated group.

The groupadd command can be used for that :

groupadd nginx

whoami

A simple command to know the current user name.

In a Terminal, type :

whoami

The default user name under Haiku, is "user".

Very original :)

groups

In case you need to know to which groups a specific user belongs to, you can use the groups command.

In a Terminal type :

groups user

The user "user" belongs to "root" and "party" groups.

Not sure what "party" is useful for :)

You can also have additional information on the list of users in the /etc/passwd file:

cat /etc/passwd | grep nginx

launch_roster

This command lets you manage jobs or services on Haiku.

Do you need information relative to the App Server ?

For that, type in a Terminal :

launch_roster info x-vnd.haiku-app_server

If you are interested in this command, you can check the dedicated article Using the launch daemon for more details.

sysinfo

Are you on a 32 bits or 64 bits system ?

If you need information on your machine, you can use the sysinfo command !

sysinfo -h

For instance, if you need more details on the CPU of your machine, type:

sysinfo -cpu

Nice, isn't it ?

top

Now the last command : top.

By default, the top command is used in interactive mode to display the various processes and their cpu usage:

top

It means it can't be used in scripts.

However what about removing the interactive mode and output the result to a file ?

top -n 1 > processes.txt
lpe processes.txt

By doing so, you can use the output results in your scripts for various usages :)

Do you want to share other useful system commands for Haiku ?

Hit the command "Comment" button below and let us know.


Powered by Bludit - Hosted by Planet Hoster
© 2025 Haiku Insider