Command Line
Command Line Tools
How to convert a number from decimal/octal to hexa-decimal format using bc command
Nov 25th
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
Nov 13th
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
Oct 29th
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 redirect standard error to standard output in bash shell
Sep 30th
Any UNIX process, by default, will have three file I/O streams open. Each opened file of the UNIX process is denoted with a number called file number. The default opened three files streams are called stdin, stdout and sterr. Their file numbers are 0, 1 and 2 respectively. Of these stdin stands for standard input and meant for reading input from user or from another file. The stdout stands for standard output and any messages printed by the process get written to this file. Typically this file is console, so the user can use the messages printed by the process. More >
How to safely remove a file that contains sensitive data in Linux
Apr 16th
Typically a file removal operation, in Linux or any other operating system, doesn’t actually erase all contents of the file. Though the file is logically deleted and doesn’t appear to the be present, its contents still present in the hard drive. Any raw disk reading software or a data recovery tools can detect such contents to gain access to sensitive information such as passwords, credit card numbers etc.
Let us assume that you have stored your passwords and credit card numbers in a plain text file, even once temporarily. It is always wise to overwrite the file contents many a times More >
How to create a patch file in Linux using diff command
Mar 13th
Patch files describe the differences between two versions of same project and it is the favourite way of exchanging differences among developers. Patch files come in handy when the project is huge and exchanging whole source code is not so convenient. If you observe the download section of open source projects like Linux kernel, you will find patches for other versions based on a base version. That means if I had already downloaded sources of 2.6.0 version kernel sources and if I want 2.6.1 sources, I would rather download the patch file instead of downloading whole 2.6.1 source code.
Any Linux More >
How to kill a process in Unix/Linux
Mar 4th
There are multiple commands supported in UNIX/Linux to kill a process. The most-used command is “kill” command which expects PID of the process which can be retrieved from the output of “ps” command.
To kill a process named httpd, first search for the process in the output of “ps” command and use the PID to kill it.
[neo@techpulp ~]# ps -e | grep kcalc 3482 ? 00:00:00 kcalc [neo@techpulp ~]# kill 3482 [neo@techpulp ~]# ps -e | grep kcalc [neo@techpulp ~]#
If the process is not killed using the above command and if you want to terminate the process for sure, you can use “kill -9″ which More >
How to use “diff” utility effectively
Mar 4th
The command line tool “diff” helps you find differences between two files or directories. It also can report the differences between two directories including all files and sub directories recursively.
Compute differences between two files:
[neo@techpulp ~]# diff animals1.txt animals2.txt 4a5 > crane 8,9d8 < tiger < panda 16c15 < lion --- > lion roars [neo@techpulp ~]#
Whatever starts with “<” is the change in first file and whatever starts with “>” is the change in second file.
Compute differences between two files but ignore white spaces and blank lines:
[neo@techpulp ~]# diff -b -B animals1.txt animals2.txt
Compute differences between two directories:
[neo@techpulp ~]# diff dir1 dir2
Compute More >
How to find if two binary files differ or not
Mar 4th
The standard “diff” command can be used to find if two binary files differ from each other or not. The following example shows how to do it.
[neo@techpulp ~]# diff file1.bin file2.bin Binary files file1.bin and file2.bin differ [neo@techpulp ~]#
Another way to find that out is to compute MD5 digest on both files and see if they match. MD5 is an cryptographic algorithm which computes an unique digest for each file. The both files are same if the MD5 digests of both files match and otherwise they differ. The “md5sum” command can be used to compute MD5 digest.
[neo@techpulp ~]# md5sum file1.bin file2.bin 4714b62a51a4057fa73a1ded36b75143 More >
How to execute a command with in VI
Feb 28th
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.


Recent Comments