In the world of DevOps, Linux is the backbone for most server-based environments. While many are familiar with popular commands like grep
, awk
, sed
, and curl
, there are a plethora of lesser-known but highly effective CLI tools that can make life easier. In this article, we’ll explore some of these hidden gems, providing a brief overview of each and examples of how they can be used in daily DevOps workflows.
1. xargs
The xargs
command can take input from stdin
and execute a command on each item. While it may not be entirely “lesser-known,” it’s often underused. It’s particularly useful when you need to apply a command to multiple files or items.
Example:
cat file_list.txt | xargs -I {} mv {} /backup
This command reads each line from file_list.txt
and moves the listed files to the /backup
directory.
2. fd
fd
is a faster and more user-friendly alternative to the find
command. It simplifies searching for files and directories with a cleaner syntax.
Installation:
sudo apt install fd-find
Example:
fd config
This command will quickly find all files and directories containing “config” in their names.
3. jq
jq
is a lightweight and flexible command-line JSON processor. If you’re dealing with APIs, config files, or any JSON data, jq
will save you a lot of time.
Example:
curl -s https://api.example.com/data | jq '.items[] | {name, id}'
This command fetches JSON data from an API and parses it, extracting the name
and id
fields from each item.
4. ncdu
ncdu
stands for “NCurses Disk Usage,” and it’s a great tool for quickly assessing disk usage in a more user-friendly manner than du -sh *
.
Installation:
sudo apt install ncdu
Example:
ncdu /
It will scan the root directory and give you a navigable view of disk usage.
5. bat
bat
is a clone of cat
with additional features like syntax highlighting, line numbers, and integration with git
. It’s a simple yet powerful enhancement.
Installation:
sudo apt install bat
Example:
bat /etc/passwd
This command displays the content of /etc/passwd
with syntax highlighting.
6. fzf
fzf
is a command-line fuzzy finder that allows you to search through lists interactively. It’s excellent for navigating through files, command history, or even Git branches.
Installation:
sudo apt install fzf
Example:
cat file_list.txt | fzf
This command will open an interactive search window for you to pick files from file_list.txt
.
7. tldr
tldr
is an excellent alternative to man
pages. It provides simplified and community-driven explanations for commands with practical examples, which is particularly useful for quick references.
Installation:
sudo apt install tldr
Example:
tldr tar
It will show a concise summary of how to use tar
with common examples.
8. htop
While top
is well-known, htop
is a more interactive and user-friendly process viewer. It allows for easier navigation, killing of processes, and better visualization of CPU and memory usage.
Installation:
sudo apt install htop
Example:
htop
Just run the command to open an interactive process viewer.
9. at
Unlike cron
, which schedules repetitive tasks, at
allows you to schedule one-time tasks in the future. It’s useful for quick jobs that you need to run later without setting up a cron
job.
Example:
echo "backup.sh" | at 03:00
This will execute backup.sh
at 3:00 AM.
10. entr
entr
is a simple utility that runs arbitrary commands when files change. It’s beneficial for scenarios where you need to run tasks whenever a file is modified, like during development or continuous integration.
Installation:
sudo apt install entr
Example:
ls *.py | entr python3 run_tests.py
This command will re-run your tests whenever a Python file is modified.
Conclusion
These lesser-known Linux commands can help you streamline your daily DevOps tasks, whether it’s managing files, monitoring resources, or automating processes. By adding these tools to your toolkit, you can make your workflows more efficient and versatile.