Monday, 14 December 2015

Creating a Restaurant Menu using Shell script

I love to visit restaurant and on their counter you will see a machine, having list of all the items with their price tags. With the help of that machine, they generate your bills. You can create a same using the shell script.

Here is the code:

out=$(dialog --stdout --menu 'CodingTheRightWay Menu' 999 999 999 Chocolate \$5 IceCream \$10)
echo "You ordered chocolate $out"

Save the code, and make it executable.

Once you run the code, then it will look like this:

You can use your keyboard arrows to choose the item, and for placing order. Cool!

Now, it's your time to create something interesting out of it.


Wednesday, 18 November 2015

One Liner to delete all the files with names present in the txt file using xargs bash

There is simple one liner, that will delete all the files, you listed in a text file containing their names.

For Ex:

Create a file with name "filenames" contains the list of all the files  that you want to delete, then execute below command on the terminal.

xargs -a filenames -d'\n' rm

xargs -  to build and execute command lines from
-a - to use for providing input from text file instead of stdin
filenames - the file you just created
-d - delimiter
rm - command to pass the list

You can also use "-i" with rm for interactive mode.


Wednesday, 7 October 2015

How to change the default display output limit of terminal ubuntu linux

By default, in ubuntu, when you type your command, or try to open your log/messages file, the output goes beyond the display, and it trims out. Below are the methods, that can help you to see more output on the terminal:
1. Go to Edit->Profiles->Edit->Scrolling, and select the option unlimited.

2. $ cat /home/abcd/Downloads/fileName.txt | more , with the usage of more command.
3. You can save your complete session, by using script command.
script — make typescript of terminal session
$ script /tmp/command.out
Script started, file is /tmp/command.out
$ the_command
$ exit
Script done, file is /tmp/command.out
$ less /tmp/command.out

Saturday, 12 September 2015

How to check your NIC (network interface card) mode

Occassionally you'll want to verify that your gigabit network is actually running in gigabit mode.  Or, to futureproof this little post, maybe we're talking about kajigabits.

Anyway, normally there are little mode LEDs on your network hardware that indicate what speed it's operating at.  However, if you aren't in a position to physically see these little lights on the back of your network card or router, or you are but you're too lazy to get off your cushy chair and go look, here are a couple of quick and totally unintuitive ways of examining things using nothing but your trusty shell.

Use mii-tool (as root):
$ mii-tool -v eth0
Look at the 'negotiated' value.  It'll indicate what speed the interface is using.  'FD' means 'Full Duplex'.  'HD' means 'Half Duplex'.  For example, '100baseTx-FD' means 100mbit Full Duplex.

Use tcpdump (as root):
$ tcpdump -v -i eth0 -c 1
Look at what it says for 'link-type', although I'm not convinced this is an accurate method for speed reporting.  But tcpdump is awesome for other stuff, and maybe I just don't know how to interpret what it's saying.

Use dmesg:
$ dmesg | grep eth0
Look for a line similar to one of the following:
eth0: link up, 100Mbps, full-duplex
e1000e: eth0 NIC Link is Up 100 Mbps Full Duplex
It may be that your dmesg buffer doesn't go back far enough to include that.  If so, try one of the other methods.  Or I guess you could cycle the interface down/up, and then peak at dmesg again.

Use ethtool:
$ ethtool eth0
Look for the 'Speed:' value.  Lots of other good info is listed as well.  This technique  is the one that produces the most self-explanatory output, but it probably also the least likely to already be available on your system.


Sunday, 6 September 2015

Sunday One Liner

Today's one liner is to display the watch. Thanks to AltoidNerd.

In this one liner, we have used the following programs:

watch: The watch will execute the program periodically and display the result on complete screen.

figlet: the figlet provides different style and size of font

 TOIlet - display large colourful characters (heard this command today itself) :))
 watch -tcpn.5 'figlet -f big -W "$(echo "coding\n-\nscripting")" |  toilet -f term --metal'

Tuesday, 1 September 2015

Secure your passwords by storing them in Keepass

KeePass is a wonderful for linux environment, as we have 1Password by Agile bits for Mac, Windows, Android, and as browser addon. Unfortunately, it is not available for the linux platform. Here comes KeePass as a solution for linux users. To use the accounts in firefox, you have to install keefox, and export the password file. KeePass will you give an amazing performance and experience on linux platform.

Most of it,

KeePass is really free, and more than that: it is open source (OSI certified). You can have a look at its full source and check whether the encryption algorithms are implemented correctly.

You can install KeePass directly on windows, by downloading it from their website.

The version available for ubuntu is older, so you need to add a new repo for the latest version.
Here is the process:

sudo apt-add-repository ppa:jtaylor/keepass
sudo apt-get update
sudo apt-get install keepass2 
By adding above repository you can install the latest version of keepass2.

That's all folks for tonight. :)

Monday, 31 August 2015

Sed Tetris by uuner

This script is the best of example to prove the power of bash and sed. :-)

A game of tetris written using sed and bash by uuner for your shell.

The game has all the features of rotating blocks, increasing blocking speed and all.

So, shell scripts are not limited to automate your tasks, you can even create game using your shell scripts. There are many games available using the shell script, like snakes, tanks, and many more.

The code for sed tetris is available on the page:

Thank you.

Saturday, 29 August 2015

Auto update upgrade your Atom editor Package

So, atom is one of my favorite text editor these days, and it has great community. You can download and read it more about the atom here:

Unfortunately, it is difficult to update the atom, as it is not available in ubuntu software center, and there is no update option available for the atom yet.

So, i have found a script over and it's very useful. You can use it for downloading, updating, and upgrading your atom package. You can add the same in your cron job.

Here is the code, save it as
and make it executable.

Save it and run it. And feel the power of new upgraded atom.

Thank you.

One liner to remove duplicate entries using awk

Hello Everyone,

Today we will discuss about one liner for removing
Sometime, we have a situation where we have the file with lots of repetitive or duplicate entries. You need to remove all those entries or count the number of those repetitive elements.

Let's suppose we have a file with below content,



Now, to remove the duplicate entries, use the below awk one liner:

$ awk '!a[$0]++' my_temp_file

Now, if you don't bother about the order, you can use sort and uniq in below manner:

$ cat one-liners/my_temp_file | sort | uniq

It will do the same, but don't preserve the order of file.

You can watch the YouTube video here:

Thank you

Add your comments for doubts.