A recommend method to run a command at startup?

To actually answer the title, the crontab’s @reboot directive runs a command at very early in the boot process, but I’ve for instance used it to for basic data management tasks, such as wiping unwanted temp files.

To run a command after the user has logged in on Gnome, a .desktop file in ~/.config/autostart/) can be used; mine as an example:

[Desktop Entry]
Exec=gnome-terminal -- /home/user/bin/other/mount-and-update.sh

This intentionally brings up a terminal window. I use the script to interactively mount (asks for a password) encrypted drives and update Flatpak packages:


# SATA SSD (1)
udisksctl unlock --block-device /dev/sdc1
udisksctl mount --block-device /dev/mapper/luks-several-strings

# system update
flatpak remove --unused && flatpak update -y
sleep 30m

The drive may be mounted automatically. The sleep command is used since I don’t recall how to keep the terminal window open otherwise (allows verifying the updating process, but you may also redirect to a file).