Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Where I work someone had Java project and used Eclipse to export that project into a .war package.

Now I need to search for a string inside all the files that make that .war package. I know that a .war package is just a .zip file, and I have extracted its contents, however, now I have bunch of of .class java files (among images, xmls and other stuff) and I have no idea on how to search strings inside them.

I am a Linux Mint user, so I tried using the "grep -R stringHere ." command without success (I am not an advanced user), this command only searches inside text files.

I also searched and found the crgrep project but it is currently bugged and it does not work.

Does anyone know a linux command that can search inside all the contents of a .war package and check if those contents contain a specific string or code sample?

I really need to find a way to search through the content of the .class files. That is my only priority so far. I don't care about images nor about any other type of text files.

share|improve this question
1  
The .class files are just text files right? –  terdon Nov 19 '13 at 16:48
2  
GNU grep should search binary files by default. –  jordanm Nov 19 '13 at 16:49
    
The .class java files are not text files as far as I know. So, it means that the command "grep -R supermario ." will also search inside the .class java files? –  Flame_Phoenix Nov 19 '13 at 16:51
    
@Flame_Phoenix, it will search inside them (if it's GNU grep), but it will not output the lines that contain the strings as there's no such thing as a line in a binary file. You can use the -a option to override that, or you could use grep -rao '[[:print:]]*yourString[[:print:]]*' to output all the printable characters around yourString that are found in the file. (you should prefer -r over -R). –  Stephane Chazelas Nov 19 '13 at 17:11
add comment

1 Answer

up vote 1 down vote accepted

How about:

find /path/to/extracted/war -name '*.class' -exec strings -f "{}" +
  |grep yourString
share|improve this answer
    
If a mint grep -R doesn't find it, chances are the string is not in there. However adding -e l or -e b options to string might bring up something if the strings are UCS2 or UTF16. –  Stephane Chazelas Nov 19 '13 at 17:04
    
thanks, that worked ! –  Flame_Phoenix Nov 19 '13 at 17:05
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.