Tracking command history across multiple computers
Magic Shell
Atuin adds some handy queries to the shell history function, while letting you synchronize your command history across the network.
"What was that long command I entered on my notebook last year that showed me all the installed packages?" If questions like these sound all too familiar, read on.
Unix shells such as Bash, Fish, or Zsh already have basic functions for reviewing the last commands typed at the command line. The up arrow key can be used to browse the command history, with each keystroke scrolling back one entry.
For commands that were executed a while ago, the Bash history
function offers a little more information and convenience. The history
function first appeared in Unix in 1978 in the C shell and spread from there to many command-line interpreters up to and including Microsoft's command.exe
. A detailed manual [1] for the history
function can be found on the DigitalOcean website (Figure 1).
The Atuin [2] history tool takes this review function to the next level. Atuin replaces the existing shell history with an SQLite database, imports the previous history, provides more search options, and records additional context about the commands used in Atuin.
Atuin also synchronizes the recorded history to other devices on the network using end-to-end encryption via an external server. This feature allows users with multiple computers on their network to not only use the shell history of a single session or computer, but to also retrieve the entire history of all synchronized devices. Atuin currently supports the Bash, Fish, and Zsh shells.
Atuin is named after A'Tuin, the turtle that carries the Discworld through space in Sir Terry Pratchett's novels. Written in Rust, Atuin runs either as a client on the desktop or is self-hosted as a client-server application. If you choose the client-server option, synchronization will take place via your server; otherwise, a server belonging to the project is used. If you do not want to synchronize, you can disable the function (which is enabled by default) in the settings.
Installation
Some distributions include Atuin in their package sources, including Alpine Linux, Arch Linux, NixOS, and Manjaro. If you install Atuin via a distribution package, you then need to run three commands to write the required hooks to the .bashrc
file (Listing 1).
Listing 1
Writing Hooks to .bashrc
$ curl https://raw.githubusercontent.com/rcaloras/bash-preexec/master/bash-preexec.sh -o ~/.bash-preexec.sh $ echo , -f ~/.bash-preexec.sh && source ~/.bash-preexec.sh' >> ~/.bashrc $ echo ,eval "$(atuin init bash)"' >> ~/.bashrc
Users of Debian-based distributions can retrieve an up-to-date binary package of the current version 11 from Atuin's GitHub page [3]. For all other distributions, Atuin can be installed using a script (Figure 2) that you call as shown in line 1 of Listing 2.
Listing 2
Installing Atuin
01 $ bash <(curl https://raw.githubusercontent.com/ellie/atuin/main/install.sh) 02 [...] 03 $ atuin register -u <user> -e <email> -p <password> 04 $ atuin import auto 05 $ atuin sync 06 [...] 07 $ atuin login -u <User> -p <Password> -k <Key>
Next, import the previous shell command history using the command:
atuin import auto
Atuin is now ready for use in this constellation. If you want to synchronize via the Atuin server, call the script and then run the commands shown in lines 3 to 5 of Listing 2.
Alternatively, a Docker image can be used to install on a server [4]. A Docker Compose file is available for easy rollout [5].
Configuration
Atuin creates files in two places in your home directory. The SQLite database can be found in .local/share/atuin/
. You need to store the configuration file (Figure 3) in TOML format [6] in .config/atuin/
. During synchronization, the encryption key is also stored in the ~/.local/share/atuin/
directory and can be retrieved using the atuin key
command. You need this key to log into a synchronized machine using the command in line 7 of Listing 2.
Create the server.toml
file for installation on a server in ~/.config/atuin/
. In the configuration file for the client on the desktop, you can change the path to the database, disable synchronization, set the interval, and link to a separate server, among other things. The documentation specifies one hour as the synchronization frequency, but the configuration file sets sync_frequency
to five minutes. If you set this to zero instead, Atuin synchronizes after each command.
For search mode, you can choose between the prefix
, fulltext
, and fuzzy
options, with prefix
as the default. The full text search works like a search engine and tries to identify the closest match to the search term. The developers describe the fuzzy search syntax in the documentation [7].
You can additionally set up a filter mode [8] for the search using the GLOBAL
, HOST
, SESSION
, and DIRECTORY
options, which will narrow down the results accordingly.
For some initial orientation regarding the available options, use the help command atuin --help
in the usual way. In the simplest case, calling atuin search
will return the desired results (Figure 4).
Interactive Mode
Atuin offers an interactive mode, which you enter by typing
atuin search -i
and exit by pressing Ctrl+C. If you don't specify any other arguments, the command shows the history of the commands entered, with the last command entered at the bottom of the list (Figure 5). The number of commands shown depends on the specification for HISTFILESIZE
in .bashrc
, with the number of stored commands limited to 500 by default.
Use the mouse wheel or arrow keys to move through the list of commands. The numbers to the left of the commands let you jump directly to the respective command by pressing Alt+Number. Before each command, Atuin also shows you the length of a command's runtime. At the bottom of the window, an input line allows you to limit the output using keywords (Figure 6). If you enter apt
in the input line, for example, only commands that contain this keyword will appear.
In Figure 6, you will see the default GLOBAL
filter specification on the far left of the input line. GLOBAL
displays the commands from all synchronized histories. You can press Ctrl+R or type HOST to limit the filter to the computer you are currently using, type SESSION for just the current session, or type DIRECTORY for commands called from the current working directory.
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
Fedora 40 Beta Released Soon
With the official release of Fedora 40 coming in April, it's almost time to download the beta and see what's new.
-
New Pentesting Distribution to Compete with Kali Linux
SnoopGod is now available for your testing needs
-
Juno Computers Launches Another Linux Laptop
If you're looking for a powerhouse laptop that runs Ubuntu, the Juno Computers Neptune 17 v6 should be on your radar.
-
ZorinOS 17.1 Released, Includes Improved Windows App Support
If you need or desire to run Windows applications on Linux, there's one distribution intent on making that easier for you and its new release further improves that feature.
-
Linux Market Share Surpasses 4% for the First Time
Look out Windows and macOS, Linux is on the rise and has even topped ChromeOS to become the fourth most widely used OS around the globe.
-
KDE’s Plasma 6 Officially Available
KDE’s Plasma 6.0 "Megarelease" has happened, and it's brimming with new features, polish, and performance.
-
Latest Version of Tails Unleashed
Tails 6.0 is based on Debian 12 and includes GNOME 43.
-
KDE Announces New Slimbook V with Plenty of Power and KDE’s Plasma 6
If you're a fan of KDE Plasma, you'll be thrilled to hear they've announced a new Slimbook with an AMD CPU and the latest version of KDE Plasma desktop.
-
Monthly Sponsorship Includes Early Access to elementary OS 8
If you want to get a glimpse of what's in the pipeline for elementary OS 8, just set up a monthly sponsorship to help fund its continued existence.
-
DebConf24 to be Held in South Korea
Busan will be the location of the latest DebConf running July 28 through August 4