Showing posts with label Ubuntu. Show all posts
Showing posts with label Ubuntu. Show all posts

Sunday, March 16, 2014

Generate MD5 Sum of Multiple Files

If you want to get the MD5 sum of multiple files at once, following command can be used. This could be useful when you want to compare two set of directories/products to see the difference between them.

i.e.  You can create jarsums1.txt, jarsums2.txt and check the difference using diff command.
find . -iname "*.jar" | sort | xargs md5sum > jarsums.txt

Saturday, October 2, 2010

How to build mod_v8 in Ubuntu

mod_v8 is a simple Apache module which enable Server Side JavaScript(SSJS) support in Apache Server. It uses Google V8 engine for the JavaScript execution. What this module basically does is, it adds a Handler for a particular file extension(.v8) and then, those files are treated as SSJS files which then get executed via V8 engine.

While I was building this amazing mod_v8 module, I had to do small modification to the process. So I though it might be worth to have a post with the steps I followed.

1. Checkout V8 development branch
svn checkout http://v8.googlecode.com/svn/branches/bleeding_edge/ v8

2. Build V8 using scons with the library=shared option. Optionally you might need to add arch option too. You can find more info about it at Building V8 in Ubuntu 64 bit
scons library=shared arch=x64

3. Assuming your v8 checkout is at /home/wageesha/v8, building process will create following obj, libv8.so etc.. directories and files within v8 directory. You need to copy this libv8.so into /usr/lib.
cp ~/wageesha/v8/libv8.so /usr/lib

4. Checkout mod_v8 code
svn checkout https://svn.i-want-a-pony.com/repos/mod_v8/trunk/ mod_v8

5. Build mod_v8 using scons. Depending on your scons version, you might need to change
opts = Options('build.py') into opts = Variables('build.py')
and
opts.Add(PathOption(....)) into opts.Add(PathVariable(....))

in the SConstruct. Further, if you haven't copied libv8.so into the /usr/lib directory as in step 3, build process will fail saying
/usr/bin/ld: cannot find -lv8

6. Then open /etc/apache2/apache2.conf and add following lines, with the correct path to libmod_v8.so
LoadModule v8_module /home/wageesha/mod_v8/trunk/libmod_v8.so

<IfModule mod_v8.cpp>
#Adds the v8 handler
AddHandler v8-script .v8
</IfModule>

7. Copy /home/wageesha/mod_v8/trunk/test.v8 into /var/www folder.

8. Restart apache and access test.v8
http://localhost/test.v8

which will then print
Hello World!

in the browser.

Friday, October 1, 2010

Building V8 in Ubuntu 64 bit

If you are trying to build Google V8 in a Ubuntu 64bit machine you might get
/usr/include/gnu/stubs.h:7:27: error: gnu/stubs-32.h: No such file or directory
error when you ran scons with default arguments. When default arguments are used, it tries to guess the OS. In my case it failed to detect the correct architecture (i.e. x64). So you can specify arch argument when you run the scons to manually set the architecture. i.e.
scons arch=x64
arch argument accepts any of arm, ia32, x64 or mips

Friday, June 18, 2010

Ubuntu - Copy Everything Except

If you want to copy everything within a directory, except certain files or directories, you can use the following command.
cp -a `ls | grep -v yourexcludepattern` ../destinationdir/

Assume, you want to copy all files, except *.java within from the current directory to the foo directory. Then, the command would be,
cp -a `ls | grep -v *.java` /home/wageesha/foo

Friday, June 11, 2010

How to copy a file into multiple directories in Ubuntu

Assume that you want to copy a file into multiple directories in the current directory, then all you have to do is, just entering following command in the terminal. Here, file.txt will be copied into all directories in the current directory. In case of a directory coping, replace file.txt with -rf [your dir].
for dir in *; do [ -d "$dir" ] && cp file.txt "$dir" ; done
for dir in *; do [ -d "$dir" ] && cp -rf /home/wageesha/images "$dir" ; done

Sunday, August 30, 2009

Find and Replace using grep and sed

Following command finds all the occurences of <br> in all .xml files in the current directory, and replace those <br> with <br/> . Please note that < and > have been surrounded with [ and ] in the sed command. / in the <br/> tag has been escaped using \. If you want to replace foo with bar, then you can just use those words.
find . -iname "*.xml" | xargs grep -l "<br>" | xargs sed -i -e 's/[<]br[>]/<br\/>/g'
find . -iname "*.xml" | xargs grep -l "<br>" | xargs sed -i -e 's/foo/bar/g'
A more general form of the expression would be
find . \( -name "*.php" -or -name "*.html" \) | xargs grep -l 'TEXT TO SEARCH' | xargs sed -i -e 's/TEXT TO REPLACE/REPLACEMENT STRING/g'

Thursday, August 27, 2009

Rename Files with find command in linux

If you want to rename files recusivelly using linux find command, here are two example usage of it with exec and xargs. This command will convert all the *.xml files into *.html files.

Using xags
find . | xargs rename 's/\.xml$/\.html/i'
Using exec
find . -exec rename 's/\.xml$/\.html/i' {} +
Above commands recurrsively replace files within inner directories too. If you want to do it for current directory only you can use -prune.
i.e
find . -prune | xargs rename 's/\.xml$/\.html/i'
find . -prune -exec rename 's/\.xml$/\.html/i' {} +

Thursday, June 25, 2009

find command - search content of a file

find in Unix is a very powerful tool for users which give you a very good flexibility. find command has a very broad usage among users. Here is the way how you can use find command to search files and content within files.

In order to search for a particular file named "test.txt" in /home directory, use
find /home -name "test.txt" -print
Search all the .txt files in /home directory, use
find /home -name "*.txt" -print
if you want to search for a string through all the files .txt files, there are two ways
find /home -name "*.txt" -exec grep -q "string-to-be-searched" '{}' \; -print
find /home -name "*.txt" | xargs grep "string-to-be-searched"
second one is more fast and efficient. Removal of -q in the first command will output the text segment where the specified string is. If you want to search all files for the string, just remove -name "*txt" option.