Monthly Archives: December 2011

Tutorial on Find command

 

Find command are useful command in linux which help you to find and search certain file or folder in your server, here is few tutorial that might help you for better understanding it.

·Find all world writable directories:

find / -perm -0002 -type d  –print

·Find all world writable files:

find / -perm -0002 -type f  -print
find / -perm -2 ! -type l  -ls

·Find files with no user:

find / -nouser -o -nogroup  –print

·Find files modified in the last two days:

find / -mtime 2 -o -ctime 2

·Search and list all files from current directory and down for the string ABC:

find ./ -name "*" -exec grep -H ABC {}  ;
find ./ -type f -print | xargs grep -H  "ABC" /dev/null
egrep -r ABC *

·Find all files of a given type from current directory on down:

find ./ -name "*.conf"  –print

·Find all user files larger than 5Mb:

find /home -size +5000000c  –print

·Find all files owned by a user (defined by user id number) on
the system: (could take a long time)

find / -user 501 –print

·Find all files created or updated in the last five minutes: (Great for finding effects of make install)

find / -cmin -5

Batch Image Resizing on linux

Batch Image Resizing on linux

Assume that you have more than 1000 image in a directory, and you are going to resize them all with higher resolution to match
your new web site design. Here is hassle free method that you can try using ImageMagick and use its tools called “mogrify“. On centos you can install imagemagick via yum by typing the following command:

yum install ImageMagick

then you can resize the image inside folder using follwing command:

mogrify -resize 320 *.jpg

all the image size will be resize to 320px

 

Hope that help, cheers~

Fix: perl(URI) >= 1.17 is needed by subversion

When you installing subversion on server you might found following problem:

error: Failed dependencies:
        perl(URI) >= 1.17 is needed by subversion-1.6.6-1.el5.rfx.x86_64

Here is the solution to fix:

wget http://yum.trixbox.org/centos/5/RPMS/perl-URI-1.35-3.noarch.rpm
rpm -i perl-URI-1.35-3.noarch.rpm

then proceed to subversion installation.

Cheers

Verify if .htaccess is working or not

We use .htaccess to rewrite and redirect link. When you get your new hosting its always there is easy step to verify if .htaccess is working fine or not on your new hosting account. Some hosting does not configure their apache server correctly and caused .htaccess is not working even the code itself is correct. So, Here is simple step that might useful for you to verify if the .htaccess is work or not working. (with these instruction, make sure you have root access to your server)

First of all you will need to check if mod_rewrite is enabled for apache.

cat /etc/httpd/conf/httpd.conf | grep rewrite

make sure you see result below:
LoadModule rewrite_module modules/mod_rewrite.so
if you dont see above line, then you will need to add it. If yes you can proceed to 2nd step

make sure AllowOverride inside httpd.conf is set to All instead of none by default.
example show on below:

    Options FollowSymLinks
    AllowOverride none

change to :

    Options FollowSymLinks
    AllowOverride All

Dont forget to restart apache after making change to AllowOverride. /var/www/html is example of mine, you can replace it to your directory example: /home/user/public_html

What next? Test it!!

Open notepad and copy and paste the following code into it:

 

<?php // htaccess tester // Copyright 2011 Booser if($_GET['url']==1){echo "Damn it! looks like htaccess is not working, please refer to: Booser Verify Htaccess for solution";} elseif($_GET['url']==2){echo" YES!! Your .htaccess is work fine man!";} else{echo"Linux Apache mod_rewrte Test Tutorial";} ?>

 

LINK1 = rewrite.php?link=1

LINK2 = link2.html

Click on Link1 and Link2, they both are same file, if you clicked link2 not work or get 404 mean its not working you will need to refer Booser Verify htaccess for solution

If you like Booser, you can copy this code and paste it to your website. Verify if .htaccess is working or not

Save it as: rewrite.php
Next step is open a new notepad again and paste following into it:

RewriteEngine On
RewriteRule ^my-rewite-link([^/]*).html$ rewrite.php?url=$1 [L]

Save it as: .htaccess

Now upload both files to your server using ftp, so that you can access it from url:

http://www.yourcoolsite.com/rewrite.php

click on Link1 and Link2 to test them out.

If you get:

404 error its mean, you dont have mod_rewite installed correctly or allowOveride is none.
500 internal error mean that you have some problem with .htaccess files make sure you copy them correctly.

You can contact your hosting to check if you not sure what you are going to do, or drop me a message on contact page, i would happily to check it for you.

Hope that help.
~Cheers~