Linux Ask!

Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.

Linux Ask!

Feb 292012
 

How to get the hostname of a local machine using Java

Answer:

The following codes illtsraeted how to get the hostname of the local machine using Java.

import java.net.InetAddress;

public class Test {

    public static void main(String[] args) {

        try {
            InetAddress addr = InetAddress.getLocalHost();

            // Get hostname
            String hostName = addr.getHostName();

            System.out.println(hostName);

        } catch (Exception e) {}
    }
}
Feb 152012
 

Sending email using raw SMTP commands

Answer:

You can send email(s) by connecting to your SMTP server, and using raw SMTP commands.

E.g. assume your SMTP is localhost, listening port 25, enter the commands in bold

# telnet localhost 25
Trying 127.0.0.1...
Connected to localhost.localdomain.
Escape character is '^]'.
220 smtp.example.com ESMTP Postfix (Ubuntu)
helo localhost
250 smtp.example.com
mail from: [email protected]
250 2.1.0 Ok
rcpt to: [email protected]
250 2.1.5 Ok
data
354 End data with .
This is a test mail
.

250 2.0.0 Ok: queued as BA2FD1DB96
quit
221 2.0.0 Bye
Connection closed by foreign host.

Feb 042012
 

Remove un-staged files or directories from Git repository

Answer:

To remove newly added files or directories under a Git repository (but un-staged yet), do:

# git clean -fdn

Check if the files/directories are really okay to remove. Then, execute the command again without the '-n'

# git clean -fd