Transforming My Linux Terminal Sessions into Daily Speedrun Adventures

Having used Linux for several years, I continuously uncover new ways to enhance my experience. It seems there’s always a quicker method to accomplish tasks. I’ve recently concentrated on these efficiency boosts to optimize my time spent in the terminal.
By monitoring command execution times and pinpointing performance enhancements, my routine Linux activities have become increasingly streamlined. Here’s what I’ve discovered.
Begin Tracking Your Commands
The First Step: Identify Time Wasters
The simplest method to gauge the time a command takes is by utilizing the built-in time command. This is particularly useful for optimizing commands or scripts you’ve created.
While using time as a general tool for reporting can be cumbersome, I wanted a rapid way to determine how I was spending my time in the terminal. If you use zsh, it’s possible to access two events: preexec, which executes just before the shell runs a command, and precmd, which runs just before the shell returns to the prompt.
timer_preexec() {
TIMER_START=$EPOCHREALTIME
}
timer_precmd() {
if [ -n "$TIMER_START" ]; then
local duration=$(( EPOCHREALTIME - TIMER_START ))
# Utilize $duration as needed here
unset TIMER_START
fi
}
add-zsh-hook preexec timer_preexec
add-zsh-hook precmd timer_precmd
The full version of this script also includes a condition that alters the PROMPT variable if the duration exceeds a defined threshold, allowing for notifications when a command is taking too long. This method is just the beginning and can be expanded further to log records if desired.
An alternative method employs the REPORTTIME variable in zsh to automatically track the time for every command:
export REPORTTIME=0
By setting REPORTTIME to a specific number of seconds, you can configure it to only display reports for commands that take longer than that time.
Enhancing Everyday Terminal Efficiency
Finding Quicker Methods Is Common
The second aspect of speeding up your work involves using shortcuts. These may seem small initially, but collectively they lead to significant time savings and less routine hassle.
Avoid Relying on the Up Arrow
I often find myself wasting time redoing or rewriting past commands in the terminal. Relying on the history functionality allows for easy retrieval of previous commands: pressing Up multiple times, then hitting Enter to rerun, or editing the command with Left, Right, and Backspace. You might even be using Ctrl + A to quickly jump to the start of the line.
However, much of this typing can be avoided. For instance, you can use !$ to reference the last argument of the previous command:
mkdir -p my/new/directory
cd !$
This shortcut is particularly useful when executing a newly made executable (ensuring to add the ./ prefix if it’s not in your PATH):
chmod +x foo.sh
./!$
There are numerous history shortcuts, such as !! that re-runs the last command:
apt install something
# Oops, need root permissions...
sudo !!
Yet, there are additional methods to modify prior commands. One of my preferred techniques is caret substitution:
$ cd my/new/directry
cd: no such file or directory
$ ^tr^tor
cd my/new/directory
This syntax alters the last command by replacing the first occurrence of the first term with the second, then immediately re-executes it. I’ve started adopting this method instead of the more cumbersome up-arrow approach, and it has significantly increased my speed once I adapted to it.
Moreover, the fc command is among the most valuable commands that you may not be utilizing. By default, it opens the last command in your terminal’s editor and runs it upon exit. This option is often quicker than caret substitution, history shortcuts, or manually adjusting the cursor.
Implement Aliases and Functions
There are likely commands—or sets of commands—you frequently execute without a second thought. Although this may be quick, it can be made even faster through the use of aliases.
Aliases allow for simple text replacements. For example, instead of typing ls -lh repeatedly for a detailed file listing, you could define a simple alias:
alias ll='ls -lh'
Once established in a file like .bashrc, this alias can save considerable typing time, especially for longer commands. I use eza instead of ls, leading to a more complex alias:
alias ll='eza --long --sort=size --reverse'
This saves significant typing effort, especially since I use this alias plentifully throughout each day.
If your aliases begin to become complex, consider utilizing a function. Functions permit parameter usage and control flow, and they can be invoked from your shell scripts. One particularly beneficial function I define is:
mkd() {
mkdir -p -- "$1" && cd -P -- "$1" || exit
}
This function name is shorter than the typical mkdir, representing a time-saving every time you create a directory. Additionally, it automatically navigates into the directory after creation, with the -p option to create any necessary parent directories. However, while using -p consistently offers efficiency, it may cause some errors to be overlooked. But a true efficiency seeker is willing to accept these minor risks for quicker results.
Choose Faster Tools
While the essential Linux toolkit is reliable and established, numerous alternative tools are available. Many of these are developed with modern programming languages such as Rust, which offer speed and safety.
Consider utilizing improved command-line tools like tmux for session management, fzf and fd as swift alternatives to search commands, and zoxide for more efficient navigation than traditional cd commands.
Acknowledge and Eliminate Your Limits
Your shell encompasses many robust features that not only gauge your productivity but also enhance it. From tab completion to background processes and command chaining, there are abundant tools available to improve your workflow.



