Home Command line utilities Bookmark The Linux Commands For Easier Repeated Invocation

Bookmark The Linux Commands For Easier Repeated Invocation

By sk
Published: Updated: 1.9K views

A while ago, we have written about a command line utility named "Keep", which is used to save the Linux commands in Terminal and use them on demand. It is quite useful when it comes to use lengthy Linux commands often. We don't have to memorize the commands. Just save it using "Keep" utility and use that command on demand. Today, I have stumbled upon yet another similar utility called "Bashpast". It is used to bookmark the Linux commands for easier repeated invocation. This provides an easy way to repeat frequently used commands and saves you a few keystrokes. Also, if you have hard time remembering lengthy commands, you can use it to bookmark them. Of course, you can simply do a reverse search using 'CTRL-R' to lookup the commands or use aliases, but this utility provides way faster and easier method.

Install Bashpast

Git clone the Bashpast GitHub repository using command:

$ git clone https://github.com/ivanmisic/bashpast.git

The above command will clone the contents of Bashpast repository in your current working directory.

Go to bashpast directory:

$ cd bashpast/

And, run the following command to install it.

$ make

Edit your ~/.bashrc file:

$ vi ~/.bashrc

Add the following line:

source ~/.local/bin/bashpast.sh

Finally, update your .bashrc file with the command:

$ source ~/.bashrc

Bashpast has been installed now. Next, we will see how to use it to bookmark the Linux commands.

Bookmark The Linux Commands Using Bashpast

Let us say you want to find and copy all files that ends with extension .mp4 and save them in a directory called Downloads. To do so, we use the following command:

$ find -iname '*.mp4' -exec cp {} /home/sk/Downloads/ \;

As you can see, this command is longer, and difficult to keep it in memory all the time. In such cases, Bashpast will make your life easier. You can simply bookmark the above commands and use them on demand.

Please keep in mind that you need to run the command before bookmarking it.

Now, let us bookmark it using command:

$ bp s find

The 'find' command has been bookmarked. To execute this command, run:

$ bp e find

Let us bookmark another command. First, run the actual command:

$ ls -l

Bookmark the above command:

$ bp s ls

To execute the bookmarked command, do:

$ bp e ls
total 8668
drwxrwxr-x 3 sk sk 4096 Jul 22 14:09 bashpast
-rw-r--r-- 1 sk sk 5123 Jul 11 18:24 client.ovpn
drwxrwxr-x 14 sk sk 4096 Jul 20 17:39 ostechnix
-rw-rw-r-- 1 sk sk 8858480 Jul 20 16:59 sk

See? It executes the bookmarked command and displays its result.

To list all bookmarks, run:

$ bp l

Sample output:

ls                   ls -l
find                 find -iname '*.mp4' -exec cp
Bookmark The Linux Commands Using Bashpast

Bookmark The Linux Commands For Easier Repeated Invocation

As you can see in the above outputs, Bashpast bookmarks the given commands and executes them without having to type the actual command. If you want to bookmark the same command multiple times, just name it with different name, such as find1, find2, find3 and so on.

Suggested Read:


You May Also Like

1 comment

IJK July 25, 2017 - 8:26 pm

It is essentially a different approach to doing what can already be done with the command history and the search utilities in the command line.


Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

This website uses cookies to improve your experience. By using this site, we will assume that you're OK with it. Accept Read More