Friday, November 18, 2016

How to kill a process on a port on ubuntu

Sometimes, when we strying to up an service and get message like: the port *** is used by another service. And we are notable to start our app to use that port. In that case, we are in need to free the port by stopping the running process. For this purpose a first we need to find out the process which is using that port.

By using the below query we can get the process id using this port:

sudo lsof -t -i:8080 [For this case 8080 is our reference port number]

to get the process in details, we can use:
ps -ef | grep


And then we can kill the process by :
kill -9

We can use the below command at once to kill the process:
sudo kill $(sudo lsof -t -i:8080)

Thursday, November 17, 2016

Sheel Script for Deleting files older than some days

find is the common tool for this kind of task :

find ./target_dir ! -name 'stayhere.txt' -mtime +5 -type f -delete


EXPLANATIONS

./target_dir your directory (replace with your own)
! -name File to exclude
-mtime +5 older than 5 days
-type f only files
-delete no surprise. Remove it to test your find filter before executing the whole command
And take care that ./target_dir exists to avoid bad surprises !

Tuesday, November 15, 2016

TODO in Ecplise IDE

in Eclipse, no TODO shortcut found; but a possible solution is to create a template so when you write some string and hit Ctrl + spacebar and Enter your TODO code will be entered.
Window -> Preferences -> Java -> Editor -> Templates -> New
  • Set the Name of the template (e.g. todo)
  • Set the Pattern (e.g. //TODO)
When you type todo and press Ctrl + spacebar and Enter // TODO will be inserted
Such a trivial todo is useless but you can tweak it by using variables as shown in the picture. Use "Insert Variable" button to insert variables.
enter image description here
When you use the pattern shown in the picture following will be inserted:
// TODO inserted by UserName [21. 1. 2015, 13:07:07]