Saturday, July 9, 2016

Solve java.net.BindException: Address already in use error messages

Ssh into the instance and check the port that is causing issues:

netstat -pan | grep ":4503 "

You should get exact pid of the process and status:

In this case the program is still busy in CLOSE_WAIT.
CLOSE_WAIT means your program is still running, and has not closed the socket.

You can get the java pid number and kill the program to clear the socket.

Friday, July 8, 2016

Linux RedHat 6.5 - Add Welcome Message when SSH log in

Message of the Day - Edit the below file and add your message here.

vi /etc/motd 

If Not working you can check that under sshd_config PrintMotd is set to yes

cat /etc/ssh/sshd_config | grep Print
PrintMotd yes


Next time you login to the instance, you get the defined welcome message:

Wednesday, June 3, 2015

Upload files to Amazon EC2 Linux instance

scp -i myAmazonKey.pem file.zip ec2-user@mec2-50-17-16-67.compute-1.amazonaws.com:~/.

Saturday, April 4, 2015

Useful Linux/Unix commands

List files from current folder:
ls -l

Get current shell:
echo $SHELL

Get present working directory:
pwd

Get content from Home directory:
ls ~

List files from current directory:
ls .

Navigate to home directory:
cd

Navigate to root folder:
cd /

Find out file type:
file [path]

Navigate to a "two words" folder:
cd word1\ word2
cd 'word1 word2'

Hidden file name example:
.hiddenfile

List all files(including hidden):
ls -a

Manual page for a certain command:
man <command>
man -k <search term>

Chain parameters example for listing all files and add kilo, bytes to size:
ls -alh

Create a new directory:
mkdir learning

Create a new directory with parameter to display the action and parameter to create all directories if needed:
mkdir -pv dir1/dir2

Remove empty directory:
rmdir dir

Create new empty file:
touch filename

Copy a directory (including subfolders and files) to a new one:
cp -r dir1 dir2

Copy a file:
cp filesrc filedest

Move a directory (including subfolders and files) to a new one:
mv dir1 dir2

Rename file and directory:
mv filedir filedirnew

Remove a file:
rm filename

Remove non-empty folder:
rm -r folder

Interactive remove a folder or file:
rm -i file

Edit file with vi:
vi filename

Enter insert mode vi:
i

Enter edit mode from insert mode vi:
ESC

Save and exit from vi:
ZZ
:wq

Save vi changes, but don't exit:
:w

Discard changes and exit:
:q!

View file using different command than vi:
cat filename

View large files:
less filename
Note: b - previous page; Space - next page; q - quit;

Add numbers to vi lines editing:
:set nu

Navigating file in vi, edit mode:
Arrow keys - move the cursor around
j, k, h, l - move the cursor down, up, left and right (similar to the arrow keys)
^ - move cursor to beginning of current line
$ - move cursor to end of the current line
nG - move to the nth line (eg 5G moves to 5th line)
G - move to the last line
w - move to the beginning of the next word
nw - move forward n word (eg 2w moves two words forwards)
b - move to the beginning of the previous word
nb - move back n word
{ - move backward one paragraph
} - move forward one paragraph

Delete commands in vi, edit mode:

x - delete a single character
nx - delete n characters (eg 5x deletes five characters)
dd - delete the current line
dn - d followed by a movement command. Delete to where the movement command would have taken you. (eg d5w means delete 5 words)

Undo changes in vi, edit mode:

u

Copy/Cut-Paste vi:

Position the cursor where you want to begin cutting.
Press v to select characters (or uppercase V to select whole lines).
Move the cursor to the end of what you want to cut.
Press d to cut (or y to copy).
Move to where you would like to paste.
Press P to paste before the cursor, or p to paste after.

Wildcards:
* - Zero character or many of characters
? - Just one character
[] - Range of characters