By ANTHONIRAJ on April 28th, 2010
You have 100 photos which was captured by using your 5 MP digital camera.Each Image has occupied 4 MB in your memory card and also You want to upload all the files into picasa or facebook or an other social networking sites. But the maximum image uploading size is 1 MB in those websites. So it is very difficult to reduce the size of each and every photo using some photo editing softwares. In this situation you can use the following shell script to convert or compress more than one images. Let us assume, the photos are available in /home/photos folder.
# cd /home/photos
# vim compress.sh
1
2
3
4
| for img in `ls *.JPG`
do
convert -quality 40% $img my-$img
done |
or
Simply copy the script and paste into your image folder. and run the script in your terminal
# chmod 777 compress.sh
# ./compress.sh
This script will reduce the size of image into approximately 300 KB .
Reference : IBM Website
By ANTHONIRAJ on April 28th, 2010
1. cp command
This command is used for copying folders and files from source to destination.
Copying Files
# cd /home/anthoniraj/uploads/
# cp kavidhai.pdf /opt/ [copy the file kavithai.pdf into /opt folder]
# cp kavidhai.pdf sam.txt /opt/ [copy the files kavithai.pdf and sam.txt into /opt folder ]
Copying Folders
# cp -r uploads/ /opt/ [Copy the folder uploads and its content into /opt folder]
2. rm command – delete files and folders
# cd /opt/uploads
# rm kavidhai.pdf [Delete kavithai.pdf from uploads folder ]
# cd ..
# rm -r uploads/ [Delete the folder uploads/ and its content from /opt]
By ANTHONIRAJ on April 24th, 2010
Running C and C++ applications in Linux is entirely different from Windows TurboC++ users. Linux uses GCC [Gnu Compiler Collections - C and C++ compiler] for developing these applications . Let us see how to develop C and C++ applications in Linux .
Checking GCC compiler
GCC comes with all Linux flavors by default . To check the version of your GCC , type this command in your terminal
root@Ubuntu:/home/anthoniraj# gcc –version
gcc (Ubuntu 4.4.1-4ubuntu9) 4.4.1
Copyright (C) 2009 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
By default only C compiler will be there in GCC , you can install C++ support by typing this command in Ubuntu
#sudo apt-get install build-essential
Developing C Program
You can use your favorite editor or IDE like Netbeans or Eclipse to develop the C and C++ programs. I am using VIM the simple and king of all editor for developing these programs. Now simply we can write one C program for finding factorial of a given number.
#vim factorial.c [ file type is .c ]
#include<stdio.h>
int main()
{
int n , i ;
unsigned long int res = 1;
printf("\nEnter the number to find the factorial:");
scanf("%d" , &n );
for(i = 1 ; i <= n ; i++)
{
res *= i;
}
printf("\n The factorial value of %d is %lu\n" , n, res);
return 0;
}
Compiling and Running
To compile c program , use gcc with file name
#gcc factorial.c
#./a.out [Default buffer for output]
Enter the number to find the factorial: 5
The factorial value of 5 is 120
or
#gcc factorial.c -o fact.out
#./fact.out [customized file for output]
Note :
- There is no void keyword in GCC ,
- Use int instead of void and also use return 0 .
Developing C++ Program
Now I am going to write C++ for the same factorial method.
#vim factorial.cpp [File Type is cpp]
#include <iostream>
using namespace std;
int main()
{
int n ;
unsigned long int res = 1;
cout << "\nEnter the number to find the factorial:" << endl;
cin << n ;
for(int i= 1 ; i <= n ; i++)
{
res *= i;
}
cout <<"The factorial value of " <<"is " << endl;
return 0;
}
Compiling and Running
To compile c program , use gcc with file name
#g++ factorial.cpp
#./a.out [Default buffer for output]
Enter the number to find the factorial: 5
The factorial value of 5 is 120
or
#g++ factorial.cpp -o fact.out
#./fact.out [customized file for output]
Note :
- Dont use .h for header files
- Use name space for header-file functions
By admin on April 21st, 2010
What is Email?
Email,short for electronic mail and often abbreviated to email,email or simply mail, is a store and forward method of composing,sending, receiving and storing messages over electronic communication systems.
Applications or Use
1.The Hotmail service was founded by Sabeer Bhatia and Jack Smith ,and was one of the first webmail services on the Internet. It was commercially launched on July 4, 1996, American Independence Day.
2. It was sold at 1997 to Microsoft for a reported $400 million, and it joined the MSN group of services
3.Yahoo! Mail (Started at 1996) is a Web based email (webmail) service from Yahoo!. It is the most used email on the Internet,serving over 260 million users.
4. Gmail, officially Google Mail is a free Web based email (webmail), POP3 and IMAP email service provided b Google. On April 1, 2004 the product began as an invitation only
beta release. On February 7, 2007 the beta version was opened to the general public.
Technology Used In Email
The format of Internet email messages is defined in RFC 2822 and a series of RFCs, RFC 2045 through RFC 2049, collectively called Multipurpose Internet Mail Extensions (MIME).
Internet email messages consist of two major sections:
-
Header — Structured into fields such as summary, sender, receiver, and other information about the email
-
Body — The message itself as unstructured text; sometimes containing a signature block at the end The header is separated from the body by a blank line.
Header
The message header consists of fields, usually including at least the following:
-
From: The email address, and optionally the name of the sender
-
To: The email address[es], and optionally name[s] of the message’s recipient[s]
-
Subject: A brief summary of the contents of the message
-
Date: The local time and date when the message was written Other common header fields include (see RFC 4021 or RFC 2076 for more).
-
Cc: carbon copy
-
Bcc: Blind Carbon Copy
-
Received: Tracking information generated by mail servers that have previously handled a message
-
ContentType: Information about how the message has to be displayed, usually a MIME type
-
ReplyTo: Address that should be used to reply to the sender.
-
References: MessageID of the message that this is a reply to, and the messageid of this message, etc.
-
InReplyTo: MessageID of the message that this is a reply to.
-
XFace: Small icon.
By admin on April 21st, 2010
Plain Text and HTML
Both plain text and HTML are used to convey email. Advantages of HTML include the ability to include inline links and images, set apart previous messages in block quotes, wrap naturally on any display, use emphasis such as underlines and italics, and change font styles.
Sendmail Configuration in php.ini file
# vim /opt/lampstack/php/etc/php.ini
[mail function]
; For Win32 only.
SMTP = localhost
smtp_port = 25
; For Win32 only.
sendmail_from = antony@gmail.com
; For Unix only. You may supply arguments as well (default: “sendmail –t -i”).
sendmail_path = sendmain –t -i
Simple Example
<php
$to = 'amalantonyraj@yahoo.co.in';
$subject = 'From PHP';
$message = 'Test';
if(mail($to, $subject, $message)) {
echo "Mail has been sent successfully";
}
else {
echo "Server error";
}
?>
Mail Function in PHP
Syntax
bool mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )
Parameters
to
Receiver, or receivers of the mail. The formatting of this string must comply with » RFC 2822. Some examples are:
* user@example.com
* user@example.com, anotheruser@example.com
* User <user@example.com>
* User <user@example.com>, Another User
<anotheruser@example.com>
subject
Subject of the email to be sent.
Caution
This must not contain any newline characters, or the mail may not be sent properly.
message
Message to be sent Each line should be separated with a LF (\n). Lines should not be larger than 70 characters.
additional_headers (optional)
String to be inserted at the end of the email header. This is typically used to add extra headers (From, Cc, and Bcc). Multiple extra headers should be separated with a CRLF (\r\n). additional_parameters (optional)
sending mail using the sendmail_path configuration setting. For example, this can be used to set the envelope sender address when using sendmail with the f sendmail option.
For Emailing with attchment and extra headers . please refer this link
http://pradeepkumar.org/2009/09/sending-email-in-php.html
By ANTHONIRAJ on April 19th, 2010
Friends,
Try the following code in truboc and devc++ editor (gcc compiler).
int i=5;
printf("%d",i++ - i++ - --i - i--);
and
int i=5,n;
n=i++ - i++ - --i - i--;
printf("%d",n);
As we expect, the answer should be same.
But it is different in both the compilers…..Why??? Please let me know if you knew this.
By ANTHONIRAJ on April 8th, 2010
ls – List Directories and Files
ls command will display the files and folders of current working directory. You can use some options to utilize this command effectively.
1. Display files and folders
anthoniraj@Ubuntu:~/sample$ ls
sam.txt uploads users.csv users.txt
2. Display the file and folder with privileges , ownership , and size
anthoniraj@Ubuntu:~/sample$ ls -l
total 16
-rw-r–r– 1 anthoniraj anthoniraj 5 2010-04-08 06:49 sam.txt
drwxrwxrwx 2 anthoniraj anthoniraj 4096 2010-03-26 08:49 uploads
-rw-r–r– 1 anthoniraj anthoniraj 140 2010-04-07 10:33 users.csv
-rw-r–r– 1 anthoniraj anthoniraj 145 2010-04-07 10:32 users.txt
3. Display all files including hidden files
anthoniraj@Ubuntu:~/sample$ ls -a
. .. sam.txt uploads users.csv users.txt

ls command output
4. Display the folder content recursively
anthoniraj@Ubuntu:~/sample$ ls -R
.:
sam.txt uploads users.csv users.txt
./uploads:
cs1999.pdf kavidhai.pdf New Text Document.txt Sample.txt
5. Display the inode or index number of each file
anthoniraj@Ubuntu:~/sample$ ls -i
331894 sam.txt 336568 uploads 331901 users.csv 331902 users.txt
By ANTHONIRAJ on April 5th, 2010
apropos
Each manual page has short description available within it, apropos command will search the command short description with the given keyword. This command is same as man -k option. but the advantage of apropos is using regular expression for searching the commands.
Example
#apropos “print”

apropos Sample Output Page
#apropos -r “^[p]+[g]$”
pg (1) – browse pagewise through text files
This pattern will match the command description word starting with “p” and ends with “g”. Like this user can create your own pattern for finding commands.
cd – Change Directory
cd command is used for changing the current directoy to some destination directory which you want to use. First you need to find which directory currently you are using, for that you can use “pwd – present working directory” command.
Examples
anthoniraj@Ubuntu:~$ pwd
/home/anthoniraj
I am using home directory , here anthoniraj is the user of the system. Now i want to change home directory to “/opt”
anthoniraj@Ubuntu:~$ cd /opt/
anthoniraj@Ubuntu:/opt$
You can also use dot (.) for changing directory
anthoniraj@Ubuntu:/opt$ cd ..
anthoniraj@Ubuntu:/$ pwd
/
[/ - root directory]
By ANTHONIRAJ on April 3rd, 2010
One of the powerful feature of Linux Shell is the help page for commands. all commands comes with the manual page so that it can be easily understood by user.For accessing help or syntax details about any command in Linux , simply get into the terminal and type
# man command-name
This will display the information like name , syntax , description , example , author of the particular command. User can also use some options like “-f” for short description and “-k” for displaying commands based on the keyword.
Regular Usgae
1. Displaying Manual or Help Page
#man find

Manual Page for Find Command
2. Getting Short Description
#man -f ifconfig

Short Description of ifconfig
3.Getting List of commands using Keyword
If you want to know about the commands for network operations , you do not know all the Linux networking commands , In this situaltion “man -k” option will help you. Type the keyword “network” with option “-k” in man command , it will display all the commands matching the keyword like network.
#man -k “network”

List of Network Commands
4. Converting Manual Page into Portable Format [ Text , PDF , PS ]
The default format of the man pages are in troff [ Text Formatting System]. We can convert troff format to text pdf or ps format using man with following options
i) For Text File conversion
# man ls | col -b > lstext.txt
ii) For PDF or PS conversion
#man -t ls > lsps.ps
#man -t ls | ps2pdf – > lstext.pdf