Normally , we write sudo apt-get install command in terminal , if we have to install something. This is normal and regular used command for any of the Ubuntu user but sometimes it's a bit irritating to type full command even if we have to install  a small application.But, We can create custom command to remove this problem.

Let's see how....

Open your terminal and type:

alias (custom command)='original command'

alias install='sudo apt-get install'

So, now if  I have to install anything, I will just type:

install vlc


This won't be there permanently. If you want this to happen everytime, you have to add this in the ~/.bashrc file.


If you open your terminal, you will something like this..


Where,
praveen : User Name
ubuntu   : Hostname

These values are in the default color mode. What if , you want to change the color of it...

Let's see how...

Type this in terminal..

gedit ~/.bashrc

This will open a file.

Look for #force_color_prompt=yes and remove #.(In short uncomment it)


Save the file and open your terminal again.


We can further change the color, look for if [ "$color_prompt" = yes ]; and go to then part:

   PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '

The italic part in the above statement decides the color, So if you want to change it, you can do something like this:

PS1='${debian_chroot:+($debian_chroot)}\[\033[01;35m\]\u\[\033[01;30m\]@\[\033[01;32m\]\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '

So, output will be something like this:


Color Code:

Black          0;30     Dark Gray     1;30
Blue            0;34     Light Blue      1;34
Green         0;32     Light Green    1;32
Cyan           0;36     Light Cyan     1;36
Red             0;31     Light Red       1;31
Purple         0;35     Light Purple  1;35
Brown         0;33     Yellow           1;33
Light Gray  0;37     White             1;37
You can't just write the drive name (like c:) on the terminal and move to another drive. This is because the file structure in Linux is different from Windows.The simplest way to change the drive in Linux, is to mount the drive first.

Let's see an example to make it more clear....

First, mount the drive. You can easily mount any drive just by opening it.

When you open any drive, it automatically gets mounted on media.So, if you want to go to any other drive, you have to go through media.

Let's see how many drives are mounted in my system.

Open your terminal and execute this command:



As, you can see in the above screenshot, two drives are mounted. So, We can easily move any of these drive:


I have created this simple Perl Script to manage all my files. It will take specific files or folders and move it to a particular folder. The files can be anything like pdf, avi or xls etc files...

You just have to provider two paths:

1) One, where all your source files are present
2) Second, where you want to move all your files

Please find the Perl Script here....


You can change the type of files, you want to move just by changing the matching pattern( like avi in place pdf ).

HOW TO RUN ?

Just open your terminal.

Make your Perl Script executable.

chmod a+x (Perl Script Name)

Now, Run it...

./(Script Name) (Source Folder) (Destination Folder)


See.....



You may be using an editor for javascript, css coding. But why to install a bulky software when you have mozilla browser in your system. You can just install an add-on and you are ready to go...

HOW TO INSTALL?

You can install it from here and can add to firefox.



If Add the firefox button is grayed as shown above, then just find the other versions of firebug compatible to your browser.

Once this is done, just press the F12 key...



For more detail, please visit here : Firebug in detail
Pdfgrep package provides the functionality to search PDF file from command line.

First, you need to install this package:

Open your terminal and type:

sudo apt-get install pdfgrep


Now, suppose you have a pdf file in your home folder and you want to search a text in that. In my case, I have a pdf file jQuery.pdf in my home folder and I want to search a text jquery in that...

pdfgrep jquery jQuery.pdf


For more info about pdfgroup, just type this in terminal:

pdfgrep --help


Yes, you don't read any pdf reader to read pdf files in your system. You can read all pdf files in your favorite terminal.

First of all, you have to download a package.

Open your terminal and type:

sudo apt-get install zathura


Once this is done, you are all set to read your files.

Type this in your terminal:

zathura (pdf file path/pdf name)

But, if your pdf is in the home folder then you just have to do this:






This is just awesome !!

Just download one package from terminal.

wkhtmltopdf:

Simple shell utility to convert html to pdf using the webkit rendering engine, and qt.

Features:

Convert web pages into PDF documents using webkit
Adding headers and footers (static version only)
TOC generation (static version only)
Batch mode conversions
(Linux) No longer requires an XServer to be running (however the X11 client libs must be installed)

How to Install ?

Open your terminal and type:

sudo apt-get install wkhtmltopdf


Once this is done, execute this :

wkhtmltopdf 


You will find your pdf in home folder :



There is a simple way to determine the length of the array in Perl:

First just declare an array with some elements:


You just have to add scalar in front of array.



Evaluating the array in the scalar context, returns the number of elements in the array.

One more powerful of thing of Perl !!

In this script, we will take input values from the standard input and convert all values to uppercase and lowercase letters.


Converting input values to uppercase :


See the power of :\U

Your output will be like this :


Converting input values to lowercase letters:

Now, See the power of :\L

Output:



First of all, you should have an input file to read. We will pass the name of this file on the command line, so no hard-coded value here !!

My input file is in the home folder. In fact, we can read number of files at the same time. It works like this, first it reads the input of first file then the second and so on...

It keeps appending the lines to the output...

This example will make this more clear....

Let's first read our file using cat utility:


Now, Perl.......

Open your terminal and execute :


This is an interesting way to find out the temperature of your city using terminal without any hassle !!

So, first of all go to this site and type your city name : Accu Weather


Now, copy the URL, it is something like this in my case:

http://www.accuweather.com/en/in/pune/204848/weather-forecast/204848

Now, just put your URL in place of mine, in the below mentioned script:


Find script code here : Weather Script Code

Now, just execute this script using terminal...

Open your terminal.

Type : chmod a+x Weather.sh

Next, ./Weather.sh


Grep is a powerful tool to filter out the elements according to our requirement.
We can use it in Perl too....

So, How to use it ?

It will much more clear if I take an example :

So, Let's take this code:

As you can see, it is a useful pattern. Just follow the syntax of using grep.

Map is also a useful tool by which we can transform the data at place. Let's see how:

 Same syntax as we have used in grep. Now, what it says, take the elements from the array collection, adds 10 to each number and put it in an array.

Simple !!
To match a specific word at the extreme last, we put a suffix $ at the end of word.Like in the below mentioned code:

Here, we are matching fred word at the extreme end of the line.So, we know the output :


But , what if our input is like this, where fred is at the extreme end but somewhere in the middle lines, not in the last line.


Now, the output will be like this:


To make it work , you have to include /m.....

Output:


We can do a lot of pattern matching in Perl by using match operator : / /

Let me show you by an example..

#!/usr/bin/perl

print "Do you want to read something?Y:N -->";
chomp($_=);
if(/Y/)
    {
        print "Good going.Keep it up !!";
    }


Output:


Nothing happens here ! It's only because we have applied y in place of Y.It makes our program a case sensitive one.

To handle this , we will use : / / i


#!/usr/bin/perl

print "Do you want to read something?Y:N -->";
chomp($_=);
if(/Y/i)
    {
        print "Good going.Keep it up !!";
    }
Output:



So, just by including a letter (i) , we can get what we want.

Power of Perl !!
I want to share a very interesting thing , I just came across with. We all know the importance of Array and in perl also , we make our coding easier by using this entity but Perl, also has a very unique way of handling the length of way..

Let me demonstrate you by an example...

First , we will insert some elements in array here:

!# /usr/bin/perl

@array = qw(21 22 23 24 25 26);
print "This is our array:@array";

Now, there is an interesting thing: $#

This thing return the index of the last number in array.

Let's use it...

print $#array;

Output: This will return 5.

If you want to reduce the size of the array then you can do something like this:

$#array=4;

This will set the last index as 4.

So, now if you print the array , you will get an output like this :

Output: 21 22 23 24 25






All the variables in perl have the special value before any value gets assigned to it. Means, when you use a variable before initializing or assigning any value to it,

it automatically gets a value : undef

If you try to use this “nothing” as a “numeric something.it acts like zero. If you try to use it as a “string something,” it acts like the empty string. But undef is neither a number nor a string; it’s an entirely separate kind of scalar value.

undef as a number:



#!/usr/bin/perl

$n=2;
$sum=$sum+2;
print "The sum is:$sum";

Here, $sum is not initialized with any value but it is having number 0 as undef value.


undef as a string:

#!/usr/bin/perl

$string= $string."adding to string";
print $string;

Here, $string is not initialized anywhere but because we are doing string concatenation here, $string will be having null string ' ' as undef value.



How To Check Undef Value?



We can check whether the value is undef or not using defined function.

It returns true if the value is not undef and ,

It returns false for undef value

Ex:

for undefined value:

if (defined($a))
    {
        print "The value is defined";
    }
else
    {
        print "The value is undefined";
    }

Output: The value is undefined



 for defined value:

$a='';
if (defined($a))
    {
        print "The value is defined";
    }
else
    {
        print "The value is undefined";
    }

Output: The value is defined
First of all, Go to Dash and type privacy.

Click on the privacy icon and you will get a window like below mentioned screenshot:

As you can see in the above mentioned screenshot, you can prevent either the files or the folders from being recorded.

If you want to prevent files from being recorded the just check the boxes.

And, if you want to select folders the just browse for the particular folder using the '+' button at the left bottom of the window:


Enjoy your secret files...



There is a simple way to maximize the Dash but let's learn a new way using terminal to maximize this awesome utility.

Let's use gsettings...

Open your terminal.

gsettings


We have to set the com.canonical.unity schema value here...
Let's first see whether this schema is installed in our system or not...

gsettings list-schemas| grep com.canonical.unity


Now, Open your terminal.

Half - Screen Dash :

Execute below mentioned command in terminal:

gsettings set com.canonical.Unity form-factor 'Desktop'


* When you set something using gsettings , it needs a key-value pair.
Key = form-factor
Value =Desktop

Full - Screen Dash:

gsettings set com.canonical.Unity form-factor 'Netbook'


Done !!!

What is MongoDB ?

MongoDB (from "humongous") is an open-source document database, and the leading NoSQL database. Written in C++, MongoDB features:

Document-Oriented Storage »
    JSON-style documents with dynamic schemas offer simplicity and power.

Full Index Support »
    Index on any attribute, just like you're used to.

Replication & High Availability »
    Mirror across LANs and WANs for scale and peace of mind.

Auto-Sharding »
    Scale horizontally without compromising functionality.

Querying »
    Rich, document-based queries.

Fast In-Place Updates »
    Atomic modifiers for contention-free performance.

Map/Reduce »
    Flexible aggregation and data processing.

GridFS »
    Store files of any size without complicating your stack.

Professional Support by MongoDB »
    Enterprise class support, training, and consulting available.

HOW TO INSTALL ?

Open your terminal and execute below mentioned command:

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10

This will import the MongoDB public GPG key.


Create a /etc/apt/sources.list.d/mongodb.list file using the following command.

echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' | sudo tee /etc/apt/sources.list.d/mongodb.list


Now, update your repository.

sudo apt-get update

Now, install MongoDB package:

sudo apt-get install mongodb-10gen

This will take sometime because of package size that will be around 221mb.
© 2015 Techie's House. Designed by Bloggertheme9