Hide

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again.

Delete that bloated snippets file you've been using and share your personal repository with the world. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.


If you have a new feature suggestion or find a bug, please get in touch via http://commandlinefu.uservoice.com/

Get involved!

You can sign-in using OpenID credentials, or register a traditional username and password.

First-time OpenID users will be automatically assigned a username which can be changed after signing in.

Hide

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for:

Hide

News

2011-03-12 - Confoo 2011 presentation
Slides are available from the commandlinefu presentation at Confoo 2011: http://presentations.codeinthehole.com/confoo2011/
2011-01-04 - Moderation now required for new commands
To try and put and end to the spamming, new commands require moderation before they will appear on the site.
2010-12-27 - Apologies for not banning the trolls sooner
Have been away from the interwebs over Christmas. Will be more vigilant henceforth.
2010-09-24 - OAuth and pagination problems fixed
Apologies for the delay in getting Twitter's OAuth supported. Annoying pagination gremlin also fixed.
Hide

Tags

Hide

Functions

Commands tagged java from sorted by
Terminal - Commands tagged java - 20 results
output=$(ps -ef|grep -i java 2>/dev/null); for w in ${output[@]}; do if [[ $w =~ .*Xmx.* ]]; then result=$(grep -oP "[0-9]+" <<< $w); echo $result ;fi ; done| awk 'BEGIN {sum=0} {for(i=1; i<=NF; i++) sum+=$i } END {print sum}'
2013-08-13 14:04:17
User: massiverobot
Functions: awk echo grep ps
Tags: java jvm xmx
0

This will find all the -Xmx[BIGINT] running on a system, add them up for you and give you the total.

find /usr/include/ -name '*.[c|h]pp' -o -name '*.[ch]' -print0 | xargs -0 cat | grep -v "^ *$" | grep -v "^ *//" | grep -v "^ */\*.*\*/" | wc -l
2013-06-17 08:37:37
Functions: cat find grep wc xargs
0

Count your source and header file's line numbers. This ignores blank lines, C++ style comments, single line C style comments.

This will not ignore blank lines with tabs or multiline C style comments.

grep -l 'flags.*\<lm\>' /proc/cpuinfo && (getconf LONG_BIT | grep '64') && java -version
2012-12-17 16:39:55
Functions: getconf grep
Tags: java 32bit 64bit
0

Let's you examine, for example, whether infrastructure folks really provisioned the correct setup.

Java 64-bit checklist

1. check if hardware is 64-bit capable by looking for lm flag

grep -l 'flags.*\<lm\>' /proc/cpuinfo

2. check if kernel is 64-bit

getconf LONG_BIT | grep '64'

3. check if java is 64-bit (simply look for 64-bit in output - if present, then it is, if absent, then it is 32-bit)

java -version
java -jar app.jar -cp $(echo lib/*.jar | tr ' ' ':')
2012-10-29 12:51:46
User: xymor
Functions: echo tr
Tags: java cli
0

Lauching an app including jars in an adjacent lib folder to its classpath

ack --java '\\u.?.?.?[^0-9a-fA-F]'
egrep "([_a-zA-Z][_a-zA-Z0-9]*) *= *\1 *[*/+-] *[0-9]+ *;"
2012-04-09 12:42:07
User: aandre
Functions: egrep
0

Search for java explicit incrementation in order to replace it with postfix or assignment operator

find . -iname '*.zip' | while read file; do unzip -l "$file" | grep -q [internal file name] && echo $file; done
2012-03-23 18:08:35
User: ricardofunke
Functions: echo file find grep read
1

This command find which of your zip (or jar) files (when you have lots of them) contains a file you're searching for. It's useful when you have a lot of zip (or jar) files and need to know in which of them the file is archived.

It's most common with .jar files when you have to know which of the .jar files contains the java class you need.

To find in jar files, you must change "zip" to "jar" in the "find" command. The [internal file name] must be changed to the file name you're searching that is archived into one of the zip/jar files.

Before run this command you must step into the directory that contains the zip or jar files.

find /usr/include/ -name '*.[c|h]pp' -o -name '*.[ch]' -print0 | xargs -0 wc -l | tail -1
find /usr/include/ -name '*.[c|h]pp' -o -name '*.[ch]' -exec cat {} \;|wc -l
2011-12-01 19:58:52
User: kerim
Functions: cat find wc
-4

Count your source and header file's line numbers

For example for java change the command like this

find . -name '*.java' -exec cat {} \;|wc -l

find . -iname pom.xml -type f -exec bash -c "cat {} | sed s/1\.0\.46\-SNAPSHOT/1\.0\.48\-SNAPSHOT/g > {}.tmp " \; -exec mv {}.tmp {} \;
2011-10-05 18:57:12
User: miguelbaldi
Functions: bash find mv
0

When a large maven release goes wrong, by deploying just some of the artifacts letting others behind, some projects got wrong SNAPSHOT versions. This command comes to help!

Tip: replace sed's regex by your version numbers

find src/ -name "*.java" | while read f; do echo -n "$f "; cat "$f" | tr -dc '{}'; echo; done | awk '{ print length($2), $1 }' | sort -n
sudo update-alternatives --config java
2011-03-07 23:43:52
User: mccalni
Functions: sudo
Tags: java
1

You have openjdk and sun java installed. Many of your java plugins will not work properly. Something called IcedTea (the java web plugin) keeps crashing. Run this and select sun java to use sun java.

find -name "*.<suffix>" -exec wc -l "{}" \; | sort -n | tail
2010-06-29 05:53:43
User: cooper
Functions: find sort wc
Tags: wc source java line
0

Find the source file which contains most number of lines in your workspace

:)

kill -3 PID
2010-04-28 08:22:42
User: mrbyte
Functions: kill
Tags: kill java
0

Useful command to get information about running java process and treads, to see log look into the default log for your java application

unpack.sh -domain=[PATH]/domains/mydomain -template=[PATH]/mydomain.jar
pack.sh -domain=[PATH]/domains/mydomain -template=[PATH]/mydomain.jar -template_name="mydomain"
ps uH p <PID_OF_U_PROCESS> | wc -l
2010-03-23 15:05:27
User: mrbyte
Functions: ps wc
Tags: java ps
1

if you have problem threads problem in tomcat

img test.jpg
2009-08-11 22:09:21
User: Inouire
Tags: bash java picture
2

This command allows you to see a preview of a picture via the terminal. It can be usefull when you are ssh'ing your server without X-forwarding.

To have en example of the output you can get with this command see http://www.vimeo.com/3721117

Download at http://inouire.net/image-couleur.html

Sources here: http://inouire.net/archives/image-couleur_source.tar.gz

find . -name "*.jar" | while read file; do echo "Processing ${file}"; jar -tvf $file | grep "Foo.class"; done
mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id> -DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging> -DgeneratePom=true
2009-03-20 16:29:08
User: virtualshock
Tags: maven java
0

If you have a JAR that is not in a central Maven repository this will add it to your repository.