Does htop Support Custom User Macros?
This article explores whether the popular Linux command-line
monitoring tool htop supports custom user macros for
process management. While htop is renowned for its
interactive interface, built-in filtering, and seamless process signal
management, it does not natively support a custom scripting or macro
engine. However, users can achieve macro-like automation and advanced
process management by leveraging htop’s extensive built-in
keyboard shortcuts, customizing its configuration file, or pairing it
with external shell scripts and aliases.
The Limits of Native Customization in htop
By default, htop is designed as an interactive,
real-time system monitor rather than a programmable automation platform.
Because of this design philosophy, there is no internal scripting
language or “macro recorder” within the application. You cannot bind a
complex sequence of internal htop commands (such as “filter
by user X, sort by memory, and send signal 15”) to a single custom
hotkey.
Built-In Alternatives That Mimic Macros
While you cannot program custom macros from scratch,
htop provides a robust set of native functions that reduce
the need for them. Mastering these built-in workflows often eliminates
the manual repetition that macros would otherwise solve:
- Tagged Process Operations: Instead of writing a
macro to kill multiple specific processes, you can use the
Spacebarto tag multiple individual processes, orUto untag them. Once tagged, pressingF9allows you to send a management signal (likeSIGKILLorSIGTERM) to all selected processes simultaneously. - Filtering and Searching: Pressing
F4allows you to filter the process list by name instantly. Combining a filter with the tagging system allows for rapid, semi-automated bulk process management. - The User Filter: Pressing
ubrings up a menu to instantly isolate processes owned by a specific user, bypassing the need to manually scroll or search.
Implementing “External Macros” via CLI and Configuration
If you require true automation or custom shorthand commands for
process management, the standard practice is to handle these workflows
outside of htop using traditional Linux scripting tools, or
by modifying htop’s setup:
- Customizing Setup via F2: You can deeply customize
what
htopdisplays by pressingF2. This setup menu allows you to configure specific column layouts, meters, and sort orders. This custom state is saved to~/.config/htop/htoprc, meaninghtopwill always open in your preferred management layout without needing a macro to set it up. - Using Shell Aliases and Scripts: For repetitive
process management tasks that
htopcannot automate, standard bash/zsh aliases or custom shell scripts are the best substitute. For example, if you frequently need to find and terminate a specific cluster of hung processes, a combined pipeline usingpgrep,awk, andkillmapped to a terminal alias will deliver the precise automation that an internal macro would provide.