- Kloudnative
- Posts
- Essential Terminal Tools That Supercharge Your Productivity
Essential Terminal Tools That Supercharge Your Productivity
A Developer's Guide to Command Line Efficiency
The evolution of command line tools offers a fascinating glimpse into how developers solve common challenges. Time and again, I've discovered that whenever I face a workflow bottleneck or wish for a more efficient way to accomplish a task, someone in the developer community has likely encountered and solved that same problem. This is particularly true in the realm of terminal utilities, where innovative developers have taken the traditional shell commands we use daily and transformed them into something extraordinary.
What's particularly exciting is how these modern tools build upon the solid foundation of classic Unix commands, enhancing them with features that speak to today's development needs: faster execution, intuitive interfaces, and thoughtfully designed output that's both informative and visually appealing. Rather than reinventing the wheel, these utilities represent the natural progression of command line interfaces, shaped by real-world usage and modern computing demands.
In this guide, I'll walk you through six exceptional terminal utilities that have significantly streamlined my development workflow. For each tool, you'll learn not only how to install and configure it, but also how to leverage its features effectively in your daily work. These aren't just marginal improvements over existing tools—they're transformative additions to your terminal toolkit that can fundamentally change how you interact with your development environment.
Kloudnative is committed to staying free for all our users. We kindly encourage you to explore our sponsors to help support us.
Learn AI in 5 minutes a day
What’s the secret to staying ahead of the curve in the world of AI? Information. Luckily, you can join 800,000+ early adopters reading The Rundown AI — the free newsletter that makes you smarter on AI with just a 5-minute read per day.
☝️ Support Kloudnative by clicking the link above to explore our sponsors!
dust: A Lightning Fast, Modern Alternative to du
Dust is a lightning-fast, modern alternative to the traditional du (disk usage) utility. If you're tired of the standard du output and want something more user-friendly, Dust might just be the solution for you. It operates similarly to du, but presents its findings in a format that's much easier to read, allowing you to quickly grasp how much space each directory occupies.
The name "Dust" comes from combining "du" with Rust, the programming language it's written in. This choice of language contributes to its efficiency, making it capable of scanning hundreds of gigabytes of data in no time. Dust generates a beautifully organized tree structure of directories and visually represents disk usage per directory using a bar graph format, all at impressive speeds.
Visual Output
One of the standout features of Dust is its colorful output. The different colors in the bars help illustrate the subdirectory structure, similar to a tree diagram. For instance, the base directory (let's say "data") will have an opaque bar representing 100% of the total data. Subdirectories will also have opaque bars, while nested directories are shown with transparent bars that align with their parent directory, clearly indicating their hierarchy.
Performance Benchmarking
To demonstrate just how efficient Dust is, I benchmarked both du and Dust using the built-in time command to measure how long each took to calculate the size of my external SSD's contents. Here’s how the commands looked:
$ time du -sh /Volumes/data
$ time dust /Volumes/data
I ran both commands ten times. The findings were impressive: Dust outperformed du by an average of 81%! Not only does Dust provide a quick calculation of disk usage, but it also formats this information in a visually appealing way, making it a clear winner for anyone looking to manage disk space efficiently.
Note on Permissions
It's worth mentioning that because my external drive uses macOS, there are certain directories like .Spotlight-V100 and .Trashes that are created by the system. These directories are essential for Spotlight search functionality and managing files in trash but cannot be accessed by Dust—even with elevated permissions—since root access is required.
Installation instructions
Installing Dust is a breeze, and you have a couple of options to choose from! You can either go with your preferred package manager or grab the pre-compiled binary from their Releases page. If you decide to take the binary route, just un-tar the archive and move the executable to your local binary directory. Here’s how to do it:
$ tar -xvf <dust_v0.8.X*>.tar.gz && sudo mv dust_v0.8.X*/dust /usr/local/bin
Package Manager Installation
If you prefer using a package manager, here’s how you can install Dust on MacOS and Linux:
For MacOS and Linux:
$ brew install dust
You can also install Dust using Cargo, which is the Rust package manager (in Cargo's terminology, packages are referred to as "crates"):
$ cargo install du-dust
For more detailed installation instructions using these methods and others, feel free to check out the installation guide on the Dust GitHub repository. Happy installing!
Usage
To check the size of each subdirectory, you can simply use the basic Dust command like this:
$ dust path/to/dir
Dust is smart enough to adjust the depth of the tree it displays based on your terminal size. This means that if you're using a smaller or larger screen, Dust will automatically decrease or increase the depth of the output. This feature is especially handy for tmux users, as it prevents the output from getting cut off and requiring you to scroll back to see everything.
Customizing Output
If you'd like to skip the bar graph in the output, you can add the -b
flag to your command:
$ dust -b path/to/dir
This option is great if you prefer a cleaner look without the visual representation, focusing solely on the directory sizes.
Setting Depth for Detailed Views
As mentioned earlier, Dust will display as much of the directory tree as can reasonably fit within your terminal dimensions. If you want to show more files and directories, you can set the depth of the output using the --depth
option, with a maximum of three levels:
$ dust --depth 2 path/to/dir
This allows you to drill down into specific subdirectories without overwhelming your terminal with too much information at once. For example, if you're interested in seeing just two levels deep, you can quickly get an overview of your directory structure while still keeping things manageable.
Additional Tips
Using Wildcards: You can also use wildcards in your path to quickly analyze multiple directories at once. For example:
$ dust path/to/*
This command will give you a summary of all subdirectories within "path/to".
Combining with Other Commands: Dust works well with other command-line tools. You can pipe its output into other commands for further processing. For instance:
$ dust path/to/dir | less
This allows you to scroll through large outputs more comfortably.
Getting Help: If you're ever unsure about how to use Dust or want to explore more options, you can always check out the help menu by running:
$ dust --help
This will provide you with a list of available commands and flags, helping you make the most out of this powerful utility.
ripgrep: An Intuitive and Blazing-fast Alternative to grep
The speed of ripgrep is what convinced me to switch to it as my go-to grep-like command. This impressive speed stems directly from the regular expression engine it uses, along with the fact that it’s implemented in Rust. Additionally, ripgrep beautifully highlights its output, making it a significant improvement over the traditional grep --color.
Honestly, this has become one of my favorite shell utilities. Not only is it shorter to type than grep, but it's also easier to use and packed with more features. It feels much more intuitive; just run the command without any options, and it will search all files in a specified directory for the string you provide. For example:
$ rg '<phrase>'
This command searches all files for the specific phrase in the base directory and each subdirectory relative to your current location. While you could accomplish this with grep -r, ripgrep does it significantly faster.
Extreme Speed
As I mentioned earlier, the standout feature of ripgrep is its extreme speed. It makes light work of scanning a large number of files spread across multiple subdirectories and can handle more complex searches without sacrificing performance. This efficiency is largely due to its regex engine, which intelligently searches for files you likely want to check before passing them through its regex processing.
For instance, ripgrep skips hidden and binary files by default (though you can change this behavior with the --hidden and --binary options). It even respects your .gitignore files, allowing it to skip over unnecessary files seamlessly. Another reason for its quick performance is walkdir, a directory iterator written in Rust that enhances its regex matching capabilities.
Andrew Gallant, one of the developers behind ripgrep, conducted extensive benchmarking tests that are detailed in his blog post. He compared ripgrep's performance against other tools like grep, Universal grep (uvgrep), git grep, The Silver Searcher (ag), and The Platinum Searcher (pt). In nearly all tests, ripgrep vastly outperformed its competitors. If it was outperformed by another tool, the difference was often less than 10 milliseconds—an almost negligible gap.
For a thorough look at ripgrep's performance metrics, methodology, and results from all 21 benchmarks, check out Andrew Gallant's blog post.
Enhanced Output
One more point worth mentioning is that compared to grep, which provides minimal highlighting by default (and only a basic level when using the --color option), the output from rg is much easier to read and interpret. The colors used can be customized according to your preferences with the --color option. By default, magenta highlights the file name, green indicates the line number, and red marks the matched regular expression (regex). You can specify these colors as arguments associated with the --color option.
To make your life easier, consider creating an alias or a shell function that applies your preferred color scheme every time you run the command. If you're unsure how to set up aliases or write shell functions, feel free to check out my articles on those topics!
ripgrep stands out not just for its speed but also for its user-friendly features and customizable output. If you’re looking for a powerful tool to enhance your command-line experience, give ripgrep a try—you might find it becomes an indispensable part of your workflow!
Installation instructions
You can easily install ripgrep using your preferred package manager or by downloading the pre-compiled binary from their Releases page. If you choose the binary installation method, just un-tar the archive and move the executable to your local binary installation directory. Here’s how you can do it:
$ tar -xvf <ripgrep-14.*>.tar.gz && sudo mv ripgrep-14.*-aarch64-apple-darwin/rg /usr/local/bin
Package Manager Installation
For those using package managers, follow the instructions below based on your operating system.
MacOS and Linux:
To install ripgrep on MacOS and Linux, you can use Homebrew:
$ brew install ripgrep
Alternatively, if you prefer Rust's package manager, you can install it via Cargo:
$ cargo install ripgrep
For installation instructions on other operating systems or methods, check out the detailed guidelines on the ripgrep GitHub repository.
Usage
To recursively search through your current subdirectory for a specific phrase, simply execute:
$ rg '<phrase>'
Customizing Highlighting Colors
If you want to change the highlighting colors used by ripgrep, you can utilize the --color option. The syntax looks like this:
--color '<type>:[fg/bg]:<color>'
For example, if you want to highlight the matched expression in green instead of the default red, you would add:
--color 'match:fg:green'
If you'd like to set the background color to yellow for better visibility, you can append another color option to your command like this:
$ rg --color 'match:fg:green' --color 'match:bg:yellow' '<phrase>'
Searching for Files Without a Certain Phrase
Sometimes, you may want to find files that do not contain a specific matched expression. In such cases, you can use the--files-without-match option:
$ rg --files-without-match 'phrase'
For a more detailed discussion on ripgrep and a collection of extremely helpful command examples, be sure to check out Marius Schulz's article titled "Fast Searching with ripgrep." This resource provides additional insights and tips to enhance your usage of this powerful tool!
bat: The New-and-Improved cat
bat is a file concatenation and printing tool that significantly enhances its predecessor, cat, by offering a wealth of options while maintaining a similar command syntax. One of the standout features of bat is its syntax highlighting, which makes it much easier to inspect files at a glance. Additionally, bat can be integrated seamlessly with git and other tools like fuzzy finder (fzf), find, fd, and even ripgrep.
At first, I was skeptical about switching from cat, as I thought it was sufficient for my daily needs. However, bat has proven to be a game-changer. Much like cat, it serves as a file concatenation and printing tool but brings a host of improvements that make it far more versatile. The syntax highlighting alone has made a noticeable difference when reviewing code or configuration files. Moreover, the ability to display non-printable characters (such as spaces and tabs) is incredibly useful for quickly debugging poorly formatted Python code on the fly. One of my favorite features is using bat to breathe new life into man pages by adding intelligent syntax highlighting!
bat's integration capabilities are impressive as well. It works smoothly with git and other command-line utilities, allowing for enhanced workflows. For more information on how to interface bat with these tools, you can check out the Integration with other tools section on the bat GitHub page.
Key Features of bat
Syntax Highlighting: By default, bat automatically highlights the syntax of text files based on their file extension. If needed, you can manually specify the language using the --language or -l option. For example:
$ bat -l python script.py
Display Non-Printable Characters: This feature is particularly helpful for debugging code by making invisible characters visible.
Git Integration: When working in a git repository, bat automatically highlights changed lines, making it easy to spot modifications at a glance.
User-Friendly Paging: Unlike cat, which dumps all content at once, bat displays files in a scrollable format similar to less. This makes it easier to read long files without overwhelming your terminal.
Customizable Themes and Styles: You can customize how bat displays content using various styles and themes. For instance:
$ bat --theme <theme-name>
Line Numbers: Bat displays line numbers by default, helping you quickly locate specific lines within a file.
Range Selection: You can easily print specific sections of a file using the -r option:
$ bat -r 30:40 filename
Miscellaneous Features: Bat also includes options like
-A
to print all characters visibly (including whitespaces) and-H
to highlight specific blocks of text.
Installation instructions
You can install bat using your package manager of choice or by downloading the pre-compiled binary from their Releases page. If you opt for the binary installation method, simply un-tar the archive and move the executable to your local binary installation directory. Here’s how you can do it:
$ tar -xvf <hyperfine-v1.*.*-x86_64-apple-darwin>.tar.gz && sudo mv hyperfine-v1.*.*-x86_64-apple-darwin/hyperfine /usr/local/bin
Package Manager Installation
For those using package managers, follow the instructions below based on your operating system.
MacOS and Linux:
To install bat on MacOS and Linux, you can use Homebrew:
$ brew install bat
Alternatively, if you prefer Rust's package manager, you can install it via Cargo:
$ cargo install --locked bat
For installation instructions on other operating systems or methods, refer to the bat GitHub repository.
Usage
Using bat is straightforward, as it retains a similar command syntax to cat. To view a file, simply execute:
$ bat path/to/file
To exit bat, just hit q, since it functions as a terminal pager.
Concatenating Files
Concatenating files is just as simple as with cat. You can enter multiple files as positional arguments and use redirection operators (> or >>) to append or overwrite the target file. For example:
$ bat file0.txt file1.txt file2.txt > file_012.txt
This command concatenates the three text files file0.txt, file1.txt, and file2.txt, resulting in one larger file named file_012.txt.
Extra Features
The fun begins with the extra features of bat. One useful option is showing all non-printable characters, like returns, tabs, spaces, etc. You can achieve this with the --show-all option:
$ bat --show-all path/to/file
If you want to add color to your man pages (which are displayed via a pager), you can pipe them to bat. To do this, you'll need to export the environment variable MANPAGER. You can enter this command on the command line for the current shell session or add it to your shell's profile or rc files:
export MANPAGER="sh -c 'col -bx | bat -l man -p'"
Customizing Themes
You can change the syntax highlighting theme by checking out the 24 available themes using the --list-themes option. For example, to see examples of the first seven color palettes, you can run:
$ bat --list-themes
To add more (or custom) themes, refer to the "Adding new themes" section on the bat GitHub repository for detailed instructions.
Conclusion
In summary, the trio of tools we've explored—dust, ripgrep, and bat—each brings significant enhancements to traditional command-line functionalities, making them indispensable for modern developers and system administrators.
Dust offers a fast and visually appealing alternative to the classic du command for assessing disk usage. Its intuitive output, complete with color-coded visual representations, allows users to quickly grasp how much space each directory occupies. With its impressive speed and efficiency, Dust is a powerful ally for anyone managing disk space.
Ripgrep revolutionizes the way we search through files with its lightning-fast performance and intelligent handling of regular expressions. By integrating seamlessly with git and other command-line tools, ripgrep not only simplifies searching but also enhances productivity. Its user-friendly features, such as syntax highlighting and the ability to exclude certain files, make it a must-have for anyone who frequently works with large codebases.
Bat, on the other hand, modernizes the file concatenation and printing experience. With features like syntax highlighting, pagination, and the ability to display non-printable characters, bat elevates the functionality of the traditional cat command. Its integration with other utilities and customizable themes further enhance its usability, making file inspection and management more efficient and visually engaging.
Together, these tools embody the spirit of innovation in the command-line environment. They not only improve upon their predecessors but also introduce new features that cater to the needs of today’s users. By incorporating Dust, Ripgrep, and Bat into your workflow, you can streamline your tasks, enhance your productivity, and enjoy a more efficient command-line experience. Embrace these powerful utilities and transform the way you interact with your system!