Wednesday 8 August 2012

Essential Commands in Ubuntu [2]


Hi friends, let's discuss some extra works which will help you learn more about Ubuntu Terminal.

Let's Start with a Text Editor:
I will discuss two text editors here, where one is common/general text editor in all Linux flavors, VI editor and another is sophisticated very popular Ubuntu text editor GEdit
Let's take practical example and discuss. 
Scenario is, let me create a text file My_File.txt at work location /home/kiran/. Choose any location in your system. So, open your Terminal first,
VI Editor:
The VI Editor is famous for its lite weight. The higher version of VI is VIM, with good visuals. 
In Terminal, I have navigated to cd /home/kiran/. Type vi My_File.txt and press enter, the VI editor opens My_File.txt in Terminal.
There are 2 modes in VI, one is command mode and another is text mode. 
In command mode, the characters you type are considered as commands, and in counter part, in text mode, what ever you type will be considered as plain text and will be updated into text file. 
On start-up VI will be in command mode. Remember, to execute any command in VI, like insert, save text, delete line, delete character, quit and many more, you should be in command mode of operation.
Once started, you are in command mode, to start inserting character press i from keyboard. The VI turns to text mode and accepts your characters. Type some texts. 
Once you are finished, now to do any operation you should go back to command mode. So to go back to command mode from text mode, press ESC from keyboard. Now VI in command mode of operation. To save and quit what ever you have entered, press ESC key and type :wq 
If you want to force quit (by discarding changes) press ESC BI key and type :q! from your keyboard. 
Notice colon (:) before the commands. Check some of the most popular VI commands in here, and to know more about VI check here.
GEdit:
GEdit is my favorite text editor in Ubuntu. It is a UTF-8 compatible text editor for GNOME desktop. It is very simple yet powerful tool for editing source codes, HTML, Scripts, all most all text editing operations. One of the most powerful feature of GEdit has Syntax Highlighting for various program code and text markup formats, means, as you write a keyword of any programming language, its syntax will be recognized automatically and highlighted with separate color !. Another beautiful feature about GEdit is, you can open multiple files in different tabs. So to simply start, type gedit My_File.txt and press enter, a new GEditor window will be opened. If the file My_File.txt already exist, it will be opened for editing and if doesn't exist it will be created and opened for editing. Type anything, to save press save button or use Ctrl+s keys from keyboard, and close the file.
Which editor is better to use? Answer is left to you. Some prefer VI and others, GEdit. Well, there are advantages if you learn VI commands, if at all you are made to work on non-Ubuntu Linux, then don't search for a text editor there, remember VI is available in all Linux flavors, just start using it.

Administrator Login
Let's see how to login as root in Ubuntu. root is an Administrator in Linux, which has got control over all the operations (for time being, remember, if any work is been denied the permission for you as Normal user, it means you have to execute that operation as root user).
So to login as root user in Ubuntu Terminal, type sudo su and press enter. Terminal asks password to login as root, enter administrator password which you gave during Ubuntu installation. Are you noticing, the password you type are Not Visible (but in actual terminal is receiving the password), just go on and once you finish, hit enter. If success, you will enter into Terminal as root user. Notice the change in prompt with # from previous prompt $, which indicates the operation you carry out next will be done as root.
Note: Next in this blog, or may be any where, wherever you find $ followed by a command, then it means you need not have root login to execute that command. When you notice # it means you should have root permission to execute that command presiding it. However # and $ are NOT a part of your command you type.
[*] Well, the word su stands for Super User, i.e. the root in Linux. The word sudo has special task to do with Ubuntu. The sudo is a command that allows user to run another command or program with security privileges of Super User. As I said, there are operations in Terminal which you cannot carryout as normal user, which needs root privileges to execute. The sudo is that command which gives you a temporary permission as root to execute some of the operations. As in case sudo su, 'sudo' allows you to execute su command (which has privilege of root) by giving you temporary permission as root.
[*] The sudo is abbreviation for Substitute User and DO the operation; some people also say it Super User and DO.
[*] Let me tell you a simple technique, you need not worry about what command or operation uses 'sudo' prefix before execution, you just try executing the commands as normal user. If command gives you any error, try putting sudo prefix at the beginning of that command. If still command doesn't execute, login as root and try it; this time you should be successful.
[*] In special cases, if you fail to execute the command even as root, remember, either the command has no meaning here in Ubuntu (means the command may be proprietary program of different Linux flavor) or There may not be proper dependency libraries installed in machine to execute that command (we will learn how to fix this issue in later sections).
[*] Once you type exit, when you loggedin as root, Terminal will exit you first from root and then again you have to type exit to close Terminal
[*] It is true, Linux commands are derived from Unix platform. But there are some proprietary commands applicable to particular flavors of Linux, like Ubuntu has its own commands which may not work in RedHat, similarly Redhat may use some proprietary libraries and packages which may not be applicable to Debian based computer operating systems.

Probably below contents, library installation or packages I am discussing here are mainly applicable to only Ubuntu and some other Debian based systems. I assume that you have Internet working in your Ubuntu system. I will post some of the methods to connect Internet in Ubuntu in next post. You should atleast have a standard external modem connected to your USB Port, a mobile used as Modem will also fine. Broadband will surely do great - just connect and surf. Believe me if you thinking about Telephone dial-up connection, till today with all kind of experiments I myself couldn't succeed; If you found any solution please let me know!

What's 'apt-get' gets?
[*] Once you have connected (working) Internet in your machine, it's very easy to install and update your libraries in Ubuntu. The command sudo apt-get does this operation for you.
[*] Linux, it mainly gives a control over source code of an application, so user could compile the source and use its executable when necessary. To compile such source codes you must have Libraries installed in your machine (obviously). 
[*] Not only for compilation process but also many of the work in Linux intern looks for their dependency libraries. To say it in simple way, you type a command on Terminal and press enter to execute it, but, that command should be known to Ubuntu and must have some meanings; that information will be held by shell library. So, cd, mkdir, sudo, pwd etc. all shell commands are set of library files which have got meaningful definition to execute their tasks. 
[*] Once the library file is missing in your machine, or the library you have installed is in different path which Terminal doesn't know, then that particular command will result into 'command not found error'. 
[*] Since Ubuntu belongs to Debian family, it uses Debian Package Managers. Package Managers are again set of Libraries (or an application you can say) which helps to manage other packages or software's in Linux. 
[*] Ubuntu seeks Debian file formats for installation. Debian files are set of formatted libraries which ends with file extension .deb. These deb files are usually called executable installers in Ubuntu, same like Setup.exe files in Windows. In RedHat and Fedora Linux, it is .rpm files which are most famous in Linux, where rpm stands for RedHat Package Manager. You cannot install rpm files in Ubuntu directly, because Debian platforms don't recognize rpm files as native standard packages. However there is a 3rd party application called alien which helps in installing rpm files in Debian based systems.
[*] One more important information to be remember is, each Library in Linux intern may or may not depend on other Libraries or files which, in overall, we call Dependencies. It is very important to know dependencies of a Library, because Linux needs all dependencies must have present installed in your machine before you install any other package or your own library; otherwise it will not allow you to install them. If library-A depends on library-B, then it is important that B must be installed and ready in your machine before you install library-A. One library may depend on several other libraries, which all you need to take care. If you downloaded any deb file, right click on it and see its properties, you will find what other libraries it depends on.
[*] Remember, each library in linux has its own release version number. Some library may depend on particular version of another dependency, which also you need to take care. Some times it also happens like Lib-A depends on Lib-B and Lib-B intern depends on Lib-A, in this case it's a dead-lock position, which one to install first? Solving dependencies is a major issue if you are trying to download deb files from one machine and carry it to your home machine for installation; bcoz deb files doesn't hold account for it's dependencies, it assumes you have dependencies already installed in your system.

You worried a little right? need not. There is a easy solution, as easy as simple command execution. The command sudo apt-get will take all your installation as well as your dependencies burden and works smoothly for you.
[*] The apt-get is a powerful command used with Ubuntu's Advanced Packaging Tool performing a supreme functions like installing new packages, upgrading existing packages, removing unnecessary packages, updating package list index and even at extreme upgrading entire Ubuntu system itself. The main advantage of apt-get is its ease of use at terminal with simple internet connected in system. The apt-get connects to internet and looks for the packages mentioned in its argument for download and installs automatically at appropriate location. The apt-get automatically takes care about all dependencies of package you are installing. If package A you are installing, depends on package B, the apt-get automatically looks for package B, installs it in prior to installation of A, makes all process smooth for A's installation and then looks for A and installs it. 
So, where does apt-get looks for any package? Should I search manually and provide any web location while issuing this command? The answer is, apt-get looks internally into 'a file' which has list of web address locations for all necessary and new released packages in Ubuntu. This list is stored locally in your hard drive, which apt-get refers into, when you type to install particular package. Ubuntu has many such repository FTP or HTTP web locations whole over the world, where a stable and new release packages will be added and kept ready for all users. The apt-get will look into those web locations to install your favorite packages. You can look in to that file under /etc/apt/sources.list.
What if Ubuntu you have installed is older one and many repositories might have updated with latest packages? How do you install those latest files into your machine? How do you know the package you have installed is very latest version? So, it is important you should have new list of addresses in your sources.list file, isn't it. In order to update the file list, type sudo apt-get update and press enter. Doing this will update the list of link's information in to your local machine with new released package repository addresses. Do it atleast once in a month or when you feel there is a new version of any package which you want to install is available. Let's see all commands in apt-get.
To Install a Package:
It is quite simple installing a package using apt-get. Use
sudo apt-get install package_name
For example to install Bin-Utils package (about which we cover later) type,
$sudo apt-get install binutils 
and press enter. You can see all the set of operation which apt-get taken care. The apt-get may ask for further permission while installing your package, say yes to it. Next steps will be handled by apt-get automatically, it installs all the dependencies of Bin-Utils before installing Bin-Utils itself.
To Remove a package:
removal of unnecessary package is also so easy, use
sudo apt-get remove package_name
For example to remove Bin-Utils, type sudo apt-get remove binutils and press enter. Be careful when you remove any package, it shouldn't hurt operating system's operation.
To Update package index:
As we have seen earlier, to update a package index use sudo apt-get update.
To Upgrade a package:
Over the time, updated versions for particular package may be available from the package repositories (for example may be some security updats). To upgrade your package, first update your package index as outlined above, and then type sudo apt-get upgrade package_name. Here package_name is optional, if you wish to upgrade a particular package then you can input the package name in argument, otherwise, be aware, all the packages installed in your system will get upgraded.
Some people get confuse with Update and Upgrade. The sudo apt-get update will update the list of database repository system, where as sudo apt-get upgrade will upgrade your package to new release version.
However, while Upgrading if the package needs to install or remove its new dependencies (if any), it will not be upgraded by the sudo apt-get upgrade command. For such an upgrade, it is necessary to use the sudo apt-get dist-upgrade command. After a fairly considerable amount of time, your computer will be upgraded to the new revision.
For further information about the use of APT type sudo apt-get help, and read.
In RedHat and Fedora Linux systems, the RedHat Package Manager will be used. It also has command line tool for installing packages, that is, yum install.

Let's conclude here. In next post I will discuss further steps in installing Tar files, Zip files and other executable files in Ubuntu. And we will also see some essential packages you must have in your system. Enjoy till then.

No comments:

Post a Comment