Home Command line utilities Bash-Snippets – Useful BASH Scripts For Heavy Commandline Users

Bash-Snippets – Useful BASH Scripts For Heavy Commandline Users

By sk
Published: Last Updated on 25.4K views

Today I stumbled upon a collection of useful BASH scripts for heavy commandline users. These scripts, known as Bash-Snippets, are quite helpful for command line inhabitants. Want to check the weather of the place where you live? There is a script will do that for you. Wondering what is the Stock price? You can run the script that displays the current details of a stock. Feel bored? Watch some YouTube videos. All from commandline! You don't actually need any memory consuming GUI applications.

As of writing this, Bash-Snippets provides the following scripts:

  1. Cheat - Linux Commands cheat sheet.
  2. Cloudup - A tool to backup your GitHub repositories to bitbucket.
  3. Crypt - Encrypt and decrypt files.
  4. Cryptocurrency - Converts Cryptocurrency based on realtime exchange rates of the top 10 cryptos.
  5. Currency - Currency converter.
  6. Geo - Provides the details of wan, lan, router, dns, mac, and ip.
  7. Lyrics - Grab lyrics for a given song quickly from the command line.
  8. Meme - Command line meme creator.
  9. Movies - Search and display a movie details.
  10. Newton - Performs numerical calculations all the way up to symbolic math parsing.
  11. Qrify - Turns the given string into a qr code.
  12. Short - URL Shortner
  13. Siteciphers - Check which ciphers are enabled / disabled for a given https site.
  14. Stocks - Provides certain Stock details.
  15. Taste - Recommendation engine that provides three similar items like the supplied item (The items can be books, music, artists, movies, and games etc).
  16. Todo - Command line todo manager.
  17. Transfer - Quickly transfer files from the command line.
  18. Weather - Displays weather details of your place.
  19. Youtube-Viewer - Watch YouTube from Terminal.

The developer may add more scripts in future, so I recommend you to keep an eye on the project's website or GitHub page for future updates.

Install Bash-Snippets On Linux

You can install these scripts on any OS that supports BASH.

First, clone the GIT repository using command:

$ git clone https://github.com/alexanderepstein/Bash-Snippets

Go to the cloned directory:

$ cd Bash-Snippets/

Git checkout to the latest stable release:

$ git checkout v1.22.0

Finally, install the Bash-Snippets using command:

$ sudo ./install.sh

This will ask you which scripts to install. Just type Y and press ENTER key to install the respective script. If you don't want to install a particular script, type N and hit ENTER.

Do you wish to install currency [Y/n]: y

To install all scripts, run:

$ sudo ./install.sh all

To install a specific script, say currency, run:

$ sudo ./install.sh currency

You can also install it using Linuxbrew package manager.

To installs all tools, run:

$ brew install bash-snippets

To install specific tools:

$ brew install bash-snippets --without-all-tools --with-newton --with-weather

Also, there is a PPA for Debian-based systems such as Ubuntu, Linux Mint.

$ sudo add-apt-repository ppa:navanchauhan/bash-snippets
$ sudo apt update
$ sudo apt install bash-snippets

Bash-Snippets - A Collection Of Useful BASH Scripts For Heavy Commandline Users

An active Internet connection is required to use most of these Bash scripts. The usage is fairly simple. Let us see how to use some of them. I assume you have installed all scripts.

1. Currency - Currency Converter

This Bash script converts the currency based on realtime exchange rates. Enter the base currency code and the currency to exchange to, and the amount being exchanged one by one as shown below.

$ currency
What is the base currency: INR
What currency to exchange to: USD
What is the amount being exchanged: 10

=========================
| INR to USD
| Rate: 0.015495
| INR: 10
| USD: .154950
=========================

You can also pass all arguments in a single command as shown below.

$ currency INR USD 10

Refer the following screenshot.

Convert the currency based on realtime exchange rates using Bash-Snippets

Convert the currency based on realtime exchange rates

2. Stocks - Display stock price details

If you want to check a stock price details, mention the stock item as shown below.

$ stocks Intel

INTC stock info
=============================================
| Exchange Name: NASDAQ
| Latest Price: 34.2500
| Close (Previous Trading Day): 34.2500
| Price Change: 0.0000
| Price Change Percentage: 0.00%
| Last Updated: Jul 12, 4:00PM EDT
=============================================

The above output the Intel stock details.

3. Weather - Display Weather details

Let us check the Weather details by running the following command:

$ weather

Sample output:

Display weather details

Check the Weather details

As you see in the above screenshot, it provides the 3 day weather forecast. Without any arguments, it will display the weather details based on your IP address. You can also bring the weather details of a particular city or country like below.

$ weather Chennai

Also, you can view the moon phase by entering the following command:

$ weather moon

Sample output would be:

view the moon phase

View the moon phase

4. Crypt - Encrypt and Decrypt files

This script is a wrapper for openssl that allows you to encrypt and decrypt files quickly and easily.

To encrypt a file, use the following command:

$ crypt -e [original file] [encrypted file]

For example, the following command will encrypt a file called ostechnix.txt, and save it as encrypt_ostechnix.txt in the current working directory.

$ crypt -e ostechnix.txt encrypt_ostechnix.txt

Enter the password for the file twice.

Encrypting ostechnix.txt...
enter aes-256-cbc encryption password:
Verifying - enter aes-256-cbc encryption password:
Successfully encrypted

The above command will encrypt the given file using AES 256 level encryption. The password will not be saved in plain text. You can encrypt .pdf, .txt, .docx, .doc, .png, .jpeg type files.

To decrypt the file, use the following command:

$ crypt -d [encrypted file] [output file]

Example:

$ crypt -d encrypt_ostechnix.txt ostechnix.txt

Enter the password to decrypt.

Decrypting encrypt_ostechnix.txt...
enter aes-256-cbc decryption password:
Successfully decrypted

5. Movies - Find Movie details

Using this script, you can find a movie details.

The following command displays the details of a movie called "mother".

$ movies mother

==================================================
| Title: Mother
| Year: 2009
| Tomato: 95%
| Rated: R
| Genre: Crime, Drama, Mystery
| Director: Bong Joon Ho
| Actors: Hye-ja Kim, Bin Won, Goo Jin, Je-mun Yun
| Plot: A mother desperately searches for the killer who framed her son for a girl's horrific murder.
==================================================

6. Display similar items like the supplied item

To use this script, you need to get the API key here. No worries, it is completely FREE! Once the you got the API,  add the following line to your ~/.bash_profileexport TASTE_API_KEY="yourAPIKeyGoesHere"

Now, you can view the similar item like the supplied item as shown below:

$ taste -i Red Hot Chilli Peppers

7. Short - Shorten URLs

This script shortens the given URL.

$ short <URL>

8. Geo - Display the details of your network

This script helps you to find out the details of your network, such as wan, lan, router, dns, mac, and ip geolocation.

For example, to find out your LAN ip, run:

$ geo -l

Sample output from my system:

192.168.43.192

To find your WAN IP:

$ geo -w

For more details, just type 'geo' in the Terminal.

$ geo
Geo
Description: Provides quick access for wan, lan, router, dns, mac, and ip geolocation data
Usage: geo [flag]
 -w Returns WAN IP
 -l Returns LAN IP(s)
 -r Returns Router IP
 -d Returns DNS Nameserver
 -m Returns MAC address for interface. Ex. eth0
 -g Returns Current IP Geodata
Examples:
 geo -g
 geo -wlrdgm eth0
Custom Geo Output =>
[all] [query] [city] [region] [country] [zip] [isp]
Example: geo -a 8.8.8.8 -o city,zip,isp
 -o [options] Returns Specific Geodata
 -a [address] For specific ip in -s
 -v Returns Version
 -h Returns Help Screen
 -u Updates Bash-Snippets

Related read: 


9. Cheat - Display cheatsheets of Linux commands

Want to refer the cheatsheet of Linux command? Well, it is also possible. The following command will display the cheatsheet of curl command:

$ cheat curl

Just replace curl with the command of your choice to display its cheatsheet. This can be very useful for the quick reference to any command you want to use.


Recommended read:


10. Youtube-Viewer - Watch YouTube videos

Using this script, you can search or watch youtube videos right from the Terminal.

Let us watch some Ed Sheeran videos.

$ ytview Ed Sheeran

Choose the video you want to play from the list. The selected will play in your default media player.

Watch youtube videos from the Terminal

Watch youtube videos from the Terminal

To view recent videos by an artist, you can use:

$ ytview -c [channel name]

To search for videos, just enter:

$ ytview -s [videoToSearch]

or just,

$ ytview [videoToSearch]

Related read:


11. cloudup - Backup GitHub repositories to bitbucket

Have you hosted any project on GitHub? Great! You can backup the GitHub repositories to bitbucket, a web-based hosting service used for source code and development projects, at any time.

You can either backup all github repositories of the designated user at once with the -a option. Or run it with no flags and backup individual repositories.

To backup GitHub repository, run:

$ cloudup

You will be asked to enter your GitHub username, name of the repository to backup, and bitbucket username and password etc.

12. Qrify - Convert Strings into QR code

This script converts any given string of text into a QR code. This is useful for sending links or saving a string of commands to your phone

$ qrify convert this text into qr code

Sample output:

Qrify Converts Strings into QR code

Qrify Converts Strings into QR code

13. Cryptocurrency

It displays the top ten cryptocurrencies realtime exchange rates.

Type the following command and hit ENTER to run it:

$ cryptocurrency
Cryptocurrency script displays cryptocurrencies realtime exchange rates

Cryptocurrency script displays cryptocurrencies realtime exchange rates

14. Lyrics

This script grabs the lyrics for a given song quickly from the command line.

Say for example, I am going to fetch the lyrics of "who is it" song, a popular song sung by Michael Jackson.

$ lyrics -a michael jackson -s who is it
Grab lyrics for a song from command line

Get lyrics for a song from command line

15. Meme

This script allows you to create simple memes from command line. It is quite faster than GUI-based meme generators.

To create a meme, just type:

$ meme -f mymeme
Enter the name for the meme's background (Ex. buzz, doge, blb ): buzz
Enter the text for the first line: THIS IS A
Enter the text for the second line: MEME

This will create jpg file in your current working directory.

16. Newton

Tired of solving complex Maths problems? Here you go. The Newton script will perform numerical calculations all the way up to symbolic math parsing.

Perform numerical calculations using Newton script

Perform numerical calculations using Newton script

17. Siteciphers

This script helps you to check which ciphers are enabled / disabled for a given https site.

$ siteciphers google.com
Check which ciphers are enabled or disabled for a https site using siteciphers

Check which ciphers are enabled or disabled for a https site using siteciphers

18. Todo

It allows you to create everyday tasks directly from the Terminal.

Let us create some tasks.

$ todo -a The first task
01). The first task Tue Jun 26 14:51:30 IST 2018

To add another task, simply re-run the above command with the task name.

$ todo -a The second task
01). The first task Tue Jun 26 14:51:30 IST 2018
02). The second task Tue Jun 26 14:52:29 IST 2018

To view the list of tasks, run:

$ todo -g
01). The first task Tue Jun 26 14:51:30 IST 2018
02). A The second task Tue Jun 26 14:51:46 IST 2018

Once you completed a task, remove it from the list as shown below.

$ todo -r 2
Sucessfully removed task number 2
01). The first task Tue Jun 26 14:51:30 IST 2018

To clear all tasks, run:

$ todo -c
Tasks cleared.

19. Transfer

The transfer script allows you to quickly and easily transfer files and directories over Internet.

Let us upload a file.

$ transfer test.txt 
Uploading test.txt
################################################################################################################################################ 100.0%
Success!
Transfer Download Command: transfer -d desiredOutputDirectory ivmfj test.txt
Transfer File URL: https://transfer.sh/ivmfj/test.txt

The file will be uploaded to transfer.sh site. Transfer.sh allows you to upload files up to 10 GB in one go. All shared files automatically expire after 14 days. As you can see, anyone can download the file either by visiting the second URL via a web browser or using the transfer command (it is installed in his/her system, of course).

Now remove the file from your system.

$ rm -fr test.txt

Now, you can download the file from transfer.sh site at any time (within 14 days) like below.

$ transfer -d Downloads ivmfj test.txt

For more details about this utility, refer our following guide.

Getting help

If you don't know how to use a particular script, just type that script's name and press ENTER. You will see the usage details. The following example displays the help section of Qrify script.

$ qrify
Qrify
Usage: qrify [stringtoturnintoqrcode]
Description: Converts strings or urls into a qr code.
 -u Update Bash-Snippet Tools
 -m Enable multiline support (feature not working yet)
 -h Show the help
 -v Get the tool version
Examples:
 qrify this is a test string
 qrify -m two\\nlines
 qrify github.com # notice no http:// or https:// this will fail

Updating Bash-snippets

You can update the installed tools at any time suing -u option. The following command updates "weather" tool.

$ weather -u

Uninstall Bash-snippets

You can uninstall these tools as shown below.

If you have installed these tools using PPA, simply run the following command to remove them.

$ sudo apt remove bash-snippets
$ sudo add-apt-repository -r ppa:navanchauhan/bash-snippets

If you have used GIT method, follow the steps given below.

Git clone the repository:

$ git clone https://github.com/alexanderepstein/Bash-Snippets

Go to the Bash-Snippets directory:

$ cd Bash-Snippets

And uninstall the scripts by running the following command:

$ sudo ./uninstall.sh

Type y and hit ENTER to remove each script.

Do you wish to uninstall currency [Y/n]: y

Resource:

You May Also Like

12 comments

Nope July 14, 2017 - 3:28 am

Hi, thank you for the useful scripts, I’m currently using the ytview one. Just a little suggestion from me, it would be better if you could show the channel name & duration of the video too when searching for one, so the search result would look like this: [ChannelName] – [VideoTitle] – [VideoDuration]

Reply
SK July 14, 2017 - 12:12 pm

I’m afraid this feature is not available in ytview script. Please send a feature request to the developer in GItHub. https://github.com/alexanderepstein/Bash-Snippets.

Reply
seth December 22, 2018 - 3:56 am

These are awesome scripts! Thanks! I have no problem running them anywhere on my Ubuntu machine, (I wanna say I didn’t even have to edit my $PATH, just started typing the commands and they worked), but when I downloaded them onto my mac via my bash terminal, for example I can only get the commands to run if I go into that script’s directory in this case geo and use the ./geo command.

Reply
KC March 31, 2019 - 4:19 pm

Hi, great scripts, thanks.
Question though – how do you search for stocks or their symbols?
It’s easy for one word like Tesla or Intel, but how to search for example: Berkshire Hathaway?

Reply
Roland Latour July 11, 2019 - 9:25 pm

Everybody needs a timer, uses yad which replaces zenity:
http://user.cavenet.com/rolandl/yad-timer.txt

Reply
Jamil Soni Neto July 11, 2019 - 9:45 pm

That’s is a very good collection of little programmes!
However, I think the approach for getting bank currency rates is awkward: you must answer 3 questions and gets a bloated result.
I suggest a more UNIXy approach to get bank currency rates with the same excellent API these guys are using…

So I implemented a more ( what I expect to be) straightforward syntax with this Bash script. You can download it from the link below and test it. Run with “-h” to get a help page and get started. But syntax would be “erates.sh 1 USD JPY” to get the equivalent of one-US-Dollar in Japanese Yen.

https://drive.google.com/file/d/1ILpktTAQUw8DyeF52XvqsWAo5-ciVtVU/view?usp=sharing

Cheers!

Reply
sk July 12, 2019 - 11:46 am

Nice! Put it on GitHub and make it available for everyone.

Reply
Jamil SN July 11, 2019 - 9:50 pm

I was looking in the source code and there is a nice function there..
It is easier if I just paste the comment from it (line 106):

## This function queries google to determine the stock ticker for a certain company
## this allows the usage of stocks to be extended where now you can enter stocks appple
## and it will determine the stock symbol for apple is AAPL and move on from there

So what you ask for should be working by default (even though this specific bash script does not work in my computer at all!)

Reply
Jamil SN July 13, 2019 - 9:47 pm

@sk, thanks for the positive feedback.
I went ahead and created my first github repo with that Bash Currency Converter utility I made and some others …
https://github.com/mountaineerbr/markets

Reply
sk July 14, 2019 - 9:18 pm

Good to know. I will look into it. Regards.

Reply
DProg September 10, 2022 - 10:13 pm

Workaround to installing these local versus as a system tool?

Reply
four-zero-four-seven-six December 15, 2022 - 1:21 am

go to the GitHub links in a web browser and download the repo
then store it somewhere safe and create an alias for it
<>

Reply

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