Archive for the 'command-line kung-fu' Category

16
Aug
09

copy a file with a progressbar


If you ever wanted a copy command with a progress bar, you can have this alternative :


pv file > destination

and this will show you a progress bar.

02
Jun
09

how to run a java project written in eclipse from the command line


I wanted to run a large java project from the command line. I knew I had to add the jar dependencies as parameters to the java binary, but I wasn’t sure how to do that. After a bit of googling around , I found out how to achieve this. Here’s a skeleton :

java -classpath lib1.jar;lib2.jar package.otherpackage.classname argv1 argv2 ... argvn

If you have your .class files in a folder, let’s name it classes, then you need to add that folder to the classpath, so the skeleton becomes :

java -classpath classes;lib1.jar ...

I hope you get the picture. If you don’t know what jars to include, but your project works in eclipse, you can open the .classpath file and extract the entries with kind=”lib”. Here is a sample .classpath file from a project :


<?xml version="1.0" encoding="UTF-8"?>
<classpath>
	<classpathentry kind="src" path="src"/>
	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
	<classpathentry kind="lib" path="lib/commons-codec-1.3.jar"/>
	<classpathentry kind="lib" path="lib/commons-collections-3.2.1.jar"/>
	<classpathentry kind="lib" path="lib/commons-httpclient-3.1.jar"/>
	<classpathentry kind="lib" path="lib/commons-io-1.4.jar"/>
	<classpathentry kind="lib" path="lib/commons-lang-2.4.jar"/>
	<classpathentry kind="lib" path="lib/commons-logging-1.1.1.jar"/>
	<classpathentry kind="lib" path="lib/cssparser-0.9.5.jar"/>
	<classpathentry kind="lib" path="lib/htmlunit-2.5.jar"/>
	<classpathentry kind="lib" path="lib/htmlunit-core-js-2.5.jar"/>
	<classpathentry kind="lib" path="lib/javax.servlet.jar"/>
	<classpathentry kind="lib" path="lib/nekohtml-1.9.12.jar"/>
	<classpathentry kind="lib" path="lib/sac-1.3.jar"/>
	<classpathentry kind="lib" path="lib/serializer-2.7.1.jar"/>
	<classpathentry kind="lib" path="lib/xalan-2.7.1.jar"/>
	<classpathentry kind="lib" path="lib/xercesImpl-2.8.1.jar"/>
	<classpathentry kind="lib" path="lib/xml-apis-1.3.04.jar"/>
	<classpathentry kind="output" path="bin"/>
</classpath>

You can easily parse this file and extract them. I’ve used it today to create a rake task that operates on a java project written in eclipse.

Hope this helps someone.

16
Feb
09

ubuntu post-installation trouble

Until about an hour ago , my operating system was Zenwalk 5.2 . I liked it at first , but then things started to go wrong . As I installed some packages ( with netpkg ) , other apps ( that worked ) , just stopped working . I don’t know , maybe it’s something I did wrong .

Anyway , I had configured global hotkeys/shortcuts for amarok , specifically alt and up arrow to increase amarok’s volume , and alt and down arrow to decrease the volume . Everytime I used those hotkeys , the system just froze . I was using XFCE as my environment .

So , because I had enough reboots already , I decided to go back to ubuntu ( specifically xubuntu ) . I decided to keep my partitions just the way they were . I downloaded an iso , and I burned it . The installation went ok , but after I restarted and booted into ubuntu , errors started to pop-up . KDE said something about a session error , then Gnome said about the same thing , and then I was taken to something that looked like xterm.

I thinked about this , and this is what I think the problem was :

  • Zenwalk must have left some configuration files left on my /home partition

So , I thought , if I remove those , I should be greeted with something like an “instalation succesful” screen . Or at least something like that . After executing ls -al , a lot of hidden files and directories popped up . So , because my bash kung-fu sucks , I wrote a script that would remove all the hidden files and folders from /home :


require "find"

Find.find("/home/your_user") do |file|
  if(file =~/\/\./)
    system("rm -rf \"#{file}\"")
  end
end

It turns out, I was right ! After the script finished , I rebooted and everything worked . Maybe this will help you if you turn up in the same situation .




Blog Stats

  • 215,219 hits