sperea.es
Published on

Boosting Linux shell productivity: my hacks, tools and tips

Authors

In this article, I'll share some hacks or tricks that allow me to use the Linux shell more productively. These tips and techniques make interacting with the command line easier and help streamline everyday tasks in a Linux environment.

Whether it's speeding up command execution, improving file management, or leveraging useful tools, these hacks will help you get the most out of your shell and work more efficiently on your Linux system. Keep reading to discover how to boost your productivity in the world of the terminal!

Correct Errors When Writing Terminal Commands with TheFuck

The application "thefuck" is a fantastic tool for Linux command-line users that corrects errors in previous commands. This application attempts to fix user errors on the command line by composing new commands using a set of matching rules.

For example, if you try to install a package without superuser permissions and receive an error, you can simply type "fuck" in the command line, and the application will suggest the correct command with "sudo."

Moreover, TheFuck is compatible with various shells like bash, fish, tcsh, and zsh. To use it, you need to set up the alias "fuck" for the "thefuck" tool.

Keep in mind that you need to have Python version 2.7+ or 3.3+ along with pip and python-dev for installation.

Example of usage:

$ aptget install vim
E: Invalid operation install
$ fuck
sudo apt-get install vim
[sudo] password for user:
Reading package lists... Done

Record Your Terminal Session with "script"

The "script" command in Linux is used to create a transcription file or record all activities in the terminal. After executing the "script" command, it starts recording everything displayed on the screen, including inputs and outputs, until you run the "exit" command.

By default, all terminal information is saved in the "typescript" file if no arguments are provided. The "script" command is very useful when you want to capture the output of a command or a set of commands while installing a program or recording the terminal logs while compiling open-source code, etc.

Here's an example of how to use the "script" command:

$ script my_terminal_session
Script started, file is my_terminal_session
$ ls
Desktop  Documents  Downloads  Music  Pictures  Public  Templates  Videos
$ exit
exit
Script done, file is my_terminal_session

In this example, the user initiates a new script session with the "script my_terminal_session" command. Then, the user runs the "ls" command, which lists directories in the current directory. Finally, the user ends the script session with the "exit" command. All of this is recorded in the "my_terminal_session" file.

It's important to note that the "script" command uses two files: one for terminal output and another for timing information.

The "scriptreplay" command in Linux is used to replay a previously recorded terminal session created with the "script" command. This command doesn't re-execute the commands but displays the same information again. Therefore, "scriptreplay" must be run in the same type of terminal where the transcription was recorded to work correctly.

To use "scriptreplay," you need to provide two files: a timing file and a transcription file. The timing file contains information about how long each command took to execute, while the transcription file contains the executed commands and their output.

Here's an example of how to use the "scriptreplay" command:

scriptreplay --timing=time.tm myscript

In this example, "time.tm" is the timing file, and "myscript" is the transcription file. Running this command will replay the recorded terminal session.

Additionally, you can use the "-d" or "--divisor" option to speed up or slow down playback. For example, to play the session at double speed, you can use a divisor of 2. To play the session at half speed, you can use a divisor of 0.5.

"dict": A Command-Line Dictionary Tool

The "dict" command-line dictionary tool is used to look up definitions of words, synonyms, antonyms, and other linguistic data from online dictionaries.

To use "dict," simply enter the "dict" command followed by the word or phrase you want to look up. For example, to search for the definition of the word "cat," you would enter the following:

dict gato

This will return the following output:

gato

(sustantivo)

1. Mam铆fero felino dom茅stico, generalmente de pelo largo y cola larga.
2. Persona que es t铆mida o cobarde.

(verbo)

1. Golpear o dar un golpe con la mano abierta.
2. Aplastar o golpear algo con fuerza.

You can also use "dict" to search for synonyms and antonyms by using the "-s" and "-a" modifiers, respectively. For example, to search for synonyms of the word "cat," you would enter:

dict -s gato

This will return the following output:

gato:

* perro
* lobo
* tigre
* le贸n
* puma
* jaguar

In addition to looking up definitions, synonyms, and antonyms, "dict" can also be used to find other linguistic data. You can use the "-p" modifier to search for pronunciation, the "-t" modifier to find the part of speech, and the "-e" modifier to search for etymology.

For pronunciation:

dict -p gato

gato:

/藞伞忙.to蕣/

For part of speech:

dict -t gato

gato:

sustantivo

For etymology:

dict -e gato

gato:

Del lat铆n cattus.

Para obtener m谩s informaci贸n sobre el uso de dict, consulte la p谩gina de ayuda de dict.

Aqu铆 hay algunos ejemplos de c贸mo utilizar dict:

    Buscar la definici贸n de una palabra:

dict gato

    Buscar sin贸nimos de una palabra:

dict -s gato

    Buscar ant贸nimos de una palabra:

dict -a gato

    Buscar la pronunciaci贸n de una palabra:

dict -p gato

    Buscar la parte de la oraci贸n de una palabra:

dict -t gato

    Buscar la etimolog铆a de una palabra:

dict -e gato

This will provide the relevant information for each search.

To get more information on using "dict," refer to the "dict" help page.

Carbonyl: A Graphic Browser Integrated into Your Terminal

Carbonyl is a web browser based on Chromium that runs in a terminal. It is written in Rust and is available for Linux, macOS, and Windows.

Carbonyl has a simple and minimalist user interface and is controlled using both the keyboard and mouse.

Carbonyl supports most of the functions of a traditional web browser, but what makes it truly interesting is its full integration into the terminal. It's incredible how it embeds a web page within the terminal, allowing you to access the web quickly without leaving your terminal session.

The easiest way to install and invoke it is through Docker, like this:

docker run --rm -ti fathyb/carbonyl https://elmundo.com

You can also install it via npm:

npm install --global carbonyl

Here's a video demonstrating its functionality:

Take Your Clipboard to the Next Level with "Clipboard"

The Clipboard Project is a fast, lightweight, feature-rich clipboard manager that is user-friendly and enables you to perform more tasks on your computer with style. Seriously.

Welcome one of the most innovative clipboard managers you've ever seen. Save time and effort in a simpler and more powerful way than ever before.

  • Copy and paste text, files, directories, binary data, your goat, anything.
  • Infinite clipboards with unlimited capacity and history in each.
  • Impressive performance 馃ゾ馃く because slow software is tiresome.
  • Seamless integration with your existing clipboard systems.
  • Multi-language support.
  • Highly customizable API for easily automating your workflows.
  • Visual and auditory effects for your visual and auditory delight.

Here's a video demonstrating its functionality:

CB Demo Video

Improve Command History with Hishtory

Hishtory is an enhanced version of the command history. It saves your terminal history in context (where you executed the command, whether it was successful, how long it took, etc.). All of this is stored locally and encrypted end-to-end to synchronize with all your other computers. Everything is easily accessible through the Hishtory CLI. This means that from your laptop, you can easily find that complex bash process you wrote on your server and see the context in which you executed it.

To install it:

curl https://hishtory.dev/install.py | python3 -

Here's a video that demonstrates its functionality:

demo

Some features:

  • Querying: You can interact with hiSHtory in two ways:
    • By pressing Control+R in your terminal to search for a command and have it ready to execute.
    • By using "hishtory query" if you only want to explore your command history.

Both options support the same query format, allowing you to search for specific commands, commands executed by a specific user, commands executed on specific dates, and more.

  • Enable/Disable: You can temporarily enable or disable hiSHtory recording using the "hishtory disable" and "hishtory enable" commands, respectively.

  • Deletion: Use "hishtory redact" to delete entries from your history that you didn't want to record. You can also delete items directly from the terminal interface using Control+R.

  • Updating: To update hiSHtory to the latest version, simply run "hishtory update."

  • Advanced Features: Additional features include customizing displayed columns, importing existing histories, customizing the installation directory, viewing debug logs, uninstallation, and more.

Conclusion

In conclusion, these tips and tricks to enhance productivity on the Linux command line have the potential to be valuable tools for simplifying daily tasks and optimizing system usage. From correcting command errors with "TheFuck" to efficiently managing command history with "Hishtory," these hacks are designed to make working in a Linux environment more effective and seamless.

By harnessing these techniques, you can save time, avoid frustrations, and perform tasks more quickly and accurately. The key is to explore and tailor these tricks to your specific needs, allowing you to maximize your productivity and unlock the full potential of the Linux command line. We hope that these tips prove to be useful in your projects and daily activities on Linux!