Tag Archives: command line

How to create and run a jar file

JAR (Java ARchive) is an archive file format typically used to aggregate many Java class files and associated metadata and resources (text, images and so on) into one file to distribute application software or libraries on the Java platform.

JAR files are built on the ZIP file format and have the .jar file extension. Computer users can create or extract JAR files using the jar command that comes with a JDK. They can also use zip tools to do so; however, the order of entries in the zip file headers is important when compressing, as the manifest often needs to be first.

How to create jar file
Into directory, there are at least java class files. It is important create the manifest file. Manifest file contains information about version, author, main class and other data about application created. Follow the TicTacToe example MANIFEST.MF file:
Manifest-Version: 1.0
Created-By: biliards
Main-Class: TicTacToe

Change directory where there are java class files and MANIFEST.MF file. To create jar file, edit this command line:
jar cfm TicTacToe.jar MANIFEST.MF TicTacToe*class

How to run jar file
The jar file created is runnable with follow command line:
java -jar TicTacToe.jar

JAR file manipulations
JAR file is a compress file and it is possible manipulate it in different ways:

  • view the contents of a JAR file
    jar tf TicTacToe.jar
  • extract the contents of a JAR file
    jar xf TicTacToe.jar
  • extract specific files from a JAR file
    jar xf TicTacToe.jar META-INF/MANIFEST.MF

Reference: Wikipedia, jar file and manifest file.

How to create and run a java file

Java files are source code edited by programmers from where to create executable files. An example about code structure is a sample TicTacToe game:

  1. create java file with main class (ie: TicTacToe class) and assign it the TicTacToe.java name
  2. if application is simple and uses few and simple classes, insert these class auxiliary into TicTacToe class
  3. else create one file for each class and declare each class into TicTacToe class

It is not possible run directly TicTacToe.java file. It needs to compile java file:
javac -g TicTacToe.java
and then it is possible run application recall name of main class:
java TicTacToe

This method is same if there are created one file for each class.

Reference: Wikipedia

How to change default editor

Each works well with your favorite text editor. It is important that there is a default editor known. In debian and in other linux distro, default editor is vi.

You could change default editor:

  1. during distro installation
  2. custom each user into .bashrc or .profile file with line:
    export EDITOR=/usr/bin/emacs
  3. custom locally in a shell session and/or particular program:
    env EDITOR=nano crontab -e


crontab – maintain crontab files for individual users (V3)
crontab [ -u user ] file
crontab [ -u user ] { -l | -r [ -i ] | -e }

Stamp output about crontab file:
crontab -l

Modify crontab with default editor:
crontab -e


DNS lookup utility.
dig [@server] [-b address] [-c class] [-f filename] [-k filename] [-p port#] [-t type] [-x addr] [-y name:key] [-4] [-6] [name] [type] [class] [queryopt...]
dig [-h]
dig [global-queryopt...] [query...]

dig bilardi.net


rdate – get the time via the network
rdate [-p] [-s] [-u] [-l] [-t sec] [host...]
rdate -s ntp0.cornell.edu

If you want syncronize date, then you could add this line into crontab:
* * * * 0 rdate -s ntp0.cornell.edu


useradd – create a new user or update default new user information

useradd [options] LOGIN
useradd -D
useradd -D [options]

add user jerry to groups admins, ftp, www, and developers, enter:
useradd -G admins,ftp,www,developers jerry
add a user tony to group developers use following command:
useradd -g developers tony


usermod – modify a user account

usermod [options] LOGIN
Add existing user tony to ftp supplementary/secondary group with usermod command using -a option ~ i.e. add the user to the supplemental group(s). Use only with -G option :
usermod -a -G ftp tony
Change existing user tony primary group to www:
usermod -g www tony


mytop – display MySQL server performance info like ‘top’

mytop [options]

mytop -u mysqluser -p mysqlpassword -d database

Mytop has started to break on RHEL or CentOS. It appears that some of the perl modules have change.d
There error is:
Error in option spec: "long|!"

The fix for this is to edit the mytop script and comment out the line containing long|!
nano /usr/bin/mytop
Run a search for long|! and comment out the following line:
"long|!" => \$config{long_nums},
Start mytop and you should be fine!

Reference: eth0.us


nc – TCP/IP swiss army knife

nc [-options] hostname port[s] [ports] ...
nc -l -p port [-options] [hostname] [port]

nc -l -p 2345