Command Line

Command Line Tools

How to convert a number from decimal/octal to hexa-decimal format using bc command

The “bc” command provides an arbitrary precision calculator language. The bc command can be used to evaluate mathematical expressions in the non-interface method as well as interactive method.

A typical interactive usage of bc command to evaluate a mathematical expression “100+200″ is as follows. The output from bc command is highlighted below.

[neo@techpulp ~]# bc
bc 1.06
Copyright 1991-1994, 1997, 1998, 2000 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'.
100+200
300
[neo@techpulp ~]#

A simple non-interactive way of using bash command to evaluate same expression is as follows.

[neo@techpulp ~]# echo "100+200" | bc
300
[neo@techpulp More >

How to disable colored display by ls command in Linux

Sometimes it is annoying to look at the colored display of output by ls command. This is more evident if you use a dark color as background color of the terminal. In such cases, you can use alternative command ‘dir’ to see non-colored output. However it is difficult for one to change the commonly-used command easily. In such case, you can run the following command to make ls command to display non-colored output.

[neo@techpulp ~]# unalias ls

However the above command affect only your current shell. If you want to make this permanent, you can place the command towards the end of More >

How to print date and time in different time zone using command line in Linux

The command “date” is used to display current date and time in Linux systems. The date command displays date and time in configured time zone in the system. The file /etc/localtime contains information about currently selected time zone. This file is copied from /usr/share/zoneinfo directory during system installation.

[neo@techpulp ~]# file /etc/localtime
/etc/localtime: timezone data
[neo@techpulp ~]#

If you want to change the current default time zone of the system, you should copy relevant file from /usr/share/zoneinfo directory to /etc/localtime file.

If you want to just display current date and time in a time zone other than default time zone, you need to set the More >

How to execute a command with in VI

You can use “:!” sequence followed by the command string in the command mode of VI.The following steps explain the procedure.

Type Esc to enter in to VI command mode

Type colon (:) and (!) followed by actual command string.

For example, if you want to run “ls” command, you would need to type “:!ls” in VI.