How to connect To Remote MySQL/MariaDB Database Server Via Command Line in Linux

This post will guide you how to connect to the remote MySQL/MariaDB database server from command Line Interface under your Linux operating system. How do I access my remote MySQL database from command line on Linux.

Connect Remote MySQL Server Via Linux Terminal


If you are using a CentOS/Ubuntu Linux, and you want to connect to a remote MySQL/MariaDB database server, you need to install mysql client package firstly on your Linux system. Just issue the following command to install it:

$ sudo yum install mysql-client

or

$ sudo apt-get install mysql-client

Outputs:

devops@devops-osetc:~$ sudo apt-get install mysql-client
sudo: unable to resolve host devops-osetc
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
libaio1 mysql-client-5.7 mysql-client-core-5.7 mysql-common
The following NEW packages will be installed:
libaio1 mysql-client mysql-client-5.7 mysql-client-core-5.7 mysql-common
0 upgraded, 5 newly installed, 0 to remove and 598 not upgraded.
Need to get 7,782 kB of archives.
After this operation, 65.7 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://us.archive.ubuntu.com/ubuntu xenial/main amd64 libaio1 amd64 0.3.110-2 [6,356 B]
Get:2 http://us.archive.ubuntu.com/ubuntu xenial-updates/main amd64 mysql-client-core-5.7 amd64 5.7.24-0ubuntu0.16.04.1 [6,030 kB]
Get:3 http://us.archive.ubuntu.com/ubuntu xenial-updates/main amd64 mysql-common all 5.7.24-0ubuntu0.16.04.1 [15.3 kB]
Get:4 http://us.archive.ubuntu.com/ubuntu xenial-updates/main amd64 mysql-client-5.7 amd64 5.7.24-0ubuntu0.16.04.1 [1,720 kB]
Get:5 http://us.archive.ubuntu.com/ubuntu xenial-updates/main amd64 mysql-client all 5.7.24-0ubuntu0.16.04.1 [10.1 kB]
Fetched 7,782 kB in 13s (592 kB/s)
Selecting previously unselected package libaio1:amd64.
(Reading database ... 178950 files and directories currently installed.)
Preparing to unpack .../libaio1_0.3.110-2_amd64.deb ...
Unpacking libaio1:amd64 (0.3.110-2) ...
Selecting previously unselected package mysql-client-core-5.7.
Preparing to unpack .../mysql-client-core-5.7_5.7.24-0ubuntu0.16.04.1_amd64.deb ...
Unpacking mysql-client-core-5.7 (5.7.24-0ubuntu0.16.04.1) ...
Selecting previously unselected package mysql-common.
Preparing to unpack .../mysql-common_5.7.24-0ubuntu0.16.04.1_all.deb ...
Unpacking mysql-common (5.7.24-0ubuntu0.16.04.1) ...
Selecting previously unselected package mysql-client-5.7.
Preparing to unpack .../mysql-client-5.7_5.7.24-0ubuntu0.16.04.1_amd64.deb ...
Unpacking mysql-client-5.7 (5.7.24-0ubuntu0.16.04.1) ...
Selecting previously unselected package mysql-client.
Preparing to unpack .../mysql-client_5.7.24-0ubuntu0.16.04.1_all.deb ...
Unpacking mysql-client (5.7.24-0ubuntu0.16.04.1) ...
Processing triggers for libc-bin (2.23-0ubuntu5) ...
Processing triggers for man-db (2.7.5-1) ...
Setting up libaio1:amd64 (0.3.110-2) ...
Setting up mysql-client-core-5.7 (5.7.24-0ubuntu0.16.04.1) ...
Setting up mysql-common (5.7.24-0ubuntu0.16.04.1) ...
update-alternatives: using /etc/mysql/my.cnf.fallback to provide /etc/mysql/my.cnf (my.cnf) in auto mode
Setting up mysql-client-5.7 (5.7.24-0ubuntu0.16.04.1) ...
Setting up mysql-client (5.7.24-0ubuntu0.16.04.1) ...
Processing triggers for libc-bin (2.23-0ubuntu5) ...

After installed mysql client package, you can use mysql command to connect to your MySQL Database server, issue the following command:

$ mysql -u dbuser_name -h database_servername -p

then you need to type the password for dbuser.

Let’s see the below example to connect my database server:
Type:

$ mysql -u root -h localhost -p

Outputs:

devops@devops-osetc:~$ mysql -u root -h localhost -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.24-0ubuntu0.16.04.1 (Ubuntu)

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

Now you have connected your MySQL Database server and you can do some mysql operation, such as: query, update, and so on.

List All Databases in Your MySQL Server


If you want to list all databases in your MySQL/Mariadb Server, you can type the following mysql command:

Note: you need to connect to your MySQL Database server firstly.

> show databases;

Outputs:

mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.02 sec)

mysql>

Selecting a Database


If you want to query a table or data from a table in a specific database, you need to select that database firstly, just executing the following mysql command:

> use mysql;

Outputs:

mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql>

So the current database has been changed to mysql database.

Create a New Database


If you want to create a new database in your connected MySQL database server, just use the create command to achieve it. type:

> create database myosetc;

Outputs:

mysql> create database myosetc;
Query OK, 1 row affected (0.00 sec)

mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| myosetc |
| mysql |
| performance_schema |
| sys |
+--------------------+
5 rows in set (0.00 sec)

mysql>

Form the above outputs, we can see that the myosetc database has been created in MySQL server.

List All Tables in a Database


If you want to list all tables in a specific database or your current database, you can use the following command:

>show tables;

Outputs:

mysql> show tables;
+---------------------------+
| Tables_in_mysql |
+---------------------------+
| columns_priv |
| db |
| engine_cost |
| event |
| func |
| general_log |
| gtid_executed |
| help_category |
| help_keyword |
| help_relation |
| help_topic |
| innodb_index_stats |
| innodb_table_stats |
| ndb_binlog_index |
| plugin |
| proc |
| procs_priv |
| proxies_priv |
| server_cost |
| servers |
| slave_master_info |
| slave_relay_log_info |
| slave_worker_info |
| slow_log |
| tables_priv |
| time_zone |
| time_zone_leap_second |
| time_zone_name |
| time_zone_transition |
| time_zone_transition_type |
| user |
+---------------------------+
31 rows in set (0.01 sec)

mysql>

Obtain Information About Table Structure


If you want to check the structure of one table in your database, and you can use the desc command to get it, type:

> desc user;

Outputs:

mysql> desc time_zone;
+------------------+------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------------+------------------+------+-----+---------+----------------+
| Time_zone_id | int(10) unsigned | NO | PRI | NULL | auto_increment |
| Use_leap_seconds | enum('Y','N') | NO | | N | |
+------------------+------------------+------+-----+---------+----------------+
2 rows in set (0.00 sec)

List all Data in A Table


If you want to list all data in a table, such as, server_cost table, just issue the following command:

>select * from server_cost;

Outputs:

mysql> select * from server_cost;
+------------------------------+------------+---------------------+---------+
| cost_name | cost_value | last_update | comment |
+------------------------------+------------+---------------------+---------+
| disk_temptable_create_cost | NULL | 2017-08-01 13:39:40 | NULL |
| disk_temptable_row_cost | NULL | 2017-08-01 13:39:40 | NULL |
| key_compare_cost | NULL | 2017-08-01 13:39:40 | NULL |
| memory_temptable_create_cost | NULL | 2017-08-01 13:39:40 | NULL |
| memory_temptable_row_cost | NULL | 2017-08-01 13:39:40 | NULL |
| row_evaluate_cost | NULL | 2017-08-01 13:39:40 | NULL |
+------------------------------+------------+---------------------+---------+
6 rows in set (0.00 sec)

mysql>

Quit MySQL Connection


If you want to quit the connection of your MySQL Database, just issue the following mysql command:

>quit

Outputs:

mysql> quit
Bye
devops@devops-osetc:~$

Video:Connect Remote MySQL Server Remotly

How to Create A New File with Vi/Vim Text Editor on Linux

This post will guide you how to create new file with vi/vim text editor in CentOS/RHEL/Ubuntu Linux. How do I create a new file in the current directory on Linux. How to save a file in vi/vim Editor in Linux. How to insert text into a file with vi/vim editor.

Vi/Vim is a text editor in Linux, and you can use this tool to create/modify a file or multiple files.

Create A new File with Vi/Vim


vi tool is installed by default in your Linux system, and vim is not installed by default, so if you want to use the vim editor, you need to installed it firstly. type the following command:

# yum install vim (For CentOS Linux)

Or

$ sudo apt-get install vim (For Ubuntu/Debian linux)

Outputs:

devops@devops-osetc:~$ sudo apt-get install vim
sudo: unable to resolve host devops-osetc
Reading package lists... Done
Building dependency tree
Reading state information... Done
Suggested packages:
ctags vim-doc vim-scripts
The following NEW packages will be installed:
vim
0 upgraded, 1 newly installed, 0 to remove and 598 not upgraded.
Need to get 0 B/1,036 kB of archives.
After this operation, 2,458 kB of additional disk space will be used.
Selecting previously unselected package vim.
(Reading database ... 178944 files and directories currently installed.)
Preparing to unpack .../vim_2%3a7.4.1689-3ubuntu1.2_amd64.deb ...
Unpacking vim (2:7.4.1689-3ubuntu1.2) ...
Setting up vim (2:7.4.1689-3ubuntu1.2) ...
update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/vim (vim) in auto mode
update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/vimdiff (vimdiff) in auto mode
update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/rvim (rvim) in auto mode
update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/rview (rview) in auto mode
update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/vi (vi) in auto mode
update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/view (view) in auto mode
update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/ex (ex) in auto mode

If you want to create a new file called fio.txt under the current directory, just execute the following command:

# vim fio.txt

Then this file will be opened. and press “:wq” to save and close the file. the file fio.txt has been created under the current directory.

Insert Text into File with vi/Vim


If you want to insert text into a file that has been created, you need to use the vi/vim command to open this file, and press “i” key in your keyboard to enter into the INSERT mode of the Vim editor. and then you can type the text into this file.

Save and close the File via Vi/Vim


If you want to save the modification of the file that is in the INSERT mode, you need to press “ESC” key to exit the INSERT mode, and type the command “:w” to save the modification.

If you want to save and close the file, and you need to type the comand “:wq” or ‘:x’.

Video: Create file with Vi/Vim

 

How to Check If Package Is Installed in CentOS/RHEL/Ubuntu Linux

This post will guide you how to check if package is installed on CentOS/RHEL/Ubuntu Linux. How to find if a package is installed or not in CentOS/RHEL/Ubuntu Linux system. How to List all installed packages in your Linux operating system.

Check If Package Is Installed in Linux


Before installed one package, you need to check if this package is installed already or not in your Linux system. So How to check the installed packages in the different Linux distribution. Let’s see the following introduction.

For CentOS/RHEL Linux

If you are using CentOS/RHEL Linux, and you want to check if a specific package is installed or not, you can use the rpm command with -qa option to achieve the result. Type the following command to check if httpd package is installed or not:

$ rpm -qa | grep httpd

Outputs:

[root@osetc_test ~]# rpm -qa | grep httpd
httpd-tools-2.2.15-59.el6.centos.x86_64
httpd-tools-2.2.15-60.el6.centos.6.x86_64
httpd-2.2.15-60.el6.centos.6.x86_64

From the above outputs, you can know that the httpd package has been installed in your system, and the installed version of httpd is 2.2.15-60.

You can also use the yum command to achieve the same result, type:

$ yum list installed httpd

Outputs:

[root@osetc_test ~]# yum list installed httpd
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.sonic.net
* epel: mirror.sjc02.svwh.net
* extras: mirror.fileplanet.com
* updates: mirror.sjc02.svwh.net
Installed Packages
httpd.x86_64 2.2.15-60.el6.centos.6 @updates
[root@osetc_test ~]#

List All Installed Packages

If you want only to list all installed packages in your CentOS/RHEL linux, you can use one of the following command:

$ rpm -qa

Or

$ yum list installed

For Ubuntu/Debian Linux

If you are using Ubuntu/Debian Linux, and you can use the dpkg command to find out a package is installed or not. type the following command to check if httpd package is installed or not:

$ dpkg -s httpd

Outputs:

devops@devops-osetc:~$ dpkg -s httpd
dpkg-query: package 'httpd' is not installed and no information is available
Use dpkg --info (= dpkg-deb --info) to examine archive files,
and dpkg --contents (= dpkg-deb --contents) to list their contents.

From the above outputs, you should know that the httpd package is not installed in your Ubuntu Linux system.

Let’s see another example to check if wget package is installed or not, type:

$ dpkg -s wget

Outputs:

devops@devops-osetc:~$ dpkg -s wget
Package: wget
Status: install ok installed
Priority: important
Section: web
Installed-Size: 880
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Architecture: amd64
Multi-Arch: foreign
Version: 1.17.1-1ubuntu1.1
Depends: libc6 (>= 2.17), libidn11 (>= 1.13), libpcre3, libssl1.0.0 (>= 1.0.1), libuuid1 (>= 2.16), zlib1g (>= 1:1.1.4)
Recommends: ca-certificates
Conflicts: wget-ssl
Conffiles:
/etc/wgetrc c43064699caf6109f4b3da0405c06ebb
Description: retrieves files from the web
Wget is a network utility to retrieve files from the web
using HTTP(S) and FTP, the two most widely used internet
protocols. It works non-interactively, so it will work in
the background, after having logged off. The program supports
recursive retrieval of web-authoring pages as well as FTP
sites -- you can use Wget to make mirrors of archives and
home pages or to travel the web like a WWW robot.
.
Wget works particularly well with slow or unstable connections
by continuing to retrieve a document until the document is fully
downloaded. Re-getting files from where it left off works on
servers (both HTTP and FTP) that support it. Both HTTP and FTP
retrievals can be time stamped, so Wget can see if the remote
file has changed since the last retrieval and automatically
retrieve the new version if it has.
.
Wget supports proxy servers; this can lighten the network load,
speed up retrieval, and provide access behind firewalls.
Homepage: https://www.gnu.org/software/wget/
Original-Maintainer: Noël Köthe <noel@debian.org>

You can also use the dpkg-query command to achieve the same result of checking the package is installed or not, type:

$ dpkg-query -l 'wget'
$ dpkg-query -l 'httpd'

Outputs:

devops@devops-osetc:~$ dpkg-query -l 'wget'
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name Version Architecture Description
+++-===========================-==================-==================-============================================================
ii wget 1.17.1-1ubuntu1.1 amd64 retrieves files from the web

devops@devops-osetc:~$ dpkg-query -l 'httpd'
dpkg-query: no packages found matching httpd

List All Installed Packages in Ubuntu

If you want to list all installed packages in Ubuntu Linux, you can use one of the following command:

$ dpkg -l

Or

$ dpkg-query -l

 

How to Get Color Man Pages on CentOS/RHEL/Ubuntu Linux

This post will guide you how to get color man pages of Linux command in bash shell. How to get some nicely colored man pages under Linux operating system.

Get Colored Man Pages Using Most Command


You can use a most tool that is a powerful program for Linux system that displays file contents on page wise. and it display status line on the screen which includes file name, current line number, and the percentage of the file so far displayed.

Install Most Tool

For Ubuntu/Debian Linux

If you are using Ubuntu/Debian Linux, you can use the apt-get command to install the most package, just type the following command:

$ sudo apt-get install most

Outputs:

devops@devops-osetc:~$ sudo apt-get install most
sudo: unable to resolve host devops-osetc
[sudo] password for devops:
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following package was automatically installed and is no longer required:
libtinfo-dev
Use 'sudo apt autoremove' to remove it.
The following NEW packages will be installed:
most
0 upgraded, 1 newly installed, 0 to remove and 598 not upgraded.
Need to get 42.6 kB of archives.
After this operation, 117 kB of additional disk space will be used.
Get:1 http://us.archive.ubuntu.com/ubuntu xenial-updates/universe amd64 most amd64 5.0.0a-2.3+deb8u1build0.16.04.1 [42.6 kB]
Fetched 42.6 kB in 1s (36.3 kB/s)
Selecting previously unselected package most.
(Reading database ... 178950 files and directories currently installed.)
Preparing to unpack .../most_5.0.0a-2.3+deb8u1build0.16.04.1_amd64.deb ...
Unpacking most (5.0.0a-2.3+deb8u1build0.16.04.1) ...
Processing triggers for man-db (2.7.5-1) ...
Processing triggers for mime-support (3.59ubuntu1) ...
Setting up most (5.0.0a-2.3+deb8u1build0.16.04.1) ...

For CentOS/RHEL Linux

If you are using CentOS/RHEL/ORACLE Linux, you can use the yum command to install most package, type:

$ sudo yum install most

Outputs:

[root@osetc_test ~]# yum install most
Loaded plugins: fastestmirror
Setting up Install Process
Loading mirror speeds from cached hostfile
epel/metalink | 17 kB 00:00
* base: mirrors.sonic.net
* epel: mirror.sjc02.svwh.net
* extras: mirror.keystealth.org
* updates: mirror.sjc02.svwh.net
base | 3.7 kB 00:00
epel | 3.2 kB 00:00
epel/primary | 3.2 MB 00:00
epel 12497/12497
extras | 3.4 kB 00:00
updates | 3.4 kB 00:00
Resolving Dependencies
There are unfinished transactions remaining. You might consider running yum-complete-transaction first to finish them.
The program yum-complete-transaction is found in the yum-utils package.
--> Running transaction check
---> Package most.x86_64 0:5.0.0-14.a.1.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

==========================================================================================================================================================================
Package Arch Version Repository Size
==========================================================================================================================================================================
Installing:
most x86_64 5.0.0-14.a.1.el6 epel 54 k

Transaction Summary
==========================================================================================================================================================================
Install 1 Package(s)

Total download size: 54 k
Installed size: 102 k
Is this ok [y/N]: y
Downloading Packages:
most-5.0.0-14.a.1.el6.x86_64.rpm | 54 kB 00:00
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : most-5.0.0-14.a.1.el6.x86_64 1/1
Verifying : most-5.0.0-14.a.1.el6.x86_64 1/1

Installed:
most.x86_64 0:5.0.0-14.a.1.el6

Complete!

For Fedora Linux

You can use the DNF command to install most package, type:

$ sudo dnf install most

For Arch Linux

If you are using Arch Linux, you can use the Pacman command to install most package, type:

$ sudo pacman -S most

For OpenSUSE Linux

If you are using the OpenSUSE Linux, you can use the Zypper command to install most tool, type:

# zypper install most

For FreeBSD Unix

If you are using the FreeBSD Unix, and you can use the pkg command to install most, type:

# pkg install most

Using Most Command

After installed most command on your Linux system, you should add the following lines into .bashrc file to set environment variable.

export PAGER="most"

Or

export PAGER="/usr/bin/most -s"

Save and close the file. and execute the below command to take this command effect.

# source .bashrc

Then you can try to run a man command to see if the man page has been colored.

# man

color man page1

Get Colored Man Pages Using Less Command


There is another way to get colored man pages and you can use the less command that is a free, open-source file pager. and you can use this command to view the file contents on screen from top to buttom.

You just need to append the following line into the .bashrc file which is a hidden file located in your home directory which gets read each time a new bash instance launched. and the new bash shell will read all the commands found in this file and executes them.

export LESS_TERMCAP_mb=$'\E[1;31m'     # begin bold
export LESS_TERMCAP_md=$'\E[1;36m'     # begin blink
export LESS_TERMCAP_me=$'\E[0m'        # reset bold/blink
export LESS_TERMCAP_so=$'\E[01;44;33m' # begin reverse video
export LESS_TERMCAP_se=$'\E[0m'        # reset reverse video
export LESS_TERMCAP_us=$'\E[1;32m'     # begin underline
export LESS_TERMCAP_ue=$'\E[0m'        # reset underline
export GROFF_NO_SGR=1                  # for konsole and gnome-terminal

Then you need to run source command to make the newly variable to take effect.

$ source .bashrc

Trying to run one man command to check if you get the colored man page:

# man ls

color man page2

How to Convert Octal Number to Hexadecimal Number in Linux

This post will guide you how to convert octal number to hexadecimal number in Linux system. How do I convert from hex to octal using bc command on CentOS/Ubuntu Linux. How to convert number base using echo command in combination with bc command under Linux operating system.

Convert Octal to Hexadecimal Number


If you want to convert octal to hexadecimal number in bash shell in Linux, you can use the echo command and then combine with bc command to achieve the result. For example, you want to convert a octal number 16 to hex, just type the following command:

$ echo "obase=16; ibase=8; 16" | bc

Outputs:

devops@devops-osetc:~$ echo "obase=16; ibase=8; 16" | bc
E

Note: the obase is set to the output base, and the ibase is set to the input base, and 16 is the number that you want to convert.
You can also use the printf command to convert octal to hex number in Linux shell, just type:

$ printf "%X\n" 016

Outputs:

devops@devops-osetc:~$ printf "%X\n" 016
E

Convert Hexadecimal Number to Octal Number


To convert Hexadecimal to Ocatl number, you can execute the following command:

$ echo "obase=8; ibase=16; 16" | bc

or

$ printf "%o\n" 0x16

Outputs:

devops@devops-osetc:~$ echo "obase=8; ibase=16; 16" | bc
26
devops@devops-osetc:~$ printf "%o\n" 0x16
26

Convert Decimal to Hexadecimal Number


To convert Decimal to hex number in bash shell, you can use the following command to achieve the result, type:

$ echo "obase=1;16" | bc

Or

$ printf "%X\n" 16

Outputs:

devops@devops-osetc:~$ echo "obase=16;16" | bc
10
devops@devops-osetc:~$ printf "%X\n" 16
10

Convert Decimal to Octal Number


If you want to convert decimal to octal number, just use one of the following commands:

$ echo "obase=8;16" | bc

Or

$ printf "%o\n" 16

Outputs:

devops@devops-osetc:~$ echo "obase=8;16" | bc
20
devops@devops-osetc:~$ printf "%o\n" 16
20

Convert Decimal to Binary Number


If you want to convert a decimal number to binary in bash shell in Linux, you can execute the following command:

$ echo "obase=2;16" | bc

Outputs:

devops@devops-osetc:~$ echo "obase=2;16" | bc
10000

Convert Hexadecimal to Decimal Number


To convert a hex number to decimal in bash shell, just use the following command:

$ echo "ibase=16;E" | bc

Or

$ printf "%d\n" 0xE

Outputs:

devops@devops-osetc:~$ echo "ibase=16;E" | bc
14

devops@devops-osetc:~$ printf "%d\n" 0xE
14

Convert Octal to Decimal Number


To convert octal to decimal number, type:

$ echo "ibase=8;16" | bc

Or

$ printf "%d\n" o16

Outputs:

devops@devops-osetc:~$ echo "ibase=8;16" | bc
14
devops@devops-osetc:~$ printf "%d\n" 016
14

Convert Binary to Decimal Number


If you want to convert a binary number to decimal in bash shell in Linux, you can use the following command:

$ echo "ibase=2;10000" | bc

Outputs:

devops@devops-osetc:~$ echo "ibase=2;10000" | bc
16

 

How to Find Wireless Chipset Information on CentOS/RHEL/Ubuntu Linux

This post will guide you how to check the information of currently installed WiFi drivers on your CentOS/RHEL/Ubuntu Linux system. How do I find out which WiFi driver is installed on your Linux system. How to find the hardware chipset information on CentOS Linux. How to find ou the name of my wireless chipset or interface information on Ubuntu/Debian Linux.

Find Wireless Chipset Information


You can use the lspci command to check the information of PCI buese of your computer. just type the following command to check the wireless chipset information:

$ lspci | grep -i wireless

Outputs:

devops@devops-osetc:~$ lspci | grep -i wireless
03:00.0 Network controller: Broadcom Corporation BCM4360 802.11ac Wireless Network Adapter (rev 03)

Then you can execute the following command to get the information about the wireless adapter driver:

$ lspci -vv -s 03:00.0

Or you can issue the following command to list the information of wireless chipset, type:

$ lspci -nnk | grep -A2 0280

Outputs:

08:00.0 Network controller [0280]: Realtek Semiconductor Co., Ltd. RTL8723AE PCIe Wireless Network Adapter [10ec:8723] Subsystem: Realtek Semiconductor Co., Ltd. Device [10ec:0724] Kernel driver in use: rtl8723ae

Find Network Wire Adapter Chipset Information


If you want to get the information of the network adapter chipset information on your Linux system, you also can use the lspci or lshw commands to achieve the result. just type the following command:

$ lshw -C network

Outputs:

devops@devops-osetc:~$ lshw -C network
WARNING: you should run this program as super-user.
*-network
description: Ethernet interface
product: 82540EM Gigabit Ethernet Controller
vendor: Intel Corporation
physical id: 3
bus info: pci@0000:00:03.0
logical name: enp0s3
version: 02
serial: 08:00:27:d9:84:92
size: 1Gbit/s
capacity: 1Gbit/s
width: 32 bits
clock: 66MHz
capabilities: bus_master cap_list ethernet physical tp 10bt 10bt-fd 100bt 100bt-fd 1000bt-fd autonegotiation
configuration: autonegotiation=on broadcast=yes driver=e1000 driverversion=7.3.21-k8-NAPI duplex=full ip=10.182.39.73 latency=64 link=yes mingnt=255 multicast=yes port=twisted pair speed=1Gbit/s
resources: irq:19 memory:f0000000-f001ffff ioport:d010(size=8)
WARNING: output may be incomplete or inaccurate, you should run this program as super-user.

From about outputs, you can find lots of information about network adapter, including description, vendor, product,driver information.

This command will give you information about both wired and wireless network adapters. As thise is no wireless adapter for my system , so the output do not print the information about wire adapter.

You can use the lspci command to get the same information about network adapter, type:

$ lspci --nnk | grep -A2 0200

Outputs:

devops@devops-osetc:~$ lspci -nnk | grep -A2 0200
00:03.0 Ethernet controller [0200]: Intel Corporation 82540EM Gigabit Ethernet Controller [8086:100e] (rev 02)
Subsystem: Intel Corporation PRO/1000 MT Desktop Adapter [8086:001e]
Kernel driver in use: e1000

Once you get the driver name that you are using in your system, and you can use the modinfo command to show more inforamation about this driver. From the above outputs, we can know that the current network adapter driver is e1000, so we can type the following command to get more detailed information about this driver:

$ modinfo e1000

Outputs:

devops@devops-osetc:~$ modinfo e1000
filename: /lib/modules/4.8.0-36-generic/kernel/drivers/net/ethernet/intel/e1000/e1000.ko
version: 7.3.21-k8-NAPI
license: GPL
description: Intel(R) PRO/1000 Network Driver
author: Intel Corporation, <linux.nics@intel.com> srcversion: A2CE8CF7D2BAFE382A1AB61
alias: pci:v00008086d00002E6Esv*sd*bc*sc*i*
alias: pci:v00008086d000010B5sv*sd*bc*sc*i*
alias: pci:v00008086d00001099sv*sd*bc*sc*i*
alias: pci:v00008086d0000108Asv*sd*bc*sc*i*
alias: pci:v00008086d0000107Csv*sd*bc*sc*i*
alias: pci:v00008086d0000107Bsv*sd*bc*sc*i*
alias: pci:v00008086d0000107Asv*sd*bc*sc*i*
alias: pci:v00008086d00001079sv*sd*bc*sc*i*
alias: pci:v00008086d00001078sv*sd*bc*sc*i*
alias: pci:v00008086d00001077sv*sd*bc*sc*i*
alias: pci:v00008086d00001076sv*sd*bc*sc*i*
alias: pci:v00008086d00001075sv*sd*bc*sc*i*
alias: pci:v00008086d00001028sv*sd*bc*sc*i*
alias: pci:v00008086d00001027sv*sd*bc*sc*i*
alias: pci:v00008086d00001026sv*sd*bc*sc*i*
alias: pci:v00008086d0000101Esv*sd*bc*sc*i*
alias: pci:v00008086d0000101Dsv*sd*bc*sc*i*
alias: pci:v00008086d0000101Asv*sd*bc*sc*i*
alias: pci:v00008086d00001019sv*sd*bc*sc*i*
alias: pci:v00008086d00001018sv*sd*bc*sc*i*
alias: pci:v00008086d00001017sv*sd*bc*sc*i*
alias: pci:v00008086d00001016sv*sd*bc*sc*i*
alias: pci:v00008086d00001015sv*sd*bc*sc*i*
alias: pci:v00008086d00001014sv*sd*bc*sc*i*
alias: pci:v00008086d00001013sv*sd*bc*sc*i*
alias: pci:v00008086d00001012sv*sd*bc*sc*i*
alias: pci:v00008086d00001011sv*sd*bc*sc*i*
alias: pci:v00008086d00001010sv*sd*bc*sc*i*
alias: pci:v00008086d0000100Fsv*sd*bc*sc*i*
alias: pci:v00008086d0000100Esv*sd*bc*sc*i*
alias: pci:v00008086d0000100Dsv*sd*bc*sc*i*
alias: pci:v00008086d0000100Csv*sd*bc*sc*i*
alias: pci:v00008086d00001009sv*sd*bc*sc*i*
alias: pci:v00008086d00001008sv*sd*bc*sc*i*
alias: pci:v00008086d00001004sv*sd*bc*sc*i*
alias: pci:v00008086d00001001sv*sd*bc*sc*i*
alias: pci:v00008086d00001000sv*sd*bc*sc*i*
depends:
intree: Y
vermagic: 4.8.0-36-generic SMP mod_unload modversions
parm: TxDescriptors:Number of transmit descriptors (array of int)
parm: RxDescriptors:Number of receive descriptors (array of int)
parm: Speed:Speed setting (array of int)
parm: Duplex:Duplex setting (array of int)
parm: AutoNeg:Advertised auto-negotiation setting (array of int)
parm: FlowControl:Flow Control setting (array of int)
parm: XsumRX:Disable or enable Receive Checksum offload (array of int)
parm: TxIntDelay:Transmit Interrupt Delay (array of int)
parm: TxAbsIntDelay:Transmit Absolute Interrupt Delay (array of int)
parm: RxIntDelay:Receive Interrupt Delay (array of int)
parm: RxAbsIntDelay:Receive Absolute Interrupt Delay (array of int)
parm: InterruptThrottleRate:Interrupt Throttling Rate (array of int)
parm: SmartPowerDownEnable:Enable PHY smart power down (array of int)
parm: copybreak:Maximum size of packet that is copied to a new buffer on receive (uint)
parm: debug:Debug level (0=none,...,16=all) (int)
devops@devops-osetc:~$

If you want to get more information about lspci and lshw commands, you can use the following commands:

$ man lshw

or

$ man lspci

 

How to Get Dell Service Tab On CentOS/RHEL/Ubuntu Linux

This post will guide you how to get your Dell Service Tab from the command line in CentOS/RHEL/Ubuntu Linux system. How to find your Dell Service Tab number via the Linux command. How to check the serial number of your Dell laptop computer under Linux operating system.

Get Service Tab of Your Dell Service Tab


You can use the dmidecode tool to get the various infomation of your Dell Laptop computer service tag. you can get the BIOS information of Dell server. and this command is not installed by default. So you need to install the dmidecode package on your Linux system.

For CentOS/RHEL Linux:
You can use the yum command to install the dmidecode tool, type the following command:

# yum install dmidecode

outputs:

[root@osetc_test ~]# yum install dmidecode
Loaded plugins: fastestmirror
Setting up Install Process
Loading mirror speeds from cached hostfile
* base: mirror.sjc02.svwh.net
* epel: mirror.sjc02.svwh.net
* extras: mirror.sjc02.svwh.net
* updates: mirror.sjc02.svwh.net
Resolving Dependencies
There are unfinished transactions remaining. You might consider running yum-complete-transaction first to finish them.
The program yum-complete-transaction is found in the yum-utils package.
--> Running transaction check
---> Package dmidecode.x86_64 1:2.12-7.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=======================================================================================================================================
Package Arch Version Repository Size
=======================================================================================================================================
Installing:
dmidecode x86_64 1:2.12-7.el6 base 74 k

Transaction Summary
=======================================================================================================================================
Install 1 Package(s)

Total download size: 74 k
Installed size: 191 k
Is this ok [y/N]:
Downloading Packages:
dmidecode-2.12-7.el6.x86_64.rpm | 74 kB 00:00
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : 1:dmidecode-2.12-7.el6.x86_64 1/1
Verifying : 1:dmidecode-2.12-7.el6.x86_64 1/1

Installed:
dmidecode.x86_64 1:2.12-7.el6

Complete!

Get Dell Service Tab with Dmidecode command

You can execute the following dmidecode command to get out Dell service tab, type:

# dmidecode | grep -i serial

Or

# dmidecode -s system-serial-number

 

How to Know the GCC Version Used to Compile Linux kernel on Linux

This post will guide you how to know the gcc compiler version that used to compile the current linux kernel on CentOS/Ubuntu Linux system. How to find the Linux kernel version and GCC compiler version on your system. How to identify what version of GCC compiler was used to compile your running Linux kernel.

Check Linux Kernel Version


If you want to get the running Linux kernel version on your system, you can use the following command to get it.

$ uname -a

or

$ cat /proc/version

outputs:

devops@devops-osetc:~$ uname -a
Linux devops-osetc 4.8.0-36-generic #36~16.04.1-Ubuntu SMP Sun Feb 5 09:39:57 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
devops@devops-osetc:~$ cat /proc/version
Linux version 4.8.0-36-generic (buildd@lgw01-18) (gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.4) ) #36~16.04.1-Ubuntu SMP Sun Feb 5 09:39:57 UTC 2017

From the above outputs, you can know the current version of running Linux kernel is 4.8.0-36.

Check GCC Compiler Version Used to Compile Kernel


If you installed multiple versions of GCC compilers in your system, and then you want to check the GCC compiler version that used to compile the running Linux kernel on your system, How to achieve the result. You can get it from /proc/version file. type the following command:

$ cat /proc/version

Outputs:

Linux version 4.8.0-36-generic (buildd@lgw01-18) (gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.4) ) #36~16.04.1-Ubuntu SMP Sun Feb 5 09:39:57 UTC 2017

So we can see from the above outputs that the gcc version is gcc version 5.4.0 .

Install An Older GCC Compiler Version (gcc 4.3.2)


If you need to install an older version of GCC Compiler on your Linux system, you can download the GCC Compiler source package from http://mirrors-usa.go-parts.com/gcc/releases/gcc-4.3.2/gcc-4.3.2.tar.gz, and compile and install the source code. just do the following commands:

$ wget http://mirrors-usa.go-parts.com/gcc/releases/gcc-4.3.2/gcc-4.3.2.tar.gz
$ tar -zxvf gcc-4.3.2.tar.gz
$ cd gcc-4.3.2
$ ./configure
$ make;make install;

Check the Version of GCC Compiler Is Installed


If you want to check the versions of GCC compiler are installed in your Linux system, you can use the following commands:

For Ubuntu/Debian Linux:

Type:

$ dpkg --list | grep -i gcc

Outputs:

devops@devops-osetc:~$ dpkg --list | grep -i gcc
ii gcc 4:5.3.1-1ubuntu1 amd64 GNU C compiler
ii gcc-3.4 3.4.6-5 amd64 The GNU C compiler
ii gcc-3.4-base 3.4.6-5 amd64 The GNU Compiler Collection (base package)
ii gcc-5 5.4.0-6ubuntu1~16.04.4 amd64 GNU C compiler
ii gcc-5-base:amd64 5.4.0-6ubuntu1~16.04.4 amd64 GCC, the GNU Compiler Collection (base package)
ii gcc-6-base:amd64 6.0.1-0ubuntu1 amd64 GCC, the GNU Compiler Collection (base package)
ii gir1.2-packagekitglib-1.0 0.8.17-4ubuntu6~gcc5.4ubuntu1.1 amd64 GObject introspection data for the PackageKit GLib library
ii libcaca0:amd64 0.99.beta19-2build2~gcc5.2 amd64 colour ASCII art library
ii libcc1-0:amd64 5.4.0-6ubuntu1~16.04.4 amd64 GCC cc1 plugin for GDB
ii libgcc-5-dev:amd64 5.4.0-6ubuntu1~16.04.4 amd64 GCC support library (development files)
ii libgcc1:amd64 1:6.0.1-0ubuntu1 amd64 GCC support library
ii libgomp1:amd64 5.4.0-6ubuntu1~16.04.4 amd64 GCC OpenMP (GOMP) support library
ii libpackagekit-glib2-16:amd64 0.8.17-4ubuntu6~gcc5.4ubuntu1.1 amd64 Library for accessing PackageKit using GLib
ii libquadmath0:amd64 5.4.0-6ubuntu1~16.04.4 amd64 GCC Quad-Precision Math Library
ii libunity-action-qt1:amd64 1.1.0+14.04.20140304-0ubuntu2~gcc5.1 amd64 Unity Action Qt API
ii libwebrtc-audio-processing-0:amd64 0.1-3ubuntu1~gcc5.1 amd64 AudioProcessing module from the WebRTC project.
ii qtchooser 52-gae5eeef-2build1~gcc5.2 amd64 Wrapper to select between Qt development binary versions
ii qtdeclarative5-unity-action-plugin:amd64 1.1.0+14.04.20140304-0ubuntu2~gcc5.1 amd64 Unity Action QML Components

For CentOS/RHEL Linux:

Type:

$ yum list intalled | grep -i gcc

outputs:

[root@osetc_test ~]# yum list installed | grep -i gcc
gcc.x86_64 4.4.7-23.el6 @base
gcc-c++.x86_64 4.4.7-23.el6 @base
gcc-gfortran.x86_64 4.4.7-23.el6 @base
libgcc.x86_64 4.4.7-23.el6 @base

Choose the Default GCC Version


If you want to compile a C program with a specific version of GCC Compiler, then you need to change the default GCC compiler version, for example, you want to choose the GCC compiler 3.4 as the default compiler. just run one of the following command:

$ export gcc=/usr/bin/gcc-3.4

Or

$ sudo rm /usr/bin/gcc
$ sudo ln -s /usr/bin/gcc-3.4 /usr/bin/gcc

Verify the default GCC Compiler Version

$ gcc --version

Outputs:

devops@devops-osetc:~$ gcc --version
gcc (GCC) 3.4.6 (Debian 3.4.6-5)
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Video: Check GCC Version Used to Compile running Linux kernel

See Also:

How to Check What Compilers Are Installed on CentOS/RHEL/Ubuntu Linux

This post will guide you how to check what compilers are install on your CentOS/RHEL/Ubuntu/Debian Linux system. How do I check if GNU GCC Compiler is installed on Linux. How do I list all available compilers that can be installed in Linux.

Check What Compilers Are Installed


Assuming that you have installed core development tools in your Linux system, and you want to check what compilers are installed, how to achieve the results in different Linux distribution system.

For Ubuntu/Debian Linux:

If you are using the Ubuntu/Debian Linux, you can use the dpkg command to check what compilers have been installed in your system. Issue the following command:

$ dpkg --list | grep compiler

Outputs:

devops@devops-osetc:~$ dpkg --list | grep compiler
ii g++ 4:5.3.1-1ubuntu1 amd64 GNU C++ compiler
ii g++-5 5.4.0-6ubuntu1~16.04.4 amd64 GNU C++ compiler
ii gcc 4:5.3.1-1ubuntu1 amd64 GNU C compiler
ii gcc-5 5.4.0-6ubuntu1~16.04.4 amd64 GNU C compiler
ii hardening-includes 2.7ubuntu2 all Makefile for enabling compiler flags for security hardening
ii libllvm3.8:amd64 1:3.8-2ubuntu4 amd64 Modular compiler and toolchain technologies, runtime library
ii libxkbcommon0:amd64 0.5.0-1ubuntu2 amd64 library interface to the XKB compiler - shared library

For the above outputs, you can know that the GNU GCC compiler has been installed. and you can use it to compile C or C++ programs on your Linux system.

For CentOS/RHEL Linux:

If you are using the Centos/RHEL Linux, and you can use the “yum install installed” command to check what compilers are installed. Issue the following command:

# yum list installed | grep gcc

or

# yum list installed | grep java

or

# yum list installed | grep automake

Outputs:

[root@osetc_test working]# yum list installed | grep -i --color compiler
[root@osetc_test working]#
[root@osetc_test working]# yum list installed | grep gcc
gcc.x86_64 4.4.7-23.el6 @base
gcc-c++.x86_64 4.4.7-23.el6 @base
gcc-gfortran.x86_64 4.4.7-23.el6 @base
libgcc.x86_64 4.4.7-23.el6 @base
[root@osetc_test working]# yum list installed | grep java
[root@osetc_test working]# yum list installed | grep automake
automake.noarch 1.11.1-4.el6 @base
[root@osetc_test working]# yum list installed | grep perl
perl.x86_64 4:5.10.1-144.el6 @base
perl-Compress-Raw-Zlib.x86_64 1:2.021-144.el6 @base
perl-Compress-Zlib.x86_64 2.021-144.el6 @base
perl-DBD-MySQL.x86_64 4.013-3.el6 @base
perl-DBI.x86_64 1.609-4.el6 @base
perl-Error.noarch 1:0.17015-4.el6 @base
perl-Git.noarch 1.7.1-9.el6_9 @base
perl-HTML-Parser.x86_64 3.64-2.el6 @base
perl-HTML-Tagset.noarch 3.20-4.el6 @base
perl-IO-Compress-Base.x86_64 2.021-144.el6 @base
perl-IO-Compress-Zlib.x86_64 2.021-144.el6 @base
perl-Module-Pluggable.x86_64 1:3.90-144.el6 @base
perl-Pod-Escapes.x86_64 1:1.04-144.el6 @base
perl-Pod-Simple.x86_64 1:3.13-144.el6 @base
perl-URI.noarch 1.40-2.el6 @base
perl-XML-Parser.x86_64 2.36-7.el6 @base
perl-libs.x86_64 4:5.10.1-144.el6 @base
perl-libwww-perl.noarch 5.833-5.el6 @base
perl-version.x86_64 3:0.77-144.el6 @base

Check C/C++ Compiler is Installed


If you want only check if C/C++ compiler is installed on Linux, you can run the following command:

$ type -a gcc

or

$ which gcc

Outputs:

[root@osetc_test working]# type -a gcc
gcc is /usr/bin/gcc
[root@osetc_test working]# which gcc
/usr/bin/gcc

Check C/C++ Compilers Version


To check the version of GNU GCC C/C++ Compiler on your Linux system, you can issue the following command:

$ gcc --version

outpus:

[root@osetc_test working]# gcc --version
gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-23)
Copyright (C) 2010 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Check which Fortran Compiler is installed


To check the version of installed fortran compiler on your Linux system, type the following command:

$ gfortran -v

outputs;

[root@osetc_test working]# gfortran -v
Using built-in specs.
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre --enable-libgcj-multifile --enable-java-maintainer-mode --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libjava-multilib --with-ppl --with-cloog --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux
Thread model: posix
gcc version 4.4.7 20120313 (Red Hat 4.4.7-23) (GCC)

Check All Available Compilers Can be Installed


If you want to check the list of available compilers can be installed in your system, you can execute the following command:

For CentOS/RHEL Linux:

Type:

$ yum search all compiler

Outputs:

[root@osetc_test working]# yum serach all compiler
Loaded plugins: fastestmirror
No such command: serach. Please use /usr/bin/yum --help
[root@osetc_test working]# yum search all compiler
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirror.fileplanet.com
* epel: mirror.sjc02.svwh.net
* extras: mirror.sfo12.us.leaseweb.net
* updates: mirror.sfo12.us.leaseweb.net
=========================================== Matched: compiler ===========================================
......
compat-gcc-34.x86_64 : Compatibility GNU Compiler Collection
compat-gcc-34-c++.x86_64 : C++ support for compatibility compiler
compat-gcc-34-g77.x86_64 : Fortran 77 support for compatibility compiler
cross-gcc-common.noarch : Cross-build GNU C compiler documentation and translation files
csclng.x86_64 : A compiler wrapper that runs Clang in background
cscppc.x86_64 : A compiler wrapper that runs cppcheck in background
csmatch.x86_64 : A compiler wrapper that runs smatch in background
cswrap.x86_64 : Generic compiler wrapper
dtc.x86_64 : Device Tree Compiler
ecj.x86_64 : Eclipse Compiler for Java
eclipse-photran-intel.noarch : Intel Fortran compiler support for Photran
......

For Ubuntu/Debian Linux:

Type:

$ apt-cache search Compiler | less

Outputs:

devops@devops-osetc:~$ apt-cache search Compiler | less
antlr - language tool for constructing recognizers, compilers etc
antlr-doc - language tool for constructing recognizers, compilers etc
binutils - GNU assembler, linker and binary utilities
binutils-multiarch - Binary utilities that support multi-arch targets
ca-certificates-mono - Common CA certificates (Mono keystore)
ccache - Compiler cache for fast recompilation of C/C++ code
cmake - cross-platform, open-source make system
cmake-doc - extended documentation in various formats for CMake
cpp - GNU C preprocessor (cpp)
cpp-5 - GNU C preprocessor
cpp-5-aarch64-linux-gnu - GNU C preprocessor
cpp-5-arm-linux-gnueabihf - GNU C preprocessor
cpp-5-powerpc-linux-gnu - GNU C preprocessor
cpp-5-powerpc64le-linux-gnu - GNU C preprocessor
cpp-aarch64-linux-gnu - GNU C preprocessor (cpp) for the arm64 architecture
cpp-arm-linux-gnueabihf - GNU C preprocessor (cpp) for the armhf architecture
cpp-powerpc-linux-gnu - GNU C preprocessor (cpp) for the powerpc architecture
cpp-powerpc64le-linux-gnu - GNU C preprocessor (cpp) for the ppc64el architecture
device-tree-compiler - Device Tree Compiler for Flat Device Trees
dpkg-dev - Debian package development tools
......

Install Compiler in Linux


To install compilers on your Linux system, you can use the yum command to install the specific compiler, such as: GNU GCC compiler, you can run the following command:

$ sudo yum install gcc

or

$ sudo yum groupinstall "Development Tools"

If you are using the Ubuntu or Debian Linux, you can use the following command to install GNU GCC compiler:

$ sudo apt-get update
$ sudo apt-get install build-essential

Video: Checking What Compilers are Installed on CentOS/RHEL/Ubuntu Linux

See Also:

How To Install Ncurse Library in Ubuntu/Debian/CentOS/Fedora Linux

This post will guide you how to install ncurse library in Unix-like operating systems. How to use the ncurses library in your C program and then compile it on Linux system.

GNU ncurses is a programming library providing an application programming interface that allows the programmer to write text-based user interfaces in a terminal-independent manner. You can use the ncurses library to develop “GUI-like” application software that runs under a terminal emulator on Linux system.

Install Ncurses Library with Default Repository


You can install the Ncurses library with the default repository on the different Unix-like system.

For CentOS/RHEL Linux, you can use the yum command to install the following one package (ncurses-devel) on your system, type:

$ sudo yum install ncurses-devel

Outputs:

[root@osetc ~]# yum install ncurses-devel
Loaded plugins: fastestmirror
Setting up Install Process
Loading mirror speeds from cached hostfile
epel/metalink | 17 kB 00:00
* base: mirror.sjc02.svwh.net
* epel: mirror.sjc02.svwh.net
* extras: mirror.sfo12.us.leaseweb.net
* updates: mirror.sfo12.us.leaseweb.net
base | 3.7 kB 00:00
epel | 3.2 kB 00:00
extras | 3.4 kB 00:00
updates | 3.4 kB 00:00
Resolving Dependencies
There are unfinished transactions remaining. You might consider running yum-complete-transaction first to finish them.
The program yum-complete-transaction is found in the yum-utils package.
--> Running transaction check
---> Package ncurses-devel.x86_64 0:5.7-4.20090207.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
ncurses-devel x86_64 5.7-4.20090207.el6 base 641 k

Transaction Summary
================================================================================
Install 1 Package(s)

Total download size: 641 k
Installed size: 1.7 M
Is this ok [y/N]:y

For Ubuntu/Debian Linux:

If you are using Ubuntu/Debian Linux, you can use the apt-get command to install the following two packages: libncurses5-dev libncursesw5-dev, type:

$ sudo apt-get install libncurses5-dev libncursesw5-dev

Outputs:

devops@devops-osetc:~/working$ sudo apt-get install libncurses5-dev libncursesw5-dev
sudo: unable to resolve host devops-osetc
[sudo] password for devops:
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
libtinfo-dev
Suggested packages:
ncurses-doc
The following NEW packages will be installed:
libncurses5-dev libncursesw5-dev libtinfo-dev
0 upgraded, 3 newly installed, 0 to remove and 599 not upgraded.
Need to get 450 kB of archives.
After this operation, 2,642 kB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 http://us.archive.ubuntu.com/ubuntu xenial/main amd64 libtinfo-dev amd64 6.0+20160213-1ubuntu1 [77.4 kB]
Get:2 http://us.archive.ubuntu.com/ubuntu xenial/main amd64 libncurses5-dev amd64 6.0+20160213-1ubuntu1 [175 kB]
Get:3 http://us.archive.ubuntu.com/ubuntu xenial/main amd64 libncursesw5-dev amd64 6.0+20160213-1ubuntu1 [198 kB]
Fetched 450 kB in 4s (104 kB/s)
Selecting previously unselected package libtinfo-dev:amd64.
(Reading database ... 175926 files and directories currently installed.)
Preparing to unpack .../libtinfo-dev_6.0+20160213-1ubuntu1_amd64.deb ...
Unpacking libtinfo-dev:amd64 (6.0+20160213-1ubuntu1) ...
Selecting previously unselected package libncurses5-dev:amd64.
Preparing to unpack .../libncurses5-dev_6.0+20160213-1ubuntu1_amd64.deb ...
Unpacking libncurses5-dev:amd64 (6.0+20160213-1ubuntu1) ...
Selecting previously unselected package libncursesw5-dev:amd64.
Preparing to unpack .../libncursesw5-dev_6.0+20160213-1ubuntu1_amd64.deb ...
Unpacking libncursesw5-dev:amd64 (6.0+20160213-1ubuntu1) ...
Processing triggers for man-db (2.7.5-1) ...
Setting up libtinfo-dev:amd64 (6.0+20160213-1ubuntu1) ...
Setting up libncurses5-dev:amd64 (6.0+20160213-1ubuntu1) ...
Setting up libncursesw5-dev:amd64 (6.0+20160213-1ubuntu1) ..

For Fedora Linux:

If you are using Fedora 22 Linux or the newer versions, you can use the dnf command to install the ncurses library, type:

$ sudo dnf install ncurses-devel

Outputs:

[root@fedora26-osetc ~]# dnf install ncurses-devel
Last metadata expiration check: 1:36:24 ago on Fri 21 Jul 2017 09:01:19 AM EDT.
Dependencies resolved.
==================================================================================================================================================================================================
Package Arch Version Repository Size
==================================================================================================================================================================================================
Installing:
ncurses-devel x86_64 6.0-8.20170212.fc26 fedora 505 k
Installing dependencies:
ncurses-c++-libs x86_64 6.0-8.20170212.fc26 fedora 54 k

Transaction Summary
==================================================================================================================================================================================================
Install 2 Packages

Total download size: 559 k
Installed size: 930 k
Is this ok [y/N]: y
Downloading Packages:
[MIRROR] ncurses-c++-libs-6.0-8.20170212.fc26.x86_64.rpm: Curl error (60): Peer certificate cannot be authenticated with given CA certificates for https://fedora-archive.ip-connect.vn.ua/fedora/linux/releases/26/Everything/x86_64/os/Packages/n/ncurses-c++-libs-6.0-8.20170212.fc26.x86_64.rpm [Peer's Certificate has expired.]
[MIRROR] ncurses-devel-6.0-8.20170212.fc26.x86_64.rpm: Curl error (60): Peer certificate cannot be authenticated with given CA certificates for https://fedora-archive.ip-connect.vn.ua/fedora/linux/releases/26/Everything/x86_64/os/Packages/n/ncurses-devel-6.0-8.20170212.fc26.x86_64.rpm [Peer's Certificate has expired.]
(1/2): ncurses-c++-libs-6.0-8.20170212.fc26.x86_64.rpm 13 kB/s | 54 kB 00:04
(2/2): ncurses-devel-6.0-8.20170212.fc26.x86_64.rpm 59 kB/s | 505 kB 00:08
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total 55 kB/s | 559 kB 00:10
warning: /var/cache/dnf/fedora-6dbd63560daef6bf/packages/ncurses-devel-6.0-8.20170212.fc26.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID 64dab85d: NOKEY
Importing GPG key 0x64DAB85D:
Userid : "Fedora 26 Primary (26) <fedora-26-primary@fedoraproject.org>"
Fingerprint: E641 850B 77DF 4353 78D1 D7E2 812A 6B4B 64DA B85D
From : /etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-26-x86_64
Is this ok [y/N]: y
Key imported successfully
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Installing : ncurses-c++-libs-6.0-8.20170212.fc26.x86_64 1/2
Running scriptlet: ncurses-c++-libs-6.0-8.20170212.fc26.x86_64 1/2
Installing : ncurses-devel-6.0-8.20170212.fc26.x86_64 2/2
Running scriptlet: ncurses-devel-6.0-8.20170212.fc26.x86_64 2/2
Verifying : ncurses-devel-6.0-8.20170212.fc26.x86_64 1/2
Verifying : ncurses-c++-libs-6.0-8.20170212.fc26.x86_64 2/2

Installed:
ncurses-devel.x86_64 6.0-8.20170212.fc26 ncurses-c++-libs.x86_64 6.0-8.20170212.fc26

Complete!

For Arch-based Linux:

You can use the following command to install ncurses library, type:

$ sudo pacman -S ncurses

Install Ncurses Library with Source code


You can use the source code to install the latest stable version of ncurses in your Linux system, just do the following steps:

#1 Download the latest source package of ncurses from ftp://ftp.gnu.org/gnu/ncurses/

According to the ncurses release notes, the latest version of nucrses is 6.1. so type the following command to get it to local disk:

$ wget ftp://ftp.gnu.org/gnu/ncurses/ncurses-6.1.tar.gz

Outputs:

[root@osetc_test working]# wget ftp://ftp.gnu.org/gnu/ncurses/ncurses-6.1.tar.gz
--2018-11-08 07:08:11-- ftp://ftp.gnu.org/gnu/ncurses/ncurses-6.1.tar.gz
=> “ncurses-6.1.tar.gz”
Resolving ftp.gnu.org... 208.118.235.20, 2001:4830:134:3::b
Connecting to ftp.gnu.org|208.118.235.20|:21... connected.
Logging in as anonymous ... Logged in!
==> SYST ... done. ==> PWD ... done.
==> TYPE I ... done. ==> CWD (1) /gnu/ncurses ... done.
==> SIZE ncurses-6.1.tar.gz ... 3365395
==> PASV ... done. ==> RETR ncurses-6.1.tar.gz ... done.
Length: 3365395 (3.2M) (unauthoritative)

100%[===============================================================>] 3,365,395 2.64M/s in 1.2s

2018-11-08 07:08:13 (2.64 MB/s) - “ncurses-6.1.tar.gz” saved [3365395]

[root@osetc_test working]# ls
ncurses-6.1.tar.gz

#2 Extract the tar.gz source package

Type the following command:

$ tar -zxvf ncurses-6.1.tar.gz

Outputs:

[root@osetc_test working]# tar -zxvf ncurses-6.1.tar.gz
ncurses-6.1/
ncurses-6.1/panel/
ncurses-6.1/mk-0th.awk
ncurses-6.1/Makefile.in
ncurses-6.1/c++/
ncurses-6.1/misc/
ncurses-6.1/man/
ncurses-6.1/Makefile.os2
ncurses-6.1/progs/
ncurses-6.1/aclocal.m4
ncurses-6.1/dist.mk
ncurses-6.1/config.guess
ncurses-6.1/config.sub
ncurses-6.1/convert_configure.pl
ncurses-6.1/ncurses/
ncurses-6.1/announce.html.in
ncurses-6.1/mk-2nd.awk
ncurses-6.1/package/
....

#3 change directory to ncurses-6.1, and then compile and install the source code. type the following command:

$ cd ncurses-6.1
$ ./configure --prefix=/opt/ncurses
$ make
$ sudo make install

#4 Verify if the ncurses library is install in your system
Type the following command:

$ ls -la /opt/ncurses

Outputs:

[root@osetc_test ncurses-6.1]# ls -la /opt/ncurses
total 24
drwxr-xr-x 6 root root 4096 Nov 8 07:18 .
drwxr-xr-x. 4 root root 4096 Nov 8 07:17 ..
drwxr-xr-x 2 root root 4096 Nov 8 07:18 bin
drwxr-xr-x 3 root root 4096 Nov 8 07:18 include
drwxr-xr-x 2 root root 4096 Nov 8 07:18 lib
drwxr-xr-x 5 root root 4096 Nov 8 07:18 share
[root@osetc_test ncurses-6.1]#

So far, the Ncurses library has been installed on your Linux system.

Compile C Porgram that call the ncurses library


Let’s write one C program called fio.c that call the ncurses library via vi/vim text editor under the command line interface in your Linux, and append the following line:

#include <ncurses.h>
#include <stdio.h>
int main()
{
initscr();
printw("Hello World!");
refresh();
getch();
endwin();
return 0;
}

Compile this C program and then execute it, type:

$ gcc fio.c -o fio -lncurses
$ ./fio

Video: Install ncurses Library From Source

See Also: