cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
5651
Views
16
Helpful
2
Comments
Alex Stevenson
Cisco Employee
Cisco Employee

CommandLineToolsinRustPart1-A.png

 

Skilled network engineers, developers, system admins, etc. use Unix/Linux commands line tools/utilities such as …. cat, ls, man, ps, etc..

Most of these were originally written for Unix or Unix-like operating systems, have been around for decades and, while they are still very useful, we can now take them to the next level with their equivalents in the Rust language. Some are upgrades to existing tools and some are brand new and much needed.

Rust is a newer language (2010) that has become extremely popular. It is a powerful, fast, multi-platform, multi-paradigm, high-level, general-purpose programming language, which was recently added to the Linux kernel. According to the Stack Overflow Developer Surveys, Rust has been the "most loved programming language" every year from 2016 to 2022 (inclusive).

Just install Rust and each tool you want to try out. Most of these tools can be installed with the standard operating system package managers, or you can use the Rust package manager, known as Cargo, which should work on most platforms. If you need help installing and setting up Rust, just scroll to the bottom of this article.

Here are the command line tools I’ll be talking about in this article: 

  • Atuin - magical shell history
  • bat - A cat(1) clone with wings
  • difftastic - A structural diff that understands syntax
  • lsd - An ls command with a lot of pretty colors and some other stuff
  • names - A random name generator for use in container instances, project names, etc
  • procs - A modern replacement for ps
  • ripgrep - supports many of the same features found in grep, but is super fast
  • tealdeer - Fetch and show tldr help pages for many CLI commands. 

 

Let the excitement begin!

 


Atuin - magical shell history

AlexStevenson_0-1676991383447.png

Follow install instructions:
https://lib.rs/crates/atuin

 

Tabbing-up to find previous commands can often make things much easier in your Terminal, Shell, IDE, CLI, etc.

Atuin takes that concept to the next level. Once, installed, tabbing up will give you this cool GUI experience, showing all recent command and when they were executed.

 

AlexStevenson_2-1676991541024.png

 

Just tab up like you normally would and hit ENTER when the command you want is highlighted.

Atuin replaces your existing shell history with an SQLite database and records additional context for your commands. Additionally, it provides optional and fully encrypted synchronization of your history between machines, via an Atuin server.

 
 

bat - A cat clone with wings

AlexStevenson_0-1676996977333.png

Follow install instructions:
https://lib.rs/crates/bat

 

The cat command in Linux has long been the one of the primary tools for viewing the contents of text files. It gets the job done, but it’s from 1971 and, well, basic.

bat supports display of colorful, customizable syntax highlights, plus line numbers, git modifications, non-printable characters and more. For me, the choice is clear:

 cat 

AlexStevenson_2-1676992210653.png  

bat

AlexStevenson_3-1676992347756.png

 

 


difftastic - A structural diff that understands syntax

AlexStevenson_0-1676992632254.png

Follow install instructions:
https://lib.rs/crates/difftastic

 

Back in the 1970s, the diff tool was created to compare files and shows their differences.

Let’s compare two files I created, using both diff and difftastic:

 

diff my_code_before.py my_code_after.py

AlexStevenson_2-1676993048986.png

 

difft my_code_before.py my_code_after.py

AlexStevenson_1-1676997283715.png

 

I’ll let you decide which one is more helpful.

 

 


lsd - An ls command with a lot of pretty colors and some other stuff

AlexStevenson_7-1676993303421.png

Follow install instructions:
https://lib.rs/crates/lsd

 

ls has been around since 1987 and it lists files and directories. lsd is a rewrite of GNU ls with a lot of added features, such as colors, icons, tree-view, and more formatting options.

ls -l

AlexStevenson_8-1676993484061.png

lsd -l

AlexStevenson_9-1676993540915.png

 

Ah, much better!

 

 


names - A random name generator with names suitable for use in container instances, project names, application instances, etc.

 

AlexStevenson_10-1676993708118.png

Follow install instructions:
https://lib.rs/crates/names

 

5 random names

alexstev % names 5
highfalutin-fireman
mindless-lift
chilly-coat
berserk-interest
abnormal-bag

 

2 random names with a random 4-number pad

alexstev % names –number 2
equal-writing-7043
shivering-partner-8412

 

 

 


procs - A modern replacement for ps

AlexStevenson_11-1676993843710.png
Follow install instructions:
https://lib.rs/crates/procs

 

ps has been used to show “process status” on Unix-like systems since the dawn of time (ok, maybe not that long ago, but it has been 50 years, so close ; ).

procs includes colored and human-readable output, automatic theme detection based on terminal background, multi-column keyword search, tree view and more.

Here’s what procs has, that ps doesn’t:

  • TCP/UDP port
  • Read/Write throughput
  • Docker container name
  • More memory information

 

Let’s see the difference between inspecting process id# 182 with ps versus with procs

 

ps 182

AlexStevenson_12-1676993970797.png

 

procs 182

AlexStevenson_13-1676993994769.png

 

 

 


ripgrep - a line-oriented search tool that recursively searches the current directory for a regex pattern, while respecting gitignore rules and automatically skip hidden files/directories and binary files

AlexStevenson_14-1676994188373.png

Follow install instructions:
https://crates.io/crates/ripgrep

 

ripgrep supports many of the same features found in grep, such as showing the context of search results, searching multiple patterns, highlighting matches with color and full Unicode support. Unlike GNU grep, ripgrep stays very fast while supporting Unicode (which is always on), and even searches compressed files!


Let’s compare the results of grep with the results of ripgrep

 

grep "json" parsing_json.py

AlexStevenson_15-1676994278907.png

 

rg "json" parsing_json.py

AlexStevenson_16-1676994299072.png

 

I’m not saying rest in peace (R.I.P.) to grep just yet, because there are times to still use grep, such as if you need a portable tool which conforms to any standard, such as POSIX; while ripgrep works on Windows, macOS and Linux, it is not ubiquitous.

 

 


tealdeer - Fetch and show tldr help pages for many CLI commands. 

AlexStevenson_18-1676994461588.png

 

Follow install instructions:
https://lib.rs/crates/tealdeer

 

teeldeer is an extremely fast implementation of tldr in Rust; it provides simplified, example based and community-driven man pages. TLDR is internet slang for “Too Long Didn’t Read” and the original tldr tool was designed more recently (within the last 5 years, I believe) for people who didn’t want or have time to read the entire man page of a tool.

Let’s look at the difference between the outputs of “man ls” and “tldr ls”

 

man ls
(prepare to be scrolling for a long time)

AlexStevenson_21-1676994697734.png

 

tldr ls

AlexStevenson_20-1676994636468.png

 

Simply beautiful!

 

 

 

Installing and Setting Up Rust

 

1. Rust is installed and managed by the rustup tool. Add it to your PATH by appending one of the following to your .bash_profile, .bashrc or .zshrc configuration files:

export PATH="$HOME/.cargo/bin:$PATH"


2. You can install Rust using cURL. The most recent version of the command will be found at https://www.rust-lang.org/tools/install

At the time of writing, the command looks like this:

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh


3. Restart your shell with ‘exec bash’, ‘exec zsh’, etc..


4. Check that Rust is installed:

% rustc –version
rustc 1.67.1 (d5a82bbd2 2023-02-07)


We’re good to go!

 

 

Mapping New Commands to the Old Command Names

If you don’t want to learn the names of the new commands, you can create aliases and map the new tools to the old names. For instructions of how to do that, see my Knowledge Base Article titled ‘Developer Basics: Creating Aliases with bashrc and zshrc

 

 

Additional Info

  • This was just the first installment in this series; more articles to come!
  • Inspiration for this article was provided by DJ Ware @CyberGizmo
  • An MP3 version of this article is attached

 

Comments
Alex Stevenson
Cisco Employee
Cisco Employee

** Attention macOS users **

 

If you like the speed and power Rust provides, I recommend you check out the Warp terminal (https://www.warp.dev/)

 

Warp bills itself as the ‘terminal for the 21st century’ and it seems to live up to that, in my opinion.

 

Here are some benefits of the Warp terminal:

 

  • User-Friendly: Feels like a modern code editor, with selections, cursor positioning, and completion menus
  • Speed: Blazingly fast, Fully native, Rust-based terminal. No Electron or web-tech.
  • Private & Secure: All cloud features are opt-in. Data is encrypted at rest.
  • Backwards Compatible: Warp works out of the box with zsh, fish, and bash.
  • A.I. Command Search: GPT-3 powered AI search will convert natural language into executable shell commands. It's like GitHub Copilot, but for the terminal.
  • And More!

 

Thanks to David Nguyen at Cisco for introducing me to Warp!

Verlaine_Devnet
Level 1
Level 1

Insightful ! so much things to discover 

Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community:

Quick Links