Why Worry?

In today’s world, most of people don’t put attention on how we can solve a particular problem rather they just panick and start worrying.
Here I am having a simple flowchart showing that problems will come but its upon us that how we handle and solve them.

image

There is a quote that ” Bhatti mei milkar sone ka rang nikhrta hai” …
So all those problems which came in our way is a method for testing our patience,  the way we tackle with it. 
  Be positive , Stay calm 🙂

Journey to Vaishnodevi

Jai mata di.. 🙂
Just reached today at home after a beautiful journey to Vaishnodevi. It was the first time i visited there. I am here sharing my experience 🙂
I went there with my family via train.
The first thing I noticed after reaching there is the new katra railway station. It was beautifully constructed. Well showing that things in India can become better and better but the condition is that we the citizens of India need to be environment friendly and concerned about it.
Then we started our journey from Balganga. We completed the whole going and coming back scenario by foot. Well it was an amazing feeling but still I recommend that you should start the journey by sitting on horses or any other way you want which is available there. Afterwards while coming back you can prefer to come by your own. Other wise its possible that cramps will disturb you for some days as I am facing this problem now :/ ,But it depends from person to person. We had walked 28 km over there but I think its more than that.
But the pleasant feeling which you feel after your efforts is priceless :’)
The weather was awesome there at night and the valley, views<3 and the Bhawan was beautifully decorated ❤ with flowers and other things.  We reached there in the morning around 01.00 am but crowd was there in lacks. No. of speakers were there through out the journey playing Bhajans and a source of motivation, people were dancing( we can say bhagvan mei leen 🙂 )
One thing is that nothing is allowed in the bhawan not even mobile phones, thats why couldn’t capture those moments 😦
But may be it was for safety purposes. But apart from all this,
I can’t explain that pure feeling which I got in the bhawan in words. Its beyond perfection ^_^
Feeling blessed 🙂

Presentation Session..

Yesterday I gave presentations on Topics: Sed command, Find command and Domain name system (DNS)

Its truly said that practice makes man perfect. Well its true in case of women also :p

Firstly only the idea of facing others makes me nervous, But now a confidence is build into me which is getting stronger day by day.

Apart from this I got to know about Helix bridge, ls command in linux and Story of Aaron Swarts.

I learnt from my experience that I should be 110% :p prepared, I should be able to transfer my knowledge among others. I will try to know about the meaning of each and every term I am using in my project from now.

I will be giving short glimpses of the topics and will answer all the queries of GD members.

I. “POWER OF FIND”

Type find . for current directory ( Here . is the current directory ) Apart from this,

.. is the folder above the current folder – the folder that contains the current folder.

Q. What is the Importance of terminal over GUI?

Though both excel in different matters. But there are somethings which can easily be accomplished using command prompt.

1.Scripts are a powerful thing. You can use conditions if and loops for etc.. and do all sorts of things.There is no limit to the power of scripting. This makes complex tasks easy to some extend.For such things, it is often hard to find a GUI app that matches your requirement.

  1. It is simply faster. It is much quicker to type a few alphabets and press TAB than to click though endless menu options.It takes less time and easy to type.

  2. We can access multiple files using terminal in less time.

  3. we can use experimental server so easily using terminal ( Talking about my case here :p )

Q. What to prefer to play music, GUI or terminal?

The easier way is GUI. But it is possible using terminal also. Wait for my next blog to see its procedure 😉

Q. Difference between find ./test  and find test? “OR”  What is the benefit of ./ in case of (find ./test)?

Both will search for test directory.

But, Prepending the command with ./ effectively says “forget about the PATH, I want you to look only in the current directory.”

Q. Difference between -name and -iname?  “OR” What is significance of using -iname (i.e find ./text  -iname  “*.php” )?

name is case sensitive but iname is case insensitive. This is the basic difference and ‘i’ mainly stands for ignore.

Q. What is the significance of ls -s?

ls stands for list and s here is size. So basically, it displays the size of files.

II. DNS

Q.DNS vs File system

In DNS (DOMAIN NAME SYTEM), Information related to mapping is distributed in parts on various computers(servers). But in file system this information is shared and is kept in a single computer system whose access is given to all other  which give request for mapping.

Q.Is google.com. and google.com same?

Yes google.com and google.com. are same. Both direct you to the page of google. But difference is only in notation i.e google.com is FQDN (fully qualified domain name) and google.com. is PQDN(partially qualified domain name) in which we can terminate the end null string.

Q.How many number of  DNS servers present under root?

There can be atmost 128 levels possible under root.

Q.Where is ISP present?

ISP(Internet service providers) is present from where we are getting internet. eg: If I am having a Airtel connection, then my current ISP is my  current Internet Service Provider(AIRTEL)

Q.What is the use of Port?

port is an endpoint of communication in an opearating system. A port is identified for each address and protocol by a 16-bit number, commonly known as the port number.

Q.How is our Internet managed?

Internet Ecosystem is the term used to describe the organizations and communities that help the Internet work and evolve.  These organizations share common values for the open development of the Internet.

Technologists, engineers, architects, creatives, organizations such as theInternet Engineering Task Force (IETF) and the World Wide Web Consortium(W3C) who help coordinate and implement open standards.

Global and local Organizations that manage resources for global addressing capabilities such as the Internet Corporation for Assigned Names and Numbers(ICANN), including its operation of the Internet Assigned Numbers Authority(IANA) function and Registrars.

Operators, engineers, and vendors that provide network infrastructure services such as Domain Name Service (DNS) providers, network operators, and Internet Exchange Points (IXPs)

Q.What if the server is present in India. Do the user still need to go to USA?

NO, if server is in India we don’t need to consult USA. We will type for anything it will be directed to closest server but verification is needed by USA servers as they are having billions of info nad we are having millions of. This is because of time gap.

 

For more info refer to my previous Blogs 😉

Stay tuned 🙂

Sed command…

Sed is a Stream Editor used for modifying the files in unix (or linux). We can use this command while making some changes like replacing text in a file.

I had here saved a file named file.txt with data

unix is great os. unix is opensource. unix is free os.
learn operating system.
unix linux which one you choose.

Examples:

  1. Replacing or Substituting string
sed 's/unix/linux/' file.txt
It will give output:
linux is great os. unix is opensource. unix is free os.
learn operating system.
linux linux which one you choose.
 "s" specifies the substitution operation. The "/" are delimiters. 
The "unix" is the search pattern and the "linux" is the replacement string.

By default, the sed command replaces the first occurrence of the pattern in
each line and it won't replace the second, third...occurrence in the line.

2. Replacing the nth occurrence of a pattern in a line
Use the /1, /2 etc flags to replace the first, second occurrence of a 
pattern in a line.
sed 's/unix/linux/2' file.txt
 Its output: unix is great os. linux is opensource. unix is free os.
learn operating system.
unix linux which one you choose.
The above command replaces the second occurrence of the word "unix"
 with "linux" in a line.

3. Replacing all the occurence of a pattern in a line
The substitute flag /g (global replacement) specifies the sed command to 
replace all the occurrences of the string in the line.
sed 's/unix/linux/g' file.txt

4. Replacing from nth occurrence to all occurrences in a line
sed 's/unix/linux/3g' file.txt
Its output: unix is great os. unix is opensource. linux is free os.
learn operating system.
unix linux which one you choose.

5. Double the word
sed 's/\(unix\)/\1\1/' file.txt
It replace the word "unix" in a line with twice as the word like "unixunix" 

6. Duplicating the replaced line with /p flag
The /p print flag prints the replaced line twice on the terminal.
If a line does not have the search pattern and is not replaced, 
then the /p prints that line only once.
sed 's/unix/linux/p' file.txt

Note:
How to make permanent changes in file?
sed -i 's/o/X/g' file.txt
It will replace all the 'o' in the file with 'X'
7. Creating backup of a file
sed -i.bak 's/o/X/g' file.txt
Screenshot from 2016-04-05 22-20-51

Stay tuned . . .
Thanks :)

“Power of Find”

The linux ‘find‘ command is very useful in searching files from Terminal. It can be used to find files based on various search criterias like permissions, modification date/time, size etc.The find command is available on most linux distros by default so you do not have to install any package.

Examples:

  1. LIST FILES IN CURRENT DIRECTORY

Screenshot from 2016-04-04 14:35:12

find . -print OR find OR find .
Above commands do same task.
Screenshot from 2016-04-04 14:36:43

  1. SEARCH SPECIFIC DIRECTORY OR PATH

Following command will look for files in the test directory in the current directory.

find ./test

The following command searches for files by their name.

find ./test -name "ty.txt"
We can also use wildcards
find ./test -name "*.txt"

1

3. IGNORE THE CASE

It is often useful to ignore the case when searching for file names. To ignore the case, just use the “iname” option instead of the “name” option.  Below is the command to print all files having extension php.

find ./test -iname "*.php" 

4. INVERT MATCH 
find ./test -not -name "*.php"

This will not print any file having extension php.
find ./test ! -name "*.php"  (This will also work in same manner)
2

5. COMBINE MULTIPLE SEARCH CRITERIAS

find ./test -name 'yo*' ! -name '*.php'

The above find command looks for files that begin with yo in their names
and do not have a php extension.

6. OR OPERATOR

find ./test -name ‘.php’ -o -name ‘.txt’

The above command search for files ending in either the php extension or the
txt extension. For OR there is ‘o’ switch.

7. SEARCH MULTIPLE DIRECTORIES TOGETHER

find ./test ./abc -type f -name “yo*”

It will list all the files in two directories starting from yo.

  1. SEARCH ONLY FILES OR ONLY DIRECTORIES

Only files

find ./test -type f

Only directories

find ./test -type d 

We can add -name "name of file.extension" after d and f to find a specific
directory or file.
9. FIND FILES WITH CERTAIN PERMISSIONS

find . -type f -perm 777
This can be useful to find files with wrong permissions which can lead to
security issues. This will show all files having 777 permission.
Inversion can also be applied to permission checking.
eg : find . -type f ! -perm 0777

10. DELETING FILES

find ./abc -type f -name "*.txt" -exec rm -f {} \;
This will delete files having extension txt in abc directory.
The same operating can be carried out with directories, 
just type d, instead of type f.

11. FINDING EMPTY FILES
  
  find ./test -type f -empty

12. LARGEST AND SMALLEST FILES
find ./test -type f -exec ls -s {} \; | sort -n -r | head -2
It will display the 2 largest file in the current directory.This may take a 
while to execute depending on the total number of files the command has to
process.
find ./test -type f -exec ls -s {} \; | sort -n | head -2
It will display 2 smallest files.

Stay tuned 🙂

Experience sharing time..

Yesterday I had given presentations on few topics among GD members.

First of all I just love giving presentations as It helps me in inhancing my confidence level and improving my communication skills as well. I just love this presentation session as during this I got to learn many new things such as: Making a website using github, Making a blog using Xampp as I was stuck in this but now after hearing it in the presentation session I got the solution. There were many more new things I got to learn like What happens between Boot and Login and heard about a new software i.e SageMath.

What next I love about this session is that I got a chance to face others questions which all GD members asks during presentation or in the end. As by this I got to know about the points where I am lacking and later on will work on it.

I am learning alot new things from here and really enjoying my work. Basically I am learning from my mistakes so that I should not repeat those in my next presentations and will get better and better. And finally a day will come when I will see a master change in myself .

Here I am also giving answers of all the questions asked by GD members which I hadn’t answered at that time.

My First topic was : Awk command in UNIX/LINUX

Little bit about Awk command is that,

If you are having a file with rows and columns, and want to pick particular rows and columns. We can use this command instead of opening and searching the files.

It has arrays and functions built inside it.

Q. What is bg command?

A question always arises in your mind that.

How do I run scripts in the background on Linux/Unix-like systems? How can I run jobs in the background on Terminal?

Job control is nothing but the ability to stop/suspend the execution of processes (command) and continue/resume their execution as per your requirements.

This is basically done by using bg command. It runs jobs in the background and manage the processes. There is no need to have root privileges for this

Firstly you can give command

jobs    OR    jobs -l                to see which processes are running.

eg. If you had opened gedit through Terminal and now you want to make it work in background. You will type gedit then press ctrl+z

After this type bg. It will make gedit run in background.

Screenshot from 2016-04-03 13-59-04

Appending an ampersand ( & ) to the command runs the job in the background. ctrl+z is for sending the file to background.

Furthur there are few more commands like,

awk ‘{print $1}’ input : To get the first column of the file.

And a few attempts but that didn’t worked at that time. Like,

awk {‘BEGIN{(sum=0)(sum=sum=+$2)END (print sum)’}input

Error: Now I got to know that even a mistake in giving space and wrong brackets can make the command wrong.

Here is the right command :

awk ‘BEGIN {sum=0} {sum=sum+$2} END {print sum}’ input

Note: Here input is the name of file. Though I will not use these kind of reserved words for file names from now as it creates chaos.

I also showed, Print $0 for printing the entire row

Print $1 $2 for printing respective columns. Also showed the sum of column entries using sum function. I formatted the two columns with colon (:).

But after prompting by the audience, can’t we write that to a file? I said “NO, we have to do that manually.

But now I am having the correct answer i.e

We can write in the file aswell using awk command as,

Screenshot from 2016-04-03 14-47-39

I had also explained,

NF is for No. of fields in each row  and   NR is for No. of rows.

For knowing more see my previous blog 🙂

Next is cp command in UNIX/LINUX

Q. Can we append a file to another using cp?

No we can not do it by cp. But it is possible using cat command

Screenshot from 2016-04-03 15-02-10

sudo cp -r -u -x -v /home/Downloads/ /media/UUI

Take in care about caps lock. s and h must be small here ,At that time I was using it in capital.

What are the flags?

These are permission flags refer to constants defined to represent corresponding permission bits

-r: recursively

-u: update only if source is newer

-x: don’t jump over filesystems. Stay on particular file.

-v: (verbose) Gives Acknowledgement i.e It gives feedback on what is happening.

For knowing more refer to my blog in presentations category.

Thanks 🙂

“Awk”

Awk is one of the most powerful tools in Unix used for processing the rows and columns in a file. Awk has built in string functions and associative arrays. Awk supports most of the operators, conditional blocks, and loops available in C language.

One of the good things is that you can convert Awk scripts into Perl scripts using a2p utility. (Awk to Perl translator) A2p takes an awk script specified on the command line (or from standard input) and produces a comparable perl script on the standard output.

Create a file with following data having rows and columns.

Screenshot from 2016-04-01 17-48-55

The rows are separated by a new line character and the columns are separated by a space characters. We will use this file as the input for the examples below.

Screenshot from 2016-04-01 17-51-29

In the first command, its printing first column. Similarly,in next second and third columns.

In third command, its taking sum of fifth column.

In the last command, sum is another file having a script

Screenshot from 2016-04-01 17-57-37

Input is our previous file having data in rows and columns. This command takes values from input file and operation is taken from sum file.

There are many other uses of this command also like,

Screenshot from 2016-04-01 18-08-17

In the first cmd, awk command checks for the string “t4” in the 9th column and if it finds a match then it will print the entire line.      Next, will print the squares of first numbers from 1 to 5.

Now for last command,

Awk Built in Variables:

You have already seen $0, $1, $2… which prints the entire line, first column, second column… respectively. Now we will see other built in variables with examples.

FS – Input field separator variable:

So far, we have seen the fields separted by a space character. By default Awk assumes that fields in a file are separted by space characters. If the fields in the file are separted by any other character, we can use the FS variable.  We had taken that character as : here. It will see now : separating columns from one another in place of space.

OFS – Output field separator variable:

By default whenever we printed the fields using the print statement the fields are displayed with space character as delimiter

Screenshot from 2016-04-01 18-17-13

Some other in-build variables used in commands are:

Screenshot from 2016-04-01 18-20-45

NF – Number of fields variable:

The NF can be used to know the number of fields in line.
This will display the number of columns in each row.

NR – number of records variable:

The NR can be used to know the line number or count of lines in a file.
This will display the line numbers from 1.

awk ‘END {print NR}’ input
This will display the total number of lines in the file.

String functions in Awk:

Some of the string functions in awk are:

length(string)
split(string,array,separator)
substr(string,position)
tolower(string)
toupper(string)

Thanks

Stay tuned 🙂