How to create symbolic links in Linux

Symbolic Links are basically a link to some application. They save your time to everytime go to that particular folder deep into the directory structure to start your application.

We can create a symbolic link by :-

ln -s location_of_your_link  your_term_for_link

Example

ln -s /usr/local/bin/eclipse eclipse

now when you type eclipse on terminal, it will go to that location_of_your_link and open it.

To confirm, the link has been created, try these

  1. Type eclipse and it will open up the application
  2. Use the command "ls -la", and you will see something like this 
lrwxrwxrwx.   1 tchander tchander         22 Nov 17  2015 eclipse -> /usr/local/bin/eclipse
 
arrow (->) means symbolic link

Enjoy Linux...







Contiguous Memory Allocation?

Contiguous Memory Allocation

Contiguous memory allocation is a classical memory allocation model that assigns a process, consecutive memory blocks (that is, memory blocks having consecutive addresses).





What is a socket in networking?


socket is one endpoint of a two-way communication link between two programs running on the network. 
socket is a combination of the port number and the IP address, so that the TCP/UDP layer can identify the application that data is destined to be sent to. 


Take an example of an apartment building ( World Famous Analogy)


  1. The street address of the building is the IP Address
  2. The specific apartment number in that building is the port number (port number tells the type of data transmission - TCP or UDP)
  3. The door of the apartment is the Socket (TCP + Socket)



So, the postman (TCP Layer) needs all the values
- Building Address (IP Address)
- Apartment Number (Port Number)
- Door (Socket)

so that the letter in postman's hand (data) can arrive at the correct destination (application).









What's a Memory Leak?


  • A memory leak is like a virtual oil leak in your computer. 
  • It will slowly drains the available memory, reducing the amount of free memory the system can use. 
  • Most memory leaks are caused by a program that unintentionally uses up increasing amounts of memory while it is running. 
  • This is typically a gradual process that gets worse as the program remains open. If the leak is bad enough, it can cause the program to crash or even make the whole computer freeze.



Reference - http://techterms.com/definition/memoryleak





How to do persistent mounting of a partition over a reboot?

Sometimes, we manually mount a folder but if we do a reboot, it doesn't stay there. 
So, How to mount a partition so that it remains persistent over reboot ?

mount --bind /source/folder destination/folder

Type the following in the /etc/fstab file

source/folder                destination/folder                 bind                 0 0


Then, if you do a reboot also, the mounted folder will stay as it is.

Creating File in CentOS Docker container



Let's create a file in the centos container.










So, you can see above

- I have a created a directory in my Centos Container (ae358738....) called Sample

- I have created a SampleText.txt file in it

- I exited the centos docker container

Now, to check this file again, we need to restart the same docker container
so, we use







[Press Enter]



And we are back to the same centos container and we can see our files back in it.









So, in this way, we can play between many Operating Systems keeping our whole work in each container safe also.





Exiting Ubuntu Docker Container


Now, to exit this UBUNTU docker container, simply type exit

now, to see the history of container you created, exited, on-going etc, type













To see only running containers,




Remember, if you open a ubuntu image 3 times, so, every time, there will be a different docker container.
And so, from the image, you can see, the containerID. They represent that I opened same ubuntu image multiple times, but, all were having a different docker container.







Docker commands (cont.)



To grab the image and download, docker has a pull command (sudo docker pull --help)





if well an image without tag, for instance




it will download multiple images of ubuntu as shown below












So, to avoid this downloading of multiple images, we use a tag

So, with a tag,





here, latest is acting a keyword which will bring down the latest version of ubuntu



To check the existing images in your local directory, type





To kill any running docker container,type





To delete any docker container,type







Docker


Docker is a virtualization technology like virtual box or vmware.

Allows multiple OS with multiple functionalities

The idea of docker is to virtualize all the apps on one Operating System. So, I can run 
multiple virtualization functionalities on a single OS and having those functionalities isolated from each other.

If you have an app which uses Java7 and there is an app which uses Java 8 , then through Docker both of them can run on a single OS side by side simultaneously, without installing both the JDK's on your machine keeping both of them completely isolated from each other .


Virtualization means having a disk image that represents the system we are running on. So, the docker registry contain tons of such images which we can containerise and use to run anywhere. The docker company and communities maintain this registry.


Remember, docker always require admin access, so use "sudo"






How to write to a file in shell script?


Linux uses >> operator to write to a file.

For instance:
If you want to calculate the size of your log directory and want to write it somewhere, then

du -s  /var/log>> filename

Isn't this simply awesome,


Multiple commands
( date +'%Y %m %d %H : %M'; du -s /var/log) >> LogsDirectorySize.txt;

In above sample, we are writing date plus size both. Yes, so simply use semi colon ; to write multiple things.








Enjoy Linux...!!!














How to find devices on a given network?



To find the devices on the given network, use nmap

On RHEL systems, 
$ sudo yum install nmap


On Unix Systems

$ sudo apt-get install nmap

$ nmap -sP IPaddress of your network

you can find IPaddress of your network by simply running ifconfig command and can find the pattern of IP address of your own netowork

So, my network has a pattern of 192.168.133....

$ nmap -sP 192.168.133.0/24


This will show you which hosts responded to ping requests on the network between 192.168.133.0 and 192.168.133.255.

Then, you can telnet into them for access.


Enjoy Linux..!!!








Update Local repository with server



Back

To synchronize all the changes done on the server with your local repository, use git PULL.

$ git pull origin BranchName
This will update the local files with the remote changes on the github server.


There is another way

$git reset --hard origin/BranchName



How to check the differences between two branches?

$ git diff branch_1 branch_2




How to update the server if the directory has been removed locally ?

1. git rm -r directory_name
2. git commit -m "directory_name removed"
3. git push origin branch_name




Compare same file under different branches 

git branch1 branch2 -- filename.js









Github - Branching




1. To create a new branch

$ git checkout -b branch_b1



2. To swtich back to master

$ git checkout master


3. To create a new branch from any other branch (other than master)

$ git checkout -b branch_b2 branch_b1



4. To list the available branches in your current repository

$ git branch -a


5. To delete the branch

$ git branch -d BranchName


6. To make the branch available to others through server repository

$ git push origin BranchName


7. How to sync local branch to the latest master on the server ?


We can do that, by the following steps

(Assume we are branch b1)
git fetch 
(This will reset the whole branch b1 to the server version)

git rebase origin/master(This will merge all the latest master into the branch b1)



Github



Git is really in use nowadays, and most of the companies are using it for smooth development and proper file synchronizations.

So, here is a small tutorial on using GITHUB from command line.


Create a account on github. And set your username and email on the terminal using the following git commands


  • git config --global user.name "your_name"
  • git config --global user.email "your_name@mail_domain.com"


1. Open a repository locally

$ git clone https://github.com/your_username/repository_name


Now, in Git work flow, your local repository consist of 3 stages.

a. Your Working Directory - This holds the actual files

b. Index - This is like a staging area.

c. Head - This points to the last commit you have made.


2. Suppose you create a new File, called modules.txt
So, to add this file to the server, you first have to add it to the index .

$ git add modules.txt

or 

$ git add *


3. But, to actually commit these changes

$ git commit -m "Some updating message"

This command basically moves your changes to one step ahead towards the HEAD.
But, still your changes are not yet saved to the server.


4. The process called PUSHING is responsible for saving to the server.

$ git push origin master

So, here,
origin = the local directory 
master = server repository. 

Master can be replaced by any other branch.

After this you will see something like 

Counting Objects...
Delta compression...
Writing Objects...
Total...
To https//.....


Summary

a) git Clone
b) git add
c) git commit
d) git push origin master







NVM - Node Version Manager



  • NVM stands for Node Version Manager.
  • It is really an awesome way to handle different versions of node and manipulate with them to work on different requirements.
  • So, to install it. 
  • Best Way is to install git 

(UBUNTU) 
  • apt-get install git 
  • Then, simply run
git clone https://github.com/creationix/nvm.git ~/.nvm && cd ~/.nvm && git checkout `git describe --abbrev=0 --tags`

  • To activate nvm, you need to source it from your shell:
$ . ~/.nvm/nvm.sh
  • Close the terminal and restart
  • So, now type 
$ nvm 
  • You will see a bunch of details about it.
  • Now, install for example, the 0.12 version of node

$ nvm install 0.12
$ nvm use 0.12



Thats all, 

Enjoy Linux..!!!
+CentOS +Ubuntu +Linux 







How to create a bootable USB device in Linux?

Thanks to Linux, it has made the creation of a bootable USB, ton of times easier than Windows.

So you just have to type the following command.

dd bs=4M if=file_name.iso of=/dev/sdb && sync


Ok, so the command looks easier, but most of the time people get stuck at of.

of means output file. Because, in output file, we cannot use the name of the file, instead we have to use the name, which the system has assigned to our USB or external HD.

So,  go to the terminal and type

df-h

There you will find a list of partitions and external medias connected to your machine.


That's all

Enjoy Linux..!!!
+CentOS +Ubuntu +Linux
  

Types of Rebooting



Cold Reboot

  • Also known as a hard reboot.
  • In this, the power to the system is physically turned off and back on again, causing an initial boot of the machine.


Warm Reboot

  • Also known as soft reboot.
  • In this the system restarts without the need to interrupt the power.






could not resolve error in github cloning...!!!!

Sometimes, we face the "could not resolve error" when we are trying to clone the github repository.

So, it happens when we have some kind of proxy set on our system.

So, either you can unset them and rerun the "git clone" command.


or

directly run this command based on the http type you are using to clone.

git config --global --unset http.proxy

or

git config --global --unset https.proxy
 





What's a proxy server?


In linux, you can check the proxy settings by using the command

$ env | grep proxy

or you can use the following commands

$echo $HTTPS_PROXY
$echo $HTTP_PROXY
$echo $http_proxy
$echo $https_proxy

If it doesn't show anything, then the proxy is not set.
Otherwise, you can unset them using the following commands.

$ unset  https_proxy
$ unset http_proxy







Text File Busy/Unexpected End of File Error in Bash

Sometimes, we get an error when we paste some bash code from windows environment to linux terminal. The error is like text file busy, or bash uninterrpreted error, Unexpected End of File etc. etc.

So, the poblem is, either the file is not writeable. 
So, chmod 777 filename

or 

the linux terminal is not able to read the input file.
So, run the dos2unix command
$ dos2unix filename.sh

And then run the bashscript
$ ./filename.sh

How to delete a directory even if it's not empty?

You might have seen, while using the "rmdir" command that you cannot delete this directory as it is not empty.

Use the following command :

> rm -r directoryName

or

> rm -rf directory_Name

so, "f" represents force. So, it will skip all the necessary checks and simply wipe out the whole directory.

Use SUDO, if you still cannot delete.



Enjoy Linux...!!!!
+CentOS
+Linux
+Ubuntu

How To in Linux

How to remove npm ?


  • Ok, so npm stands for Node Package Manager, and trust me, it's really an awesome thing. 
  • It is a package manager for various things, like angular, node (default), gulp, grunt, mobile, javascript and many more.
  • But, it is also important to know, how to uninstall npm from the system to get a fresh npm later.
  • So, here it goes
$ sudo npm uninstall npm -g
$ npm -v
  • To remove everything related to npm,
$ rm -rf /usr/local/{lib/node{,/.npm,_modules},bin,share/man}/npm*


Simple..!!!


Enjoy Linux
+CentOS

    Delete dual boot options on windows

    Sometimes, we see multiple options of windows even if they are not running because of failed installation.
    So, to remove them,

    1. Goto run, and type msconfig:
    2. After msconfig is launched:
    3. Go to the Boot tab
    4. Slect the boot entry you want to delete.
    5. Click the Delete button and then click OK.

    Thats all.

    How to know if a package is there on your CentOS or not ?


    To find a exisiting package on your CentOS system, just type this command 


    # rpm -ql "package_name"

    For instance, to download the youtube videos, we need the youtube package - "youtube -dl" 

    rpm -ql youtube-dl

    So, you will see a list of files within that package, and that makes sure the presence of that package on your system. 




    If the package is not installed, the terminal will display 

    " package youtube-dl is not installed "



    That's all



    Live Linux...!!!
    +CentOS