Neo
This user hasn't shared any biographical information
Posts by Neo
How to rename multiple files by pattern or wildcard in Linux
Oct 28th
Linux provides a command “rename” to help rename files using patterns. If you don’t see the rename command in your system, you can run the following command to install it under Fedora/RHEL Linux.
[root@techpulp ~]# yum install -y util-linux-ng
The following shows the syntax of rename command.
rename <from> <to> <files> from - source pattern to - destination pattern files - list of files to operate on
The following command renames all files with .htm extension to .html extension.
[neo@techpulp ~]# rename .htm .html *.htm
The following command renames all files with .jpeg extension to .jpg extension.
[neo@techpulp ~]# rename .jpeg .jpg *.jpeg
The following command searches recursively More >
How to understand IPv6 address and types
Oct 22nd
IPv6 uses 16 bytes (128 bits) to represent and IP address as opposed to 4 bytes (32 bits) in IPv4. IPv6 uses colon separated hexa-decimal notation as opposed to dotted-decimal notation in IPv4.With 128-bit long IP address size, IPv6 can provide 2^128 addresses. In a simple decimal notation, it takes up to 39 digits making it harder to memorize. To make it relatively convenient, an IPv6 address is represented by a series of 16 bit hexa-decimal values separated by colons. An example IPv6 address is as follows.
2001:0da3:02f0:d413:4e39:7b9a:e2cd:08a2
The leading zeros can be omitted for simplicity. The above IPv6 address looks like More >
What is IPv6 and why is it needed
Oct 21st
The Internet as we use today uses IPv4 as layer 3 protocol as packet delivery mechanism. IPv4 stands for Internet Protocol version 4 which was designed back in 1980. As the Internet usage grew exponentially during the last decade, the number of free IP addresses for new allocations reduced rapidly. According to current estimates, the number of free IP addresses fallen below 5% and expected to become zero by first quarter of 2011. The IPv4 protocol uses 32 bit (4 byte) addresses limiting the possible IP address space to 2^32 (4 billion). To solve this IP address exhaustion problem. Internet More >
How to reboot a Linux system remotely using ssh or telnet
Oct 12th
You can simply login to the remote system using SSH and execute “reboot” command to reboot it. But you must be logged in “root” user to be able to reboot the remote Linux system.
This example shows how to login using IP address.
[root@neo.techpulp.com ~]# ssh root@192.168.123.55
This example shows how to login using remote host name.
[root@neo.techpulp.com ~]# ssh root@www.techpulp.com
Typically after a successful login, you will get access to shell. You can run “reboot” command to reboot the remote system. This action will automatically terminate you current SSH session.
Otherwise, you use the following example to do the job with single command.
[root@neo.techpulp.com ~]# ssh More >
How to start or stop or restart a service in Fedora/RHEL/Ubuntu/Debian Linux
Oct 11th
The following examples show how to start or stop or restart a service in different flavours of Linux. In all these examples, the service name “httpd” is used. You can replace it with name of the service you want to start or stop or restart.
Starting a serviceIn RHEL or Fedora:
[root@techpulp ~]# service httpd start
or
[root@techpulp ~]# /etc/init.d/httpd start
In Debian Linux:
[root@techpulp ~]# /etc/init.d/httpd start
In Ubuntu Linux:
[root@techpulp ~]# sudo /etc/init.d/httpd startStopping a service
In RHEL or Fedora:
[root@techpulp ~]# service httpd stop
or
[root@techpulp ~]# /etc/init.d/httpd stop
In Debian Linux:
[root@techpulp ~]# /etc/init.d/httpd stop
In Ubuntu Linux:
[root@techpulp ~]# sudo /etc/init.d/httpd stopRestarting a service
In RHEL or Fedora:
[root@techpulp ~]# service httpd restart
or
[root@techpulp More >
How to change/set/reset MySQL root password using mysqladmin
Oct 10th
After installing MySQL service, administrator should set a reasonably strong password using mysqladmin utility. In MySQL, user name of administrator is “root”. To change/set/reset password, you need to run two commands. The following shows the syntax of the commands.
[root@techpulp ~]# mysqladmin -u root password NEWPASSWORD [root@techpulp ~]# mysqladmin -u root -h HOSTNAME password NEWPASSWORD
The following commands show example usage.
[root@techpulp ~]# mysqladmin -u root password y5FxEtrh [root@techpulp ~]# mysqladmin -u root -h localhost password y5FxEtrh
As the commands you executed are stored in history file (~/.bash_history), you can avoid it by running following command before running mysqladmin utility.
[neo@techpulp ~]# echo $HISTFILE /home/neo/.bash_history More >
How to make a BSD socket non-blocking – EWOULDBLOCK
Oct 5th
Sometimes it is needed to make a socket non-blocking so that I/O requests on the socket don’t block. For a non-blocking socket, when I/O requests like read() and write() return a negative value, the errno should be checked against -EWOULDBLOCK code to find if the I/O request would have blocked.
The following utility function sets non-blocking flag of a socket.
int socketSetNonBlocking(int sockfd)
{
unsigned int flags;
flags = fcntl(sockfd. F_GETFL, 0);
if(flags < 0) return -1;
if(fcntl(sockfd, F_SETFL, flags|O_NONBLOCK) < 0) return -1;
return 0;
}
Similarly the following function makes a non-blocking socket a blocking socket.
int socketSetBlocking(int sockfd)
{
unsigned int More > How to find IP address of an interface using bash scripting
Oct 1st
In Linux, ifconfig command is used to view the information about network interfaces. Let us examine the output of the command to determine how we can parse the information for IP address.
[neo@techpulp ~]# ifconfig eth0 eth0 Link encap:Ethernet HWaddr 03:A6:2E:52:3D:BA inet addr:66.27.16.64 Bcast:66.27.16.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:14257 errors:0 dropped:0 overruns:0 frame:0 TX packets:4364 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:4831053 (4.6 MiB) TX bytes:663388 (647.8 KiB) Interrupt:21 Base address:0x2000 [neo@techpulp ~]#
The IP address information is present in second line containing keyword “inet addr”. The following script accepts an interface name as command line argument More >
How to extract extension from a file name in bash
Sep 29th
The following trick can be used to extract file extension from a name.
[neo@techpulp ~]# MYFILE=filename1.txt
[neo@techpulp ~]# echo $MYFILE
filename1.txt
[neo@techpulp ~]# echo ${MYFILE##*.}
txt
[neo@techpulp ~]#
Let us try the same on a file name with full path.
[neo@techpulp ~]# MYFILE=/home/neo/filename1.txt
[neo@techpulp ~]# echo ${MYFILE##*.}
txt
[neo@techpulp ~]#
How to scan a host for open ports in Linux
Sep 23rd
It is better to scan the server once to detect any unwanted services. It helps in harden the security of the server and minimizes security threats. Linux provides a command nc command to scan the open ports on a host. Typically it comes with default installation. If not, you can use following command to install it.
yum -y install nc
To scan a host with IP address “172.16.5.20″ for ports ranging from 1 to 1023, use the following command.
[neo@techpulp ~]# nc -z 172.16.5.20 1-1023 Connection to 172.16.5.20 80 port [tcp/http] succeeded! Connection to 172.16.5.20 443 port [tcp/ssh] succeeded! Connection to 172.16.5.20 904 More >


Recent Comments