Thursday, March 28, 2019

Technical difference between HARD and SOFT links in linux

Hard and Soft links, hmm what are those?

Well we are going to see what are those and how they are technically different from one another, lets jump in

Most of the people who uses windows operating system should be familiar with the term ShortCuts, which is nothing but accessing a file indirectly... if you want me to put this in other terms, I would say referring the contents through other means.

Well in Linux and Unix like operating systems, this concept would remain same as far as Soft links are concerned well with Hard links the story is entirely different.

Let us justify ourselves through a small demonstration....

Create a file in your favourite location using the following command
> touch mainfile.txt
Let us see the statistics of the file mailfile.txt using the following command...
> stat mainfile.txt

From the above image, we take three important properties i.e Inode, Links and the type of the file which is nothing but regular empty file, for now let the file be empty and when we try dealing with Hard Links we put some contents in it.

Soft Link
Now let me create a soft link for the file mailfile.txt, the command given below would create a soft link for the file mainfile.txt
> ln -s mainfile.txt softlink-for-mainfile
the above command would create a new file named softlink-for-mainfile which would point to the file mainfile.txt and not the inode of the file mainfile.txt, technically the actual file i.e mainfile.txt and the link to it are two different files. the soft link to the actual file has no meaning in the absence of the main file.

Let us have the statistics of the two file

Statistics of mainfile.txt


Statistics of softlink-for-mainfile



If you look at the File property from both the stat it is very evident that the second file is a link to the first one. The File property is not the only which confirms that but the inode property too, please do have a look at it the values of inode are different.

Now I am going to move the main file to a different location in order to test the validity of the link that we created.

Try moving the file mainfile.txt using the following command...
> mv mainfile.txt ../


From the picture above, it is evident that the soft link has become invalid when the file is removed/moved or deleted from the original location. You can also confirm this by trying display the contents of the file using the cat command as given below...
> cat softlink-for-mainfile


As said now we can conclude that the soft link becomes invalid without the original file.

So as far as soft links are concerned, we could have the below inference...

1. Soft links cannot stand alone
2. Soft links becomes invalid if the source/original file is moved to different location
3. Soft link and the original file are not the same but they are two different files.

Hard Link
Let us now deal the second part of the story i.e the Hard links

Let us create a hard link of the file mainfile.txt using the command given below...
> ln mainfile.txt hardlink-for-mainfile
After the execution of the command, you would have a file named hardlink-for-mainfile at the location where you executed the command, this can be witnessed from the image below...


Now let us have the statistics of the both the files....

Statistics of mainfile.txt


Statistics of hardlink-for-mainfile



From the images above, you can infer the following details

1. Both the files pointing to the same inode
2. Both the files are regular empty file
3. The total number of links to the inode is 2, which is given against the property Links.

Regarding the links, if you try to have another hard link to the mainfile.txt... the links count would be increased to 3, let us see how is this

Try creating an other hard link to the file mainfile.txt
> ln mainfile.txt hardlink-for-mainfile-1
now if you look at the stat of the file mainfile.txt, the Links property of the inode would have increased by 1, to justify that have a look at the screen shot given below...



Now here comes the interesting part of the story, put some contents into the file mainfile.txt using the command as given below
> echo "hello world" > mainfile.txt
now let us have the stat of the file mainfile.txt


As you can see the file has been changed from "regular empty file" to "regular file". Now, what would be your expectation on the files hardlink-for-mainfile and hardlink-for-mainfile-1, let us see from the screen shots given below...

Statistics of the hard link hardlink-for-mainfile and hardlink-for-mainfile-1



If we look at the image above everything remains same except the name of the file... which conveys all the three files are pointing to the same inode than the different one.

This can even be concluded by deleting the original file, Now try deleting the original file i.e mainfile.txt using the below command and look at the statistics of the hard links we created.
> rm mainfile.txt




From the above image it is evident that, though the original file is deleted the hard links created would retain the inode that actually belongs to the original file.

So, we could conclude the morale of the story as follows...

1. soft link created on a file cannot stand alone without the original file
2. soft link has its own inode
2. hard links would retain the inode of the original file even though the original is deleted
3. hard links uses the same inode as that of the original file.

Hope you liked the story. Thanks.

Wednesday, March 27, 2019

Technical difference between "mv" and "cp" command in LINUX

In this post we are going to discuss about the difference i.e the technical difference between Move and Copy command in linux.

As we all know the copy command is used to make the replica of a file or a directory in linux, where as the Move command it moves the file or a directory to a another location that we mention as part of the command.

What we discussed above is a theoretical difference between these commands, but how technically they are different? well, to answer this question we have to have the statistics of a file soon after the execution of the above mentioned commands.

Let me put this in a simple way to understand.... assuming we have a file named test.txt in one of the locations in the file system as given in the image below...


before we move further, I would like to discuss the details mentioned in the image

  • First column of numbers is the inode number of the file/directory
  • Second column tells us the privileges available on a file/directory
  • Third column gives the number of links to the file/directory
  • Fourth column gives the user who owns the file
  • Fifth column gives the group of the user
  • Sixth column is the IO Block of the file
  • Seventh column gives the last modified date of the file/directory
  • Eight column gives the time at the file/directory is modified
  • Ninth column is the name of the file/directory


From the above details, the real candidate for consideration is the INODE number of the file/directory, this number is generated by the file system for the files/directories when they are created, but how this inode number tells the techinical difference between these two commands?

Rather talking, actions would give ample information to convince us so let us get on with it.

let me take the COPY command first...

Before we copy the file test.txt let us have the statistics of the file itself...



the image above and the previous one would have the same inode number against the file test.txt, you can check it comparing the images above

Now let us take the replica of the file test.txt i.e copying the file to another location in the file system and analyse the statistics of the file again...


As you can see the inode of the file test.txt which is available in the new location is entirely different from the previous one.

From this we can conclude that the file copied to a new location is not the same file as the one which is copied but it a replica of the old file.

Now let us try to move the file test.txt to a new location and infer the statistics...


From the above image if we look at the inode number of the file, it is same as that of the one available in the last location, from this stats we can conclude that the file which moved is the same old file and the command does not create a new file as that of the old one and deletes the old.

Hope this post helps in understanding a bit about inode, files and commands.

Post you comments and thanks.

Thursday, March 21, 2019

Want to get rid of "System program problem detected" in ubuntu

What is this post is all about?



Well those who are familiar with Ubuntu Linux operating system might have encountered this problem, this alert message normally appears at start up of the system. What is this error message and what is it trying to convey?

The answer is pretty simple, When ever we try to install something and during installation if there is some breakage in the package this alert message pops up every time you login to the system.

Some people really do not care about such pops up where as for some it is a serious issue...

Before we correct this pop up problem, let us understand why this happens.

As I said earlier this problem happens due to some broken packages available in the system, but how did I get those broken packages well there could be lot of reasons, some of them are mentioned below...

  • When the supporting packages are not available.
    • assuming you are trying to install jenkins package in your system, the package manager tries to find all its supporting packages online, in case the package manager find all it needs to install jenkins the installation process goes fine, if not it would end up as an error... this would results in broken packages..
  • When your internet is broken in the middle of the installation process.
    • During the process of installation of a package and when the package manager finds all the supporting packages it needs to install the actual package, the process continues as long as your internet connection is stable, if not you would encounter this from ubuntu.

What I mentioned above are some of the reasons... there could be other reasons contributing to this alert message as well.

Now the time has come to clear this alert message from the system, when ever such broken package or crash situation happens, ubuntu logs the situation in the folder /var/crash

Just like the entries in the image given below....


The simple solution to get rid of this problem is to delete all the entries you find in the folder by using the command below..

> rm /var/crash/*

What we have discussed here is a temporary solution, well I prefer to stick to the temporary solution as far as this error is concerned because if any such situation happens in future... it would help us to track the problem for further investigation.

Well that is it and hope you have found the solution here for your problem.

Thanks. 

Wednesday, March 20, 2019

Installing Jenkins 2.164.1 CI Server in Ubuntu-16.04 LTS

Hi, in this post we are going to see how to install Jenkins Continuous Integration Server in ubuntu.

The following are the required soft wares needed to have a successful installation

1. java-1.6 or greater
2. Jenkins war file

We are going to use the WAR package of jenkins to have the server up and running

Since most of us know how to install java, I am not going to talk about installing it, you can check online resources(plenty available) on how to install the same.

Let us download the Jenkins-2.164.1.war file from the location given below

http://mirrors.jenkins.io/war-stable/latest/jenkins.war

Make sure you have the downloaded package in a location you prefer.

Open a terminal and execute the command below to have your server up and running
> java -jar <location-of-jenkins.war>/jenkins.war

When the server is ready to serve... you should be able to see console as something below...




After executing the above command, Open a browser and on the address bar type the location as below...
http://localhost:8080/

Now your browser would have you at the page as given below...



Well this concludes the installation of Jenkins CI server... hope you like it

thanks.

Deleting a broken package completely in Ubuntu

In this post I would like to share some details about deleting completely a broken package in Ubuntu.

Let me setup the scenario first...

Let us assume you were trying to install a package from the package repository using apt-get, unfortunately due to some error during the installation process and unmet dependencies, the installation package results broken and you would see a DANGER Icon appearing on top of the screen indicating you have a broken package installed.

Some of us would rarely care about this broken package and would spend some time on correcting it but for some people it would be annoying having the DANGER Icon at the top and would also engage themselves in fixing it.

This post is for those who tries to keep the system clean.....

You might be searching internet for solutions, some would usually find it and rectify the error but most of us would have no idea on how to get it done.

Executing some commands sequentially as said below would help in rectifying the error easily...

Lets get into action....

It is always a better start to update the installed packages, during the update process, the process would also list the package which is found to be broken...

The command to have the update process is given below...
> sudo apt-get update
the above command would ask you to provide the password to start the execution, provide the one associated with the user account, this would also update the packages installed in the system, when it encounters the broken package, it would highlight the one... just remember the name of the package.

the next command that would come into action is given below i.e the general syntax of the command
> sudo apt-get remove --purge *<name-of-the-broken-package>*
for eg... if you have a broken package named "jenkins" then the above command can be re-written as
follows
> sudo apt-get remove --purge *jenkins*
When you press enter... the command would list all the related packages along with the broken one with the question "Do you want to continue? [Y/n]

Press "Y"/"y" to continue to remove the broken package.

And it is a good practice to update the packages again once the broken one is removed.

At this point you can see the DANGER Icon disappearing at the top of the screen.

This concludes the removal of the broken package in Ubuntu.

Hope you enjoyed reading, Thanks.

Friday, March 15, 2019

Reset the password of 'root' user in MySql in Ubuntu-16.0.4

Hi all, In this post we are going to see how to reset the password of root user in mysql

As we all know the root user of mysql is something like the root user of linux with full power to access anything in MySql database server.

Normally during the install, the installation would ask for password to set for the root user but there are occasions where as administrator or developer would pushed to reset the password.

This post talks about resetting the password in a precise manner.

This post assumes that you already have a valid MySql Server instance up and running and I am going to use the command line tool i.e the Terminal for connecting to the server and resetting the password.

Let's start it...

Open a terminal and check whether the MySql server is up and running....
> sudo systemctl status mysql
In my case I had the following response on the terminal



If the server is up and running, then you would have something like given below...



Stop the Server(MySql Server) using the command given below
> sudo systemctl stop mysql
Now we have the server stopped.

We have to start the MySql Server differently to have the passord reset for the user root, to do that you must edit mysqld.cnf file located in /etc/mysql/mysql.conf.d folder...

Now open mysqld.cnf file in your favourite editor and try to locate the group [mysqld], you can use the picture below to locate...



At the top of the group or just below the line which contains the content [mysqld]
add the line as said below
skip-grant-tables
Now the configuration file should appear something like the one shown below...



Save the file and exit from the text editor

Now try to start the server using the terminal as given below...
> sudo systemctl start mysql
Check the status of the mysql process
> sudo systemctl status mysql
you should have something like given below...



Connect to mysql server from the command using the command "mysql"
> mysql --user=root
Now you should be connected to the server and what you see on the server is the response connected to the server without the password for the user "root"



Change the password of the user "root" using the statement like the one given below...



Now stop the server and revert back the changes that we made in mysqld.cnf file and start the server...

Connect to the server now using the password switch..
> mysql --user=root --password
Which would ask you to provide the password, provide the one you updated the user with, now you have successfully changed the password of the user "root"



Hope you enjoyed the post, feel free to post your comments...

Thanks.

Tuesday, March 5, 2019

Installing Hudson-3.3.3 CI Server in Ubuntu-16.04 LTS

Hi, in this post we are going to see how to install Hudson Continuous Integration Server in ubuntu.

The following are the required soft wares need  to have a successful installation

1. java-1.6 or greater
2. hudson-3.3.3.war

We are going to use the WAR package of hudson to have the server up and running

Since most of us know how to install java, I am not going to talk about installing it, you can check online resources(plenty available) on how to install the same.

Let us download the hudson-3.3.3.war file from the location given below


Make sure you have the downloaded package in a location you prefer.

Open a terminal and execute the command below to have your server up and running
> java -jar <location-of-hudson-3.3.3.war>/hudson-3.3.3.war

When the server is ready to serve... you should be able to see console as something below...



After executing the above command, Open a browser and on the address bar type the location as below...
http://localhost:8080/

Now your browser would have you at the page as given below...



Well this concludes the installation of hudson-3.3.3 CI server... hope you like it

thanks.

How to change the root password in linux when it is forgotten/to change

This blog is all about changing the root password of the Linux system when it is forgotten or to reset the password...   Let's get it ...