Tuesday, October 13, 2009
What does the alphabets on the left of aptitude search command output mean?
However here is the excerpt:::
Unless you pass the -F option, the output of aptitude search will look something like this:
i apt - Advanced front-end for dpkg
pi apt-build - frontend to apt to build, optimize and in
cp apt-file - APT package searching utility -- command-
ihA raptor-utils - Raptor RDF Parser utilities
Each search result is listed on a separate line. The first character of each line indicates the current state
of the package: the most common states are p, meaning that no trace of the package exists on the system, c,
meaning that the package was deleted but its configuration files remain on the system, i, meaning that the
package is installed, and v, meaning that the package is virtual. The second character indicates the stored
action (if any; otherwise a blank space is displayed) to be performed on the package, with the most common
actions being i, meaning that the package will be installed, d, meaning that the package will be deleted, and
p, meaning that the package and its configuration files will be removed. If the third character is A, the
package was automatically installed.
For a complete list of the possible state and action flags, see the section “Accessing Package Information” in
the aptitude reference guide. To customize the output of search, see the command-line options -F and --sort.
Monday, October 12, 2009
Single, Master and Slave Drives and Jumpering
Courtsey: http://www.pcguide.com/ref/hdd/if/ide/confJumpering-c.html
Why I came across the below article?
When I was trying to install Ubuntu 9.10 (Karmic Koala) beta release installation on my system, I faced a peculiar problem. When I connected the CD Drive and my IDE HDD on a single IDE channel, BIOS was not detecting any of the hardware. However when connected individually, BIOS was able to detect both drives. I first felt that the IDE channel was not working and hence changed it and tried it again but again the same problem. Then I also changed the CPU and tried it on some other CPU thinking that my BIOS might have some problem( ya ya I am an idiot but sometimes inexpirience is very costly, however most people learn only the hard way). Then I finally gave up and asked my senior about it and that is when I found about the problem of master and slave and understood that it was a simple matter of changing the jumper and configuring one as master and other as slave. Anyways I now hope that nobody in future will find that dificulty and hopefully this whole article(along with the article from pcguide )will be useful.
Each IDE/ATA channel can support either one or two devices. IDE/ATA devices of course each contain their own integrated controllers, and so in order to maintain order on the channel, it is necessary to have some way of differentiating between the two devices. This is done by giving each device a designation as either master or slave, and then having the controller address commands and data to either one or the other. The drive that is the target of the command responds to it, and the other one ignores the command, remaining silent.
Note that despite the hierarchical-sounding names of "master" and "slave", the master drive does not have any special status compared to the slave one; they are really equals in most respects. The slave drive doesn't rely on the master drive for its operation or anything like that, despite the names (which are poorly-chosen--in the standards the master is usually just "drive 0" and the slave "drive 1"). The only practical difference between master and slave is that the PC considers the master "first" and the slave "second" in general terms. For example, DOS/Windows will assign drive letters to the master drive before the slave drive. If you have a master and slave on the primary IDE channel and each has only one regular, primary partition, the master will be "C:" and the slave "D:". This means that the master drive (on the primary channel) is the one that is booted, and not the slave.
Devices are designated as master or slave using jumpers, small connectors that fit over pairs of pins to program the drive through hardware. Each manufacturer uses a different combination of jumpers for specifying whether its drive is master or slave on the channel, though they are all similar. Some manufacturers put this information right on the top label of the drive itself, while many do not; it sometimes takes some hunting around to find where the jumper pins are on the drive even once you know how the jumpers are supposed to go. The manufacturers are better about this now than they have been in the past, and jumpering information is always available in the manual of the hard disk, or by checking the manufacturer's web site and searching for the model number. I describe (and illustrate) the jumpers on IDE/ATA disks in detail in the section on hard disk construction. For a fundamental description of what jumpers are, see here.
ATAPI devices such as optical, Zip and tape drives are jumpered in pretty much the same way as hard disks. They have the advantage of often having their jumpers much more clearly labeled than their hard disk counterparts. Most optical drives, for example, have three jumper blocks at the back, labeled "MA" (master), "SL" (slave) or "CS" (cable select).
If you are using two drives on a channel, it is important to ensure that they are jumpered correctly. Making both drives the master, or both the slave, will likely result in a very confused system. Note that in terms of configuration, it makes no difference which connector on the standard IDE cable is used in a standard IDE setup, because it is the jumpers that control master and slave, not the cable. This does not apply when cable select is being used, however. Also, there can be electrical signaling issues if one connects a single drive to only the middle connector on a cable, leaving the end connector unattached. In particular, the use of Ultra DMA is not supported in such a configuration; see the discussion of the 80-conductor Ultra DMA cable for more information.
As long as one drive is jumpered as master and the other as slave, any two IDE/ATA/ATAPI devices should work together on a single channel. Unfortunately, some older hard disks will fail to work properly when they are placed on a channel with another manufacturer's disk. One of the reasons why drives don't always "play nicely together" has to do with the Drive Active / Signal Present (/DASP) signal. This is an IDE/ATA interface signal carried on pin #39, which is used for two functions: indicating that a drive is active (during operation), and also indicating that a slave drive is present on the channel (at startup). Some early drives don't handle this signal properly, a residue of poor adherence to ATA standards many years ago. If an older slave drive won't work with a newer master, see if your master drive has an "SP" (slave present) jumper, and if so, enable it. This may allow the slave drive to be detected.
Drive compatibility problems can be extremely frustrating, and beyond the suggestion above, there usually is no solution, other than separating the drives onto different channels. Sometimes brand X won't work as a slave when brand Y is the master, but X will work as a master when Y is the slave! Modern drives adhere to the formal ATA standards and so as time goes on and more of these older "problem" drives fall out of the market, making all of this less and less of a concern. Any hard disk bought in the last five years should work just fine with any other of the same vintage or newer.
When using only a single drive on a channel, there are some considerations to be aware of. Some hard disks have only a jumper for master or slave; when the drive is being used solo on a channel it should be set to master. Other manufacturers, notably Western Digital, actually have three settings for their drives: master, slave, and single. The last setting is intended for use when the drive is alone on the channel. This type of disk should be set to single, and not master, when being used alone.
Also, a single device on an IDE channel "officially" should not be jumpered as a slave. In practice, this will often work despite being formally "illegal". Many ATAPI drives come jumpered by default as slave--because they are often made slaves to a hard disk's master on the primary IDE channel, this saves setup time. However, for performance reasons they are sometimes put on the secondary channel, and often the system assemblers don't bother to change the jumpers. It will work, but I don't recommend it; if nothing more, it's confusing to find a slave with no master when you or someone else goes back into the box a year or two later to upgrade.
For performance reasons, it is better to avoid mixing slower and faster devices on the same channel. If you are going to share a channel between a hard disk and an ATAPI device, it is generally a good idea to make the hard disk the master. In some situations there can be problems slaving a hard disk to an optical drive; it will usually work but it is non-standard, and since there is no advantage to making the ATAPI device the master, the configuration is best avoided.
There are many more performance considerations to take into account when deciding how to jumper your IDE devices, if you are using several different ones on more than one channel. Since only one of the master and slave can use any channel at a time, there are sometimes advantages to using more than one IDE/ATA channel even if not strictly necessary based on the number of devices you are trying to support. There can also be issues with using a drive that has support for a fast transfer mode like Ultra DMA with older devices that don't support these faster modes.Monday, October 5, 2009
import mysql query into csv
SELECT a,b,a+b INTO OUTFILE '/tmp/result.text'
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\n'
FROM test_table;
LDAP LDAP LDAP
To run a LDAP server, you need to install slapd package.
To do various work on LDAP, you need libldap and ldap-utils package.
While installing you are asked for a DN, which will be the main path for your LDAP server. IT is something similar to domain names, and the DN that you specify will be the name of the root of your LDAP directory. You will have to access the LDAP server using the DN.
Configuration::
the configuration of the slapd is stored in slapd.conf. This is a good document about slapd configuration file, http://www.openldap.org/doc/admin24/slapdconfig.html
Adding data::
Data can be added in the LDAP server using ldapadd and ldapmodify commands. You can either store the different data in a file and then supply the file as an argument to the ldapadd command or directly specify the data in ldapadd command.
Need to improve this post many times any folds.
Sunday, October 4, 2009
Understanding software installation in linux, configure, make, make install
Each software comes with a few files which are solely for the purpose of installation sake. One of them is the configure script. The user has to run the following command at the prompt
$ ./configure
The above command makes the shell run the script named ' configure ' which exists in the current directory. The configure script basically consists of many lines which are used to check some details about the machine on which the software is going to be installed. This script checks for lots of dependencies on your system. For the particular software to work properly, it may be requiring a lot of things to be existing on your machine already. When you run the configure script you would see a lot of output on the screen , each being some sort of question and a respective yes/no as the reply. If any of the major requirements are missing on your system, the configure script would exit and you cannot proceed with the installation, until you get those required things.
The main job of the configure script is to create a ' Makefile ' . This is a very important file for the installation process. Depending on the results of the tests (checks) that the configure script performed it would write down the various steps that need to be taken (while compiling the software) in the file named Makefile.
If you get no errors and the configure script runs successfully (if there is any error the last few lines of the output would glaringly be stating the error) then you can proceed with the next command which is
$ make
' make ' is actually a utility which exists on almost all Unix systems. For make utility to work it requires a file named Makefile in the same directory in which you run make. As we have seen the configure script's main job was to create a file named Makefile to be used with make utility. (Sometimes the Makefile is named as makefile also)
make would use the directions present in the Makefile and proceed with the installation. The Makefile indicates the sequence, that Linux must follow to build various components / sub-programs of your software. The sequence depends on the way the software is designed as well as many other factors.
The Makefile actually has a lot of labels (sort of names for different sections). Hence depending on what needs to be done the control would be passed to the different sections within the Makefile Or it is possible that at the end of one of the section there is a command to go to some next section.
Basically the make utility compiles all your program code and creates the executables. For particular section of the program to complete might require some other part of the code already ready, this is what the Makefile does. It sets the sequence for the events so that your program does not complain about missing dependencies.
One of the labels present in the Makefile happens to be named ' install ' .
If make ran successfully then you are almost done with the installation. Only the last step remains which is
$ make install
As indicated before make uses the file named Makefile in the same directory. When you run make without any parameters, the instruction in the Makefile begin executing from the start and as per the rules defined within the Makefile (particular sections of the code may execute after one another..thats why labels are used..to jump from one section to another). But when you run make with install as the parameter, the make utility searches for a label named install within the Makefile, and executes only that section of the Makefile.
The install section happens to be only a part where the executables and other required files created during the last step (i.e. make) are copied into the required final directories on your machine. E.g. the executable that the user runs may be copied to the /usr/local/bin so that all users are able to run the software. Similarly all the other files are also copied to the standard directories in Linux. Remember that when you ran make, all the executables were created in the temporary directory where you had unzipped your original tarball. So when you run make install, these executables are copied to the final directories.
Thats it !! Now the installation process must be clear to you. You surely will feel more at home when you begin your next software installation.
how to download an ftp link from browser
I was in my friend's laptop and ssh-ed in my system. Now i wanted to download a tar file from internet to my system. The link mentioned was a ftp link. When i tried to use wget, I got a permissioned denied error. So I was left with 2 options, either to download it in my friend's lappy and then scp it into my system or download it using link2 console WWW browser. I chose the later even though it was my first time to try that.
First after starting links2 in console, using links2 command, we need to open the link where the download link is present. For that, the shortcut-key to get address bar is "g". (Note that I first tried to directly open the ftp link assuming that it would directly download the file, but instead I came to know that links2 actaully tries to open that as a page and hence file does not get downloaded, hence no use). Now after you have entered the web-page, go to the download link. Now you can download the file by using the shorcut-key "d". It gives you an option to rename the file that is being downloaded. After you have given it a suitable name, you are ready to download it. Note that the file is downloaded in the present working directory(the directory from where you executed the links2 command).
Also let me mention here that "esc" is the key to get the toolbar in links2 browser.
Thursday, October 1, 2009
difference between helo and ehlo
features.
An advanced mailserver will send "EHLO ..." -- if the remote mailserver
doesn't accept EHLO, then it will revert to HELO (which all mailservers
understand).
Wednesday, September 30, 2009
SMTP numeric codes
These three-digit coded responses, like 220, may look familiar to Webmasters. The first digit indicates success or failure. 1 indicates a success requiring confirmation, 2 indicates complete success, and 3 indicates success so far, but that more input is expected. 4, the first failure code, is used for failures that may be temporary, such as the mail account existing but being locked; 5 indicates that the failure condition is permanent, such as a syntax error in the command. The second and third digits provide further details, but at the top level, all that matters is that 1xx, 2xx, and 3xx are good, and 4xx and 5xx indicate problems. (For further information on mail response codes, read RFC 1893.)
Wednesday, September 23, 2009
how to repair a mysql table using myisamchk
myisamchk is an table-maintainence utility. It is used to repair corrupted mysql tables.
First, try myisamchk -r -q tbl_name (-r -q means “quick recovery mode”). This attempts to repair the index file without touching the data file. If the data file contains everything that it should and the delete links point at the correct locations within the data file, this should work, and the table is fixed. Start repairing the next table. Otherwise, use the following procedure:
1.
Make a backup of the data file before continuing.
2.
Use myisamchk -r tbl_name (-r means “recovery mode”). This removes incorrect rows and deleted rows from the data file and reconstructs the index file.
3.
If the preceding step fails, use myisamchk --safe-recover tbl_name. Safe recovery mode uses an old recovery method that handles a few cases that regular recovery mode does not (but is slower).
Courtsey: http://dev.mysql.com/doc/refman/5.1/en/repair.html
Monday, September 21, 2009
how to login into screen by default
Now you would like to login into screen by default so that you dont have enter the screen command every time you start a new bash. For this all you have to do is enter a line
screen -x || screen
in your .bashrc or .bash_profile file in your home directory.
.bashrc is executed every time you start a console. So adding the above line in .bashrc file executes the above line every time .bash is started. above line just checks if there is already a screen opened on the system. If it is opened, it connects to that or else it starts a new screen.
Wednesday, September 9, 2009
using routes.rb to change the default home page in redmine
I have copied the chat here so that I dont miss anything that was pointed out by him(Also I am too lazy to write it all again).
iggy_prabhu> hi friends
viggy_prabhu> I have installed redmine and added one of my projects
viggy_prabhu> now i want that whenever i open the redmine domain, it directly opens the home page of the project and not the home page
viggy_prabhu> Can I do this by route.rb file or should I use rewrite mod in apache to do this
viggy_prabhu> ?
relaxdiego> viggy_prabhu: try modifying the map.home entry in routes.rb
viggy_prabhu> relaxdiego, any good HOWTO before I start modifying it?
* jas4711_ has quit ("Ex-Chat")
relaxdiego> none that I know of
relaxdiego> map.home '', :controller => 'projects', :project_id => (your project's id)
relaxdiego> try that
relaxdiego> and for Rails routing: http://api.rubyonrails.org/classes/ActionController/Routing.html
viggy_prabhu> relaxdiego, i have done the necessary changes
viggy_prabhu> should I restart my apache?
relaxdiego> yep
viggy_prabhu> i did it and got the changes
viggy_prabhu> but i want projects/show/myproject to appear instead of the list of projects
viggy_prabhu> (at present I have only one project)
viggy_prabhu> relaxdiego, hope you got my doubt?
relaxdiego> what's your project's id?
relaxdiego> map.home '', :controller => 'projects', :action => 'show', :project_id => (your project's id)
* kibaho1 (n=pelamm@gw.tietoteema.fi) has joined #redmine
viggy_prabhu> relaxdiego, "The page you were trying to access doesn't exist or has been removed" i am getting this error now
viggy_prabhu> map.home '', :controller => 'projects', :action => 'show', :project_id => 'myproject'
relaxdiego> sorry, i think i got it wrong
relaxdiego> this works for me --> map.home '', :controller => 'projects', :action => 'show', :id => (project id)
viggy_prabhu> relaxdiego, finally it is working
viggy_prabhu> relaxdiego, thanks a lot for your time :)
relaxdiego> np :)
Wednesday, September 2, 2009
how to make qmail accept mails for any specifc domains
Tuesday, September 1, 2009
This is how you talk to yourself on IRC :)
viggy_prabhu I am trying to configure apache2 to run redmine
viggy_prabhu I have followed the steps that were given on the site
viggy_prabhu but I am getting the "Internal Server Erro"
viggy_prabhu Error*
viggy_prabhu I am new to apache2 and Ruby on rails, so I might have done some mistake in configuration
viggy_prabhu the problem I dont know how to check that?
viggy_prabhu can anyone help me
viggy_prabhu ?
* kardan| (n=kardan@p54BE393E.dip.t-dialin.net) has joined #redmine
viggy_prabhu I got the following error in my apache2 error log file "apache2: Could not reliably determine the server's fully qualified domain name"
viggy_prabhu "[Tue Sep 01 20:31:28 2009] [alert] [client 127.0.0.1] /var/www/redmine/public/.htaccess: Invalid command 'RewriteEngine', perhaps misspelled or defined by a module not included in the server configuration"
viggy_prabhu can anybody help me
* hobodave (n=hobodave@63.149.16.13) has joined #redmine
* hobodave has quit (Remote closed the connection)
* hobodave (n=hobodave@63.149.16.13) has joined #redmine
viggy_prabhu Got the solution
viggy_prabhu I just had to enable the rewrite module in apache2
Saturday, August 29, 2009
installing mysql bindings for ruby
To install mysql bindings for ruby, use this command
#gem install mysql
You might get the following error:
"extconf.rb:1:in `require': no such file to load -- mkmf (LoadError)"
This probably means that you forgot to install the ruby1.8-dev package. Just do an apt-get install ruby1.8-dev to fix this.
"Could not create Makefile due to some reason [..] Check the mkmf.log file for more details. [..]"
You should do what the error message tells you: check the mkmf.log! Search for this file using find /usr/lib/ruby/gems/1.8/gems/. Usually, this error message appears because you forgot to install the -dev package for the extension you were trying to install. So if you wanted to install the mysql gem, you probably forgot to install the libmysqlclient14-dev first. Do an apt-cache search to find the appropriate packages.
Courtsey: Simon Josefsson Datakonsult
RAILS_ENV=”production”
(in /home/redmine/redmine)
rake aborted!
No such file or directory - /tmp/mysql.sock
(See full trace by running task with –trace)
The problem is that you need the Ruby MySQL wrappers. This isn’t really clear from the error message. Install it using:
# apt-get install libmysql-ruby
Monday, August 24, 2009
wget to rescue
Everyone must have known wget's feature to download a partially downloaded file. Well you will be shocked to know that wget can download the partially downloaded file even if it was downloaded using Firefox.
Firefox downloaded usually downloads the file in .part. So all you have to do is rename the .part file to the actual file name.
Then run the command:
wget -c "link of the server from which it was downloading"
Thats it and wget will resume your download as if your internet connection was not lost at all.
Sunday, August 16, 2009
After windows reinstallation, Linux no longer boots!, How do I restore GRUB?, I have lost my GRUB, how do I find it again?, I have reinstalled Windows
Courtsey: Thinkdigit forum.
1. Boot from a Live CD, like Ubuntu Live CD or similar.
2. Open a Terminal. Go SuperUser (that is, type "su"). Enter root passwords as necessary. (in kanotix you need to set the passwd for root yourself. Use:
$ passwd root
3. Type "grub" which makes a GRUB prompt appear.
4. Type "find /boot/grub/stage1". You'll get a response like "(hd0)" or in my case "(hd0,3)". Use whatever your computer spits out for the following lines.
5. Type "root (hd0,3)".
6. Type "setup (hd0,3)". This is key. Other instructions say to use "(hd0)", and that's fine if you want to write GRUB to the MBR. If you want to write it to your linux root partition, then you want the number after the comma, such as "(hd0,3)".
7. Type "quit".
8. Restart the system. Remove the bootable CD.
Source: http://ubuntuforums.org/showthread.php?t=42030
If the Step 3 doesn't work, then instead of typing "su" and then "grub" type "sudo grub". Then continue with Step 4.
Also if GRUB was your main boot loader then use (hd0) in Step 6, otherwise (hd0,x), where 'x' is your Linux Boot Partition (in case you are using some other boot loader, like Vista's Boot Loader for e.g.).
But if you dont have a LIVE CD, then SUPERGRUB is a perfect solution. I have not used it myself, so cant give any good review about it. However you can find more details for your solution here.
Saturday, August 15, 2009
Check List of essential features of websites for small businesses
1) Basic:
- Thier Location
- Their Hours of Operation
- Contact Information
- Business of the company
- Profiles of founder and other importent staff of the company.
4) Portfolio: Examples of ongoing projects or previous commitments
5) NEWS Room: Articles and Accolades
6) Links: Other presence of the company on the web
7) Photo Gallery:
8) Calendar: To inform about the upcoming events
9) Blog:
10) Contact:
11) Send to Friend & share:
12) Printer Friendly Pages:
13) Email Signup:
14) E-commerce:
15) Donations:
Thursday, July 30, 2009
Customizing Terminator using terminator_config
- The default font size was very small and I had to increase it to 4 times its size to get a normal font.
- The colour of text was #AAAAAA, which was very dull.
All you need to do is edit the config file of terminator which can generally be found in "${XDG_CONFIG_HOME}/terminator/config" (usually "~/.config/terminator/config"). If this file does not exist, create it. Then you just need to add the options that you need for your Terminator. You can find the list of options from the man page of terminator_config
$man terminator_config
So I went through the man page and edited my terminator_config file. Here is what my terminator config file looked after editing.
font = Mono 14
use_theme_colors = false
background_color = black
background_darkness = 0.0
foreground_color = #00FF00
copy_on_selection = true
focus = sloppy
enable_real_transparency = true
So finally my Terminator looked normal and now I dont have any problems using it. Though I still have to do lots of customization like adding a background image.
?
Monday, July 27, 2009
Customizing VIM
Vim is an editor designed to work like that most venerable of UNIX editors, vi. Vim doesn't just clone vi; it extends vi with features like multi-level undo, a graphical interface (if you want it), windows, block operations, on-line help and syntax coloring.
Along with the new features, Vim 5.5 (the current version as I write) has 196 options you can set. Practically any behavior you might have found obnoxious in plain vi can be configured to your liking in Vim. To download or get more information on Vim, see the Vim home page at http://www.vim.org/. Within Vim, you can view the on-line help at any time by pressing ESC, typing :help and pressing ENTER.
I'll admit that the thought of trudging through 196 options on the off chance that one or two will do what I want might seem a bit daunting, so here are several of my favorite Vim customizations just to get you started. These customizations have saved me much frustration and helped make a regular Vim user out of me.
Before I talk about specific Vim customizations, however, let me explain how to save your customizations so they are loaded each time you start Vim. When you first start using Vim, it will be 100% compatible with vi. You won't notice any of Vim's fancy features until you activate them.
This behavior is nice: it allows system administrators to replace /bin/vi with a link to Vim without their users rising up against them screaming, “vi is broken. Fix it!” In fact, some people have used Vim for years this way without realizing they were using anything fancier than vi. But strict vi emulation can confuse people who expect to see all of Vim's bells and whistles right from the start.
Luckily, it's easy to convince Vim that we know we're actually in Vim and not in vi. Vim customizations are stored in a file called .vimrc in your home directory. If Vim sees that you have a .vimrc file—even if that file is empty—Vim will turn off vi-compatibility mode, which will configure Vim as Vim, rather than vi.
If you don't have a .vimrc file, but you do have an .exrc file that you have used to customize your vi sessions in the past, execute the command
mv ~/.exrc ~/.vimrc
to rename your .exrc file to .vimrc.
If you have neither a .exrc file nor a .vimrc file, execute the command
touch ~/.vimrc
to create an empty .vimrc file.
You're now ready to begin configuring Vim in earnest. You can add commands to your .vimrc file in the same way you would add them to your .exrc file. That is, if you tried Vim's incremental searching feature (which I'll describe shortly) by pressing the ESC key and entering the command
:set incsearch
and decided you wanted to make incremental searching the default behavior for future Vim sessions, you could do it by putting the line
set incsearchinto your .vimrc file on a line by itself. Note the lack of a leading colon.
Suppose you have the following text file to edit:
In Xanadu did Kubla Khan
A stately pleasure-dome decree:
Where Alph, the sacred river, ran
Through caverns measureless to man
Down to a sunless sea.
Your cursor is on the I in the first line. You need to get to the first occurrence of the word “measureless”. How do you do it?
One way is to press / to put Vim into search mode, type in “measureless”, and press ENTER. Vim will find the first “measureless” after the current cursor position and leave your cursor on the m. Easy, in principle, that is. I'm not such a great typist. When I try to search forward for the word “measureless”, I'm just as likely to misspell it as not. And if I misspell it as “measurless”, I won't realize my mistake until I press ENTER and Vim returns “Pattern not found: measurless”.
I could increase my chances of typing the search pattern correctly by searching for a substring of “measureless”. For example, if I search for “measu”, I have fewer characters to type, which means fewer ways I can mistype my search pattern. However, that means I have to guess how many characters will specify a unique substring of the word I want to find. If I don't type in enough for my search pattern, I'll end up in the wrong location. For example, if search for “me”, I'll end up in “pleasure-dome” on line two rather than where I want to be, which is on line four. I'd then have to search again by pressing n.
Vim's incremental search feature can help with both of these problems. To try it out, press the ESC key to enter command mode, then type
:set incsearch
and press ENTER.
Incremental searching means that as you enter your search pattern, Vim will show you the next match as you type each letter. So when you start your search for “measureless” by pressing m, Vim will immediately search forward for the first m in the file following the current cursor position. In this case, it's the m in “pleasure-dome” on line two. Vim will then highlight in the text the pattern it has matched so far for you. Since “pleasure-dome” isn't where you wanted to go, you need to type more letters in your search pattern. When you press e, “pleasure-dome” still matches the substring me, so Vim will highlight the “me” in “pleasure-dome” and wait for more input. When you press a, “pleasure-dome” no longer matches the substring mea, so Vim will highlight the next match for mea, which is “measureless” on line four. Jackpot! Since that's the word you are looking for, press ENTER, and Vim will leave your cursor on the m in “measureless”.
With incremental searching, you always know what the results of your search will be, because the results are highlighted on your screen at all times. If you misspell your search pattern, Vim will no longer show you a highlighted match for your search pattern. When your highlighted match string disappears from the screen, you know immediately that you should back up by using the BACKSPACE key, and fix your search pattern. If you change your mind about what you wish to search for, you can press the ESCAPE key, and Vim will return the cursor to its previous location.
Programmers often don't capitalize code consistently. I'm no exception here. From one program to another—and sometimes even, to my shame, within the same program—my capitalization scheme changes.
“Let's see, was that subroutine named “CrashAndBurn”, “CRASHANDBURN”, “crashandburn” or “Crashandburn”?” If your editor is too picky about distinguishing upper-case from lower-case letters in its search patterns, you'll have a hard time matching the string. On the other hand, sometimes case is significant, and you do want to find “CrashAndBurn” and not “crashandburn”. What to do?
By default, both vi and Vim won't match anywhere in the text where the capitalization isn't exactly the same as the search pattern you entered; however, we can change this default behavior. Vim has a couple of options that, when used together, can take the pain out of upper/lower-case confusion. You can try these options by pressing the ESCAPE key, then typing the following two commands, pressing ENTER after each one:
:set ignorecase
:set smartcase
The ignorecase option is supported in vi as well as in Vim. It entirely disregards upper- and lower-case distinctions in search patterns. With ignorecase set, a search for the pattern “crashandburn” will match “CrAsHaNdBuRn” and “crashANDburn” as well as “crashandburn” in the text.
This is an improvement over the default behavior in some cases, but what if I really do want to search based on case distinctions? Will I have to set and unset ignorecase each time I want to search a different way?
In vi, the answer, unfortunately, is yes. Vim is a little more subtle, though, in that it offers the smartcase option as well. If both ignorecase and smartcase are set, Vim will ignore the case of the search only if the search pattern is all in lower-case. But if there are any upper-case characters in the search pattern, Vim will assume you really want to do a case-sensitive search and will do its matching accordingly.
For example, with both ignorecase and smartcase turned on, Vim will match “crashandburn” with both “CrashAndBurn” and “crashandburn”. If you enter “CrashAndBurn” as your search pattern, however, Vim will only match the string “CrashAndBurn” in the text. It won't match “crashaNDBUrn”.
In practice, this combination of options works out to be a good compromise, letting you balance case-sensitive and case-insensitive searches nicely without having to set or unset an option to do them.
When I'm editing a program or document, I like to have a little context around my work by keeping the line of text I'm working on a couple of lines away from the edge of the window at all times.
In vi, I would maintain this bit of context by scrolling a few lines either above or below the line I wished to edit, then moving back to my destination and doing my editing. It wasn't great, but it was better than typing blind, which is how I felt whenever I worked on the first or last line of the screen.
Luckily, Vim can maintain some context for you automatically through the use of the scrolloff option. You can try setting this option by pressing the ESC key and entering
:set scrolloff=2
The 2 means I want at least two lines of context visible around the cursor at all times. You can set this to any number you like. Vim will scroll your file so that your cursor will never be closer to the top and bottom edge of the screen than the number of lines you specify.
Vim won't always be able to honor your scrolloff specification. If you're near the bottom or top of the file, there may not be enough lines left between your cursor and the file's beginning or end to give you the context you asked for. It will do the best it can, though.
I recommend the scrolloff feature highly. It's been a great help to me.
I hate typing file names. Why should I have to type out a file name like “thelongestfilenameintheworld.html” if the starting characters “thelong” will uniquely identify it from all other files in the current subdirectory? I also have the habit of wanting to edit a file deep within an unfamiliar directory structure.
Luckily, Vim has file name completion. File name completion lets you enter a partial file name into Vim, then press the TAB key to have Vim search for a file or directory name that could complete it. If Vim finds exactly one file or directory that matches, it fills in the rest of the name. If Vim can't find any match, it beeps.
What if Vim finds more than one file or directory name that matches? You can specify what Vim does next in this case by setting the wildmode option. The default setting for wildmode is “full”. When wildmode is set like this, the first time you press TAB, Vim will fill in one of the files or directory names that match what you have typed so far. If you hit TAB again, Vim will show you another file that completes your match. As you keep pressing TAB, Vim will go through all the possible completions. When it runs out, the next time you press TAB, Vim will show you the original incomplete string you entered. Now you're back where you started. If you press TAB again, Vim will show you the first match again.
While this is good, I prefer my file name completion to work a little differently. Here's how I like to have wildmode set:
:set wildmode=longest,list
Setting wildmode this way makes Vim act as follows. When I enter part of a file name and press TAB, Vim completes my file name to the longest common string among the alternatives. It then waits for me to do one of the following: press ENTER to accept that as the file name, keep typing the file name from that place, press ESC to cancel the command, or press TAB again. The second time I press TAB, Vim will list all possible files that could complete my partial file or directory name.
Don't like either of the file completion methods I listed above? Not to worry: wildmode has many different options. For details, enter
:help wildmode
and Vim will show you every possible option.
Enjoy customizing Vim. If you take one step at a time, you'll find that using Vim becomes more and more pleasant as time goes by. I think the more you make Vim work your way rather than its default way, the more you'll come to like it.
Coutsey : Dan Puckett supports configuration management software for a rather large telecommunications firm. He is a writer and actor. He welcomes your comments at puckett@acm.org.
http://www.linuxjournal.com/article/3805#comment-340004
Thursday, July 23, 2009
how to add different vim color schemes
set nocompatible and syntax on to your ~/.vimrc file. While you are editing your .vimrc file, there are a ton of other cool things you can tweak which I recommend as well (ex. tabstop, nowrap, ignorecase, bs, etc). Once you have syntax highlighting on, you may decide you want a different color scheme. This is also simple. You can put color scheme definition files in the ~/.vim/colors/ directory. The files will have a “vim” extension. You can load a color scheme by typing :colors [scheme_name] while in vi. In most OS installs there are a ton of schemes included, in OS X these are in “/usr/share/vim/vim62/colors/”. Included for me are: darkblue, desert, elflord, evening, koehler, morning, murphy, pablo, peachpuff, ron, shine, shine, torte, and zellner. If none of these tickle your fancy, there are a bunch available here or you could always build your own.
You may also add any color schemes that you got from internet. To do that, obtain the file from internet, it must be a .vim extension file. Check out which is your VIM's home directory. You can get it by executing the following in vim ":echo $home". Go to that directory. You will find a "colors" directory. Add your .vim extension file in it. Also then make the necessary changes in .vimrc file also.
Courtsey: http://nosheep.net/story/vi-color-schemes/
Tuesday, July 21, 2009
How to search a perl function's man page
perldoc -f
for example,
perldoc -f our
perldoc -f sysopen
Perl-error ".pm did not return a true value at"
It was because I had not put "1;" at the end of my perl module. So I did not get the error after I put "1;" at the end of the perl module.
why is the "1;" necessary at the end of perl modules?
Typically, a module contains a bunch of subroutine definitions. A
module may also contain code which is not part of a subroutine. This
code is executed at the time the module is loaded, so it can be used
to initialize the module. For example, the module might open
adatatbase connection or initialize some time at the time it is
loaded.
Such code might be successful, or it might fail. Perl allows the
module to indicate the result by returning a true or false value back
to its caller. If the value is false, Perl aborts the compilation
with an error message.
Unfortunately, the default return value is *false*, so a module which
just defines a bunch of subroutines, and which has no initialization
code, accidentally returns a false value back to the caller, and Perl
aborts. So we insert "1;" at the end to suppress this misbehavior.
http://dev.perl.org/rfc/269.pod
http://dev.perl.org/rfc/269.html
discusses this in some more detail.
For documentation, see perldiag:
%s did not return a true value
(F) A required (or used) file must return a true value
to indicate that it compiled correctly and ran its
initialization code correctly. It's traditional to
end such a file with a "1;", though any true value
would do. See the require entry in the perlfunc man-
page.
and the relevant part of 'perlfunc':
The file must return true as the last statement
to indicate successful execution of any initialization code, so
it's customary to end such a file with "1;" unless you're sure
it'll return true otherwise. But it's better just to put the
"1;", in case you add more statements.
Courtsey: http://lists.netisland.net/archives/phlpm/phlpm-2001/msg00426.html
Friday, July 17, 2009
cd // ??
- cd //
When I tried the command "pwd" i got the output as "//".
When I tried the command "ls" i got the same output as if it was the "/" directory.
When I tried the command "cd .." I was in the same directory as happens in "/" directory.
So I could conclude that it is the same "/" directory. But its existence did not make any sense then.
Tuesday, July 7, 2009
adding alias for commands in Bash
If you have used UNIX for a while, you will know that there are many commands available and that some of them have very cryptic names and/or can be invoked with a truckload of options and arguments. So, it would be nice to have a feature allowing you to rename these commands or type something simple instead of a list of options. Bash provides such a feature : the alias .
Aliasses can be defined on the command line, in .bash_profile, or in .bashrc, using this form :
| |
- alias ls='ls -aF --color=always'
- alias ll='ls -l'
- alias search=grep
- alias mcd='mount /mnt/cdrom'
- alias ucd='umount /mnt/cdrom'
- alias mc='mc -c'
- alias ..='cd ..'
- alias ...='cd ../..'
- alias ls='/bin/ls -aFG'
One more important thing. After you have added alias in .bashrc, you need to inform your system about the changes and hence execute the following command:
- source .bashrc
Monday, July 6, 2009
OpenSSH Public Key authentication
This is method is used usually when you are a server administrator and usually work by logging through SSH in to the server. You will not like to enter the password everytime you want to log in. For this you can follow this method.
Host-based authentication works as follows: If the machine the user logs
in from is listed in /etc/hosts.equiv or /etc/shosts.equiv on the remote
machine, and the user names are the same on both sides, or if the files
~/.rhosts or ~/.shosts exist in the user's home directory on the remote
machine and contain a line containing the name of the client machine and
the name of the user on that machine, the user is considered for login.
Additionally, the server must be able to verify the client's host key
(see the description of /etc/ssh/ssh_known_hosts and ~/.ssh/known_hosts,
below) for login to be permitted. This authentication method closes se-
curity holes due to IP spoofing, DNS spoofing, and routing spoofing.
[Note to the administrator: /etc/hosts.equiv, ~/.rhosts, and the
rlogin/rsh protocol in general, are inherently insecure and should be
disabled if security is desired.]
Public key authentication works as follows: The scheme is based on pub-
lic-key cryptography, using cryptosystems where encryption and decryption
are done using separate keys, and it is unfeasible to derive the decryp-
tion key from the encryption key. The idea is that each user creates a
public/private key pair for authentication purposes. The server knows
the public key, and only the user knows the private key. ssh implements
public key authentication protocol automatically, using either the RSA or
DSA algorithms. Protocol 1 is restricted to using only RSA keys, but
protocol 2 may use either. The HISTORY section of ssl(8) contains a
brief discussion of the two algorithms.
The file ~/.ssh/authorized_keys lists the public keys that are permitted
for logging in. When the user logs in, the ssh program tells the server
which key pair it would like to use for authentication. The client
proves that it has access to the private key and the server checks that
the corresponding public key is authorized to accept the account.
The user creates his/her key pair by running ssh-keygen(1). This stores
the private key in ~/.ssh/identity (protocol 1), ~/.ssh/id_dsa (protocol
2 DSA), or ~/.ssh/id_rsa (protocol 2 RSA) and stores the public key in
~/.ssh/identity.pub (protocol 1), ~/.ssh/id_dsa.pub (protocol 2 DSA), or
~/.ssh/id_rsa.pub (protocol 2 RSA) in the user's home directory. The us-
er should then copy the public key to ~/.ssh/authorized_keys in his/her
home directory on the remote machine. The authorized_keys file corre-
sponds to the conventional ~/.rhosts file, and has one key per line,
though the lines can be very long. After this, the user can log in with-
out giving the password.
The most convenient way to use public key authentication may be with an
authentication agent. See ssh-agent(1) for more information.
Challenge-response authentication works as follows: The server sends an
arbitrary "challenge" text, and prompts for a response. Protocol 2 al-
lows multiple challenges and responses; protocol 1 is restricted to just
one challenge/response. Examples of challenge-response authentication
include BSD Authentication (see login.conf(5)) and PAM (some non-OpenBSD
systems).
Finally, if other authentication methods fail, ssh prompts the user for a
password. The password is sent to the remote host for checking; however,
since all communications are encrypted, the password cannot be seen by
someone listening on the network.
ssh automatically maintains and checks a database containing identifica-
tion for all hosts it has ever been used with. Host keys are stored in
~/.ssh/known_hosts in the user's home directory. Additionally, the file
/etc/ssh/ssh_known_hosts is automatically checked for known hosts. Any
new hosts are automatically added to the user's file. If a host's iden-
tification ever changes, ssh warns about this and disables password au-
thentication to prevent server spoofing or man-in-the-middle attacks,
which could otherwise be used to circumvent the encryption. The
StrictHostKeyChecking option can be used to control logins to machines
whose host key is not known or has changed.
When the user's identity has been accepted by the server, the server ei-
ther executes the given command, or logs into the machine and gives the
user a normal shell on the remote machine. All communication with the
remote command or shell will be automatically encrypted.
Thursday, June 25, 2009
Sending emails using telnet
Sending emails using telnet.
The basics.
Before starting it's important to know a few things:
SMTP address.
The SMTP server address of a provider you are permitted to use. Usually this will be you ISP's SMTP server but could be any other, if you are not sure of the address
then look at the settings in your email client. Otherwise the E-Eeasy.com site has a long
list of SMTP servers.
Port blocking.
To prevent spamming it's possible that your ISP blocks the default SMTP port, port 25. If this is the case and you try to connect to a different SMTP server (other
than your ISP's smtp server) then you will probably just get a timeout when you try to connect. Some email providers allow you to use an alternate port, in my
case I use Fastmail.fm and they allow you to use port 26, but you will have to check with your
account provider first.
Relaying.
If you are able to connect to another SMTP that's not your ISP's then you will (or should) only be able to send an email to a user of that email provider. For example I can
connect using telnet to my email provider at Fastmail.fm and send an email to another Fastmail user since they have to accept mail to their users (otherwise they would
not be able to receive any mail), but if I try to send an email to another email address, say someone@hotmail.com then I will be denied since then I'm using Fastmail.fm's
SMTP server as a mail relay which is not allowed without authentication.
Using telnet.
If you make a mistake you cannot use backspace to delete the entry, you may have to press enter to get an error and then re-type the command or quit and start again.
Connecting to the host.
With this in mind it's very easy to send a basic text email just using telnet which is installed on most computers. First open up a terminal and type the following, of
course replacing mail.yourserver.dk with the address of your SMTP server:
telnet mail.yoursever.dk 25
This should return something like:
telnet mail.yoursever.dk 25
Trying 172.16.0.2...
Connected to mail.yoursever.dk (172.16.0.2).
Escape character is '^]'.
220 cirkeline.yoursever.dk ESMTP Postfix (Debian/GNU)
HELO command.
Next we need to introduce ourselves using the helo command, in reality this can be anything and the mail will still be sent OK (although a false helo command
will result in a spam score from spamassasin for example).
helo mail.localhost
250 mail.yoursever.dk
MAIL FROM command.
Next we type mail from: followed by your email address, if you use a name as well then you need to put angle brackets around you address,
like Bob Peers <email@domain.dk>, but the name is not necessary
mail from:me@domain.dk
250 Ok
RCPT TO command.
Now type rcpt to: followed by who you are sending the mail to, following the same rules as above. Note that this IS NOT the address that appears on the To: line in
your email client or webmail, the two are completely unrelated which is why you can receive spam when your email address is not listed on the To: line.
rcpt to:you@domain.com
250 Ok
DATA command.
Now for the actual mail body, type the word 'data' and press enter:
data
354 End data with <CR><LF>.<CR><LF>
Your SMTP server might not display the extra help here but it simply means that we type our mail body now and to end the input press enter then type a single .
followed by pressing enter again. At this point we can add extra headers if we wish but they are not required. This just shows that the To and From fields are just
part of the message body and have nothing to do with the delivery of the email. However if you do not add them then the message will arrive with
'To: undisclosed-recipients:; in the To field, which again will probably cause your message to be assigned a spam score. If you do decide to add these extra
headers make sure you leave a blank line between them and the 'real' text you wish to appear in the body of the message.
to:Joe Bloggs<you@domain.com>
from: Bob Peers<me@domain.dk>
subject:Telnet test
Hope you are following along OK...
.
250 Ok: queued as 4DDFB180CDA
To actually send the mail we need to quit the telnet session by typing 'quit'.
quit
221 Bye
Connection closed by foreign host.
Summary
If all goes well you should get the email without problems, that's basically all there is to it. Many of the extra lines are not really required, as long as you type
the 'helo', 'mail from:' and 'rcpt to:' commands along with 'data', terminating '.' and 'quit' the mail should be sent.
Relay access denied error.
If you try to send an email to an external address when you are not permitted you will get some output like below (this is using my Fastmail account).
telnet mail.messagingengine.com 25
Trying 66.111.4.160...
Connected to mail.messagingengine.com (66.111.4.160).
Escape character is '^]'.
220 frontend2.messagingengine.com ESMTP . No UCE permitted.
helo mail.localhost
250 frontend2.messagingengine.com
mail from:someone@somewhere.dk
250 Ok
rcpt to:someoneelse@hotmail.com
554 <someoneelse@hotmail.com>: Relay access denied
quit
221 Bye
Connection closed by foreign host.
Tuesday, June 23, 2009
difference between useradd and adduser command
useradd and groupadd are the posix or SUS-standardized tools to create
users and groups. You can expect them to work (almost) identically on all Linux
distributions as well as on HP-UX, Solaris, AIX, ...
adduser and groupadd are distribution specific wrappers which make it
simpler to create users which conform to some (distribution-specific or
local) policy. The options vary wildly between different distributions
and other UNIXes may not have these commands at all.
Monday, June 22, 2009
To add dhclient on startup
Add the line
auto eth0
to /etc/network/interfaces
Then the system will definitely try to get an ip-address.
It is not working for me. So if it does for you do tell me. :(
Sunday, June 21, 2009
how to extract different types of compressed files.
- .tar.gz - command$: tar xvfz file.
Friday, June 12, 2009
how to add more than one homepage in firefox
Thursday, June 11, 2009
how to extract a .tar.bz2 file?
bunzip2
tar -tvf
tar -xvf
Accessing POP3 email accounts using telnet
The basics.
About POP.
POP is simply a protocol for retrieving emails from a remote server. The vast majority of mail
providers use this protocol and it has been around for many years now. The protocol, in it's
simplest form, is just a few text commands sent from your computer over the internet which when received by the mail server prompt it to respond with the
requested information. There's only 4 or 5 basic commands we need to know to get started so it's very simple.
Before starting it's important to know a few things:
Mail server address.
The address of your mail server, this will usually be of the form mail.domain.com. You should look at the settings in your email client or documentation about your
email account to get this information.
Security.
In this demonstration we will be sending our account username and password unencrypted over the internet, if this is a major concern to you then you should not follow
this exercise.
Using telnet.
If you make a mistake in a telnet session you cannot use backspace to delete the entry, you may have to press enter to get an error and then re-type the command or quit and start again.
Connecting to the host.
First open up a terminal and type the following, of course replacing mail.yourserver.dk with the address of your POP server:
telnet mail.myserver.dk 110
This should return something like:
telnet mail.myserver.dk 110
Trying 172.16.0.2...
Connected to mail.myserver.dk (172.16.0.2).
Escape character is '^]'.
+OK Hello there.
Logging in.
Next we need to log in using the user command.
user myusername
+OK Password required.
Now give our password using the pass command.
pass ***********
+OK logged in.
The list command.
To see a list of all the messages on the server and their sizes in bytes use the list command. If you specify a message number then only that message will be shown,
i.e list 7.
list
+OK POP3 clients that break here, they violate STD53.
1 22683
2 19870
3 785
4 4475
5 3221
6 2972
7 2412
This just shows that I have 7 emails on the server, they are listed in order from oldest first to newest last.
Reading the messages using retr.
To read one of the messages use the retr command followed
by the message number returned from the list command. It will return the whole message including all headers.
retr 7
+OK 2412 octets follow.
Return-Path: <bounce@domain.com>
X-Original-To: me@domain.dk
Delivered-To: me@domain.dk
Received: from mail-in1.inet.tele.dk (mail-in1.inet.tele.dk [194.182.148.158])
by cirkeline.ingolf.dk (Postfix) with ESMTP id 554DA180D71
for <me@domain.dk>; Wed, 1 Feb 2006 10:09:54 +0100 (CET)
Received: from out4.smtp.messagingengine.com (out4.smtp.messagingengine.com [66.111.4.28])
by mail-in1.inet.tele.dk (Postfix) with ESMTP id 2984C7049
for <me@domain.dk>; Tue, 31 Jan 2006 18:37:01 +0100 (CET)
Received: from frontend1.internal (mysql-sessions.internal [10.202.2.149])
by frontend1.messagingengine.com (Postfix) with ESMTP id 2069DD335A7
for <me@domain.dk>; Tue, 31 Jan 2006 12:36:18 -0500 (EST)
Received: from web2.messagingengine.com ([10.202.2.211])
by frontend1.internal (MEProxy); Tue, 31 Jan 2006 12:36:18 -0500
Received: by web2.messagingengine.com (Postfix, from userid 99)
id 1148513964; Tue, 31 Jan 2006 12:36:12 -0500 (EST)
Content-Disposition: inline
Content-Transfer-Encoding: 7bit
Content-Type: text/plain
MIME-Version: 1.0
X-Mailer: MIME::Lite 5022 (F2.73; T1.15; A1.64; B3.05; Q3.03)
Date: Tue, 31 Jan 2006 17:36:12 UT
From: "Email Administrator" <bounce@domain.com>
Reply-To: "Email Administrator" <webmaster@domain.com>
To: me@domain.dk
Subject: Your www.domain.com account activation
Message-Id: <20060131173612.1148513964@web2.messagingengine.com>
..............................
Reading the top n lines with top.
The top command is used to read the top n lines of a message, the syntax is 'top message n' where n is the number of lines you wish to read. Note
that the full headers will be returned along with a new line and then the n lines of the message body.
top 3 5
Headers appear here.....
This is a multi-part message in MIME format.
------=_NextPart_000_0295_01C5A03F.3E4B4030
Content-Type: text/plain;
charset="iso-8859-1"
The stat command.
To see the total number and size of all messages issue the stat command.
stat
+OK 7 56418
Deleting messages using dele.
To delete a message use dele followed by the message number, note that messages are not immediately deleted, they will only be deleted after quitting the session.
dele 7
+OK Deleted.
The stat command again shows the message is gone.
stat
+OK 6 54006
Resetting the account using rset.
Since the message is only marked for deletion we can undelete the message (and any other marked for deletion) by using rset (for reset).
rset
+OK Resurrected.
Again, stat shows the message is now back.
stat
+OK 7 56418
To end the session use quit, this will now permanently delete the messages you deleted during this session.
quit
+OK Bye-bye.
Summary
It's very simple to read your emails from a POP account using telnet by just remembering a few simple commands, what we have done here is basically exactly
the same as an email client, like Thunderbird or Outlook Express, does when it retrieves your mail. Of course on a daily basis it's much nicer to use a web interface
or email client but in those situations where all you have is an internet connection then this is a great fall-back especially since nearly every computer will
have telnet already installed.
Accessing IMAP email accounts using telnet.
The basics.
About IMAP.
IMAP is an email protocol for organizing, storing and retrieving emails on a remote server. It was
developed after POP and is a much more advanced system, one of the main differences being that all the mail is stored on the server so it remains accessible from many
different locations. With POP you have to download the mail to your local computer in order to read it and therefore you cannot synchronize your mail across many
different machines.It may be more complex than POP but there are still only a few core commands we need to know in order to access our mail on an IMAP server.
Before starting it's important to know a few things:
IMAP command syntax.
Before the actual command is typed into the terminal we need to type a command tag, this could be anything (without spaces) and the server will tag its response
with the tag we give it. This seems to be because IMAP allows multiple connections and so multiple commands, by tagging you know which response refers to which command.
In our case we have only 1 connection and we send single commands so it's not really relevant, however we need to type something as a tag. I usually just use a period
'.' but you could use a number or whatever suits you. To demonstrate the command tag see the two server responses here with the tag (don't worry about the command itself, it
will be explained soon), in the first one we send '. fetch' and the second one 'a01a fetch' getting the same tag back to identify the response:
. fetch 1 fast
* 1 FETCH (FLAGS (\Seen hasatt) INTERNALDATE " 1-Feb-2006 08:37:23 -0500" RFC822.SIZE 15013)
. OK Completed (0.000 sec)
ao1a fetch 1 fast
* 1 FETCH (FLAGS (\Seen hasatt) INTERNALDATE " 1-Feb-2006 08:37:23 -0500" RFC822.SIZE 15013)
a01a OK Completed (0.000 sec)
Finally, the IMAP commands are not case sensitive, so 'SELECT inbox' will work just as well as 'select INBOX'. For clarity in the code I have typed the commands in
uppercase and the word INBOX in uppercase also.
Mail server address.
The address of your mail server, this will usually be of the form mail.domain.com. You should look at the settings in your email client or documentation about your
email account to get this information.
Security.
In this demonstration we will be sending our account username and password unencrypted over the internet, if this is a major concern to you then you should not follow
this exercise.
Another alternative, if your email provider supports SSL, is to use OpenSSL (which most if not all Linux computers will have), see the 'Connecting to the host' section
below for the syntax.
Using telnet.
If you make a mistake in a telnet session you cannot use backspace to delete the entry, you may have to press enter to get an error and then re-type the command or quit and start again.
Connecting to the host.
Insecure login - login using telnet.
By insecure I just mean that your username and password are sent unencrypted over the internet so potentially could be intercepted on the route between your computer and the mail server.
First open up a terminal and type the following, of course replacing mail.myserver.com with the address of your IMAP server, note that the IMAP port used is 143:
telnet mail.myserver.com 143
This should return something like:
telnet mail.myserver.com 143
Trying 66.111.4.160...
Connected to mail.myserver.com (66.111.4.160).
Escape character is '^]'.
* OK IMAP4 ready
Secure login - login using OpenSSL.
To open an SSL session that encrypts all data sent between your computer and the mail server open a teminal and follow these steps, note that we use port 993 here:
openssl s_client -connect mail.myserver.com:993
CONNECTED(00000003)
depth=0 /C=AU/ST=New South Wales/L=Crows Nest/O=Optimal Decisions Group Pty Ltd/CN=mail.messagingengine.com
verify error:num=20:unable to get local issuer certificate
verify return:1
depth=0 /C=AU/ST=New South Wales/L=Crows Nest/O=Optimal Decisions Group Pty Ltd/CN=mail.messagingengine.com
verify error:num=27:certificate not trusted
verify return:1
depth=0 /C=AU/ST=New South Wales/L=Crows Nest/O=Optimal Decisions Group Pty Ltd/CN=mail.messagingengine.com
verify error:num=21:unable to verify the first certificate
verify return:1
---
Certificate chain
0 s:/C=AU/ST=New South Wales/L=Crows Nest/O=Optimal Decisions Group Pty Ltd/CN=mail.messagingengine .com
i:/C=ZA/ST=Western Cape/L=Cape Town/O=Thawte Consulting cc/OU=Certification Services Division/CN= Thawte Premium Server CA/emailAddress=premium-server@thawte.com
---
Server certificate
-----BEGIN CERTIFICATE-----
MIIDeDCCAuGgAwIBAgIDQBYSMA0GCSqGSIb3DQEBBAUAMIHOMQswCQYDVQQGEwJa
..........................
-----END CERTIFICATE-----
subject=/C=AU/ST=New South Wales/L=Crows Nest/O=Optimal Decisions Group Pty Ltd/CN=mail.messagingeng ine.com
issuer=/C=ZA/ST=Western Cape/L=Cape Town/O=Thawte Consulting cc/OU=Certification Services Division/C N=Thawte Premium Server CA/emailAddress=premium-server@thawte.com
---
No client certificate CA names sent
---
SSL handshake has read 1054 bytes and written 340 bytes
---
New, TLSv1/SSLv3, Cipher is AES256-SHA
Server public key is 1024 bit
SSL-Session:
Protocol : TLSv1
Cipher : AES256-SHA
Session-ID: Session ID
Session-ID-ctx:
Master-Key: Key
Key-Arg : None
Krb5 Principal: None
Start Time: 1140271254
Timeout : 300 (sec)
Verify return code: 21 (unable to verify the first certificate)
---
* OK IMAP4 ready
Once this step is carried out the IMAP commands are identical to those for a normal telnet session.
Logging in.
Next we need to log in using the login command. Type '. login' followed by your username and password separated by spaces.
. login accountname@myserver.com *********
. OK User logged in
LIST command.
To see a list of all the mailboxes on the server we use the list command. The arguments "" "*" simply get all the mailboxes including sub folders.
. list "" "*"
* LIST (\HasChildren) "." "INBOX"
* LIST (\HasNoChildren) "." "INBOX.Drafts"
* LIST (\HasNoChildren) "." "INBOX.Sent Items"
* LIST (\HasNoChildren) "." "INBOX.Trash"
* LIST (\HasNoChildren) "." "INBOX.test1"
* LIST (\HasNoChildren) "." "INBOX.test2"
. OK Completed (0.460 secs 7 calls)
We can see from this output how the mailboxes are arranged like a tree with INBOX being the 'trunk'. My IMAP provider uses a period (.) as a separator between parent and
child folders so INBOX.Drafts is a child of the INBOX. The \HasChildren simply tells us that this folder has sub folders whereas the other folders do not.
The way IMAP works means that all folders are created as subfolders of the INBOX even if your email client is configured not to show it that way.
STATUS command.
This command return some basic information on the folder without selecting the folder, it takes arguments depending on what information you would like returned.
Here are 3 example showing total messages, recent messages and unseen messages.
. status INBOX (messages)
* STATUS INBOX (MESSAGES 2)
. OK Completed
. status INBOX (recent)
* STATUS INBOX (RECENT 0)
. OK Completed
. status INBOX (unseen)
* STATUS INBOX (UNSEEN 0)
. OK Completed
EXAMINE and SELECT commands.
These two commands basically do the same thing, they return information on the folder chosen and then allow us to access the mails stored inside the folder. The
main difference is that EXAMINE returns a read-only reference whereas SELECT is read-write.
. examine INBOX.test2
* FLAGS (\Answered \Flagged \Draft \Deleted \Seen)
* OK [PERMANENTFLAGS ()]
* 0 EXISTS
* 0 RECENT
* OK [UIDVALIDITY 1138801117]
* OK [UIDNEXT 1]
. OK [READ-ONLY] Completed
. select INBOX.test2
* FLAGS (\Answered \Flagged \Draft \Deleted \Seen)
* OK [PERMANENTFLAGS (\Answered \Flagged \Draft \Deleted \Seen \*)]
* 0 EXISTS
* 0 RECENT
* OK [UIDVALIDITY 1138801117]
* OK [UIDNEXT 1]
. OK [READ-WRITE] Completed
Note that the only difference in response is the [READ-ONLY] and [READ-WRITE] text. Basically this command just tells us the possible IMAP flags we can set,
EXIST is how many mails are in the folder, RECENT is how many recent mails there are (the SELECT command will remove the RECENT flag since the folder has now been
viewed, this is not the same as the \Seen IMAP flag, also note that the EXAMINE command will not reset the RECENT flag).
The RECENT data is what tells an IMAP email client if you have new mails, by clicking on the folder the client sends the SELECT command and the new mail icon
disappears even though the mails are still unread.
CREATE, DELETE and RENAME folders.
It's very easy to create and delete folders, just make sure you create them as subfolders of the INBOX. For example to create a top level folder called test3 do
do the following.
. create INBOX.test3
. OK Completed
. list "" "*"
* LIST (\HasChildren) "." "INBOX"
* LIST (\HasNoChildren) "." "INBOX.Drafts"
* LIST (\HasNoChildren) "." "INBOX.Sent Items"
* LIST (\HasNoChildren) "." "INBOX.Trash"
* LIST (\HasNoChildren) "." "INBOX.test1"
* LIST (\HasNoChildren) "." "INBOX.test2"
* LIST (\HasNoChildren) "." "INBOX.test3" #we created this
. OK Completed (0.420 secs 8 calls)
Conversely we can delete our new folder using the DELETE command. Note that you cannot delete a folder that had subfolders without first deleting the subfolders, also
deleting a folder containing mails will delete all the mails inside so beware!
. delete INBOX.test3
. OK Completed
. list "" "*"
* LIST (\HasChildren) "." "INBOX"
* LIST (\HasNoChildren) "." "INBOX.Drafts"
* LIST (\HasNoChildren) "." "INBOX.Sent Items"
* LIST (\HasNoChildren) "." "INBOX.Trash"
* LIST (\HasNoChildren) "." "INBOX.test1"
* LIST (\HasNoChildren) "." "INBOX.test2"
. OK Completed (0.430 secs 7 calls)
Renaming a folder is just as easy, just type RENAME [current name] [new name]. This will not delete mails as they will just exist in the new folder. Here we rename
folder test1 to linux.
. rename INBOX.test1 INBOX.test3
* OK rename user.accountname.test1 user.accountname.test3
. OK Completed
. list "" "*"
* LIST (\HasChildren) "." "INBOX"
* LIST (\HasNoChildren) "." "INBOX.Drafts"
* LIST (\HasNoChildren) "." "INBOX.Sent Items"
* LIST (\HasNoChildren) "." "INBOX.Trash"
* LIST (\HasNoChildren) "." "INBOX.linux" #this was test1
* LIST (\HasNoChildren) "." "INBOX.test2"
. OK Completed (0.410 secs 7 calls)
FETCH command.
This command is the main command we use to actually access our emails. It has many possible options depending in what you wish to see, message flags, email headers,
text of the body etc. Here we select the INBOX and fetch the emails in a few different ways.
. select INBOX
* FLAGS (\Answered \Flagged \Draft \DeleteCLOSE and EXPUNGE commands.d \Seen hasatt)
* OK [PERMANENTFLAGS (\Answered \Flagged \Draft \Deleted \Seen hasatt \*)]
* 2 EXISTS
* 0 RECENT
* OK [UIDVALIDITY 1138801043]
* OK [UIDNEXT 3]
. OK [READ-WRITE] Completed
. fetch 1 flags
* 1 FETCH (FLAGS (\Seen hasatt))
. OK Completed (0.000 sec)
First we shall fetch the message IMAP flags for all the messages in the folder.
. fetch 1:2 flags
* 1 FETCH (FLAGS (\Seen hasatt))
* 2 FETCH (FLAGS (\Seen hasatt))
. OK Completed
Note that with all the commands that act upon messages we can select either 1 message by using the message number as in 'fetch 1 command' or we can select a range
of messages in the format 'fetch first:last command' or all the messages 'fetch 1:last command'. Also note that we can use '*' to indicate all messages so fetch 1:* will get
all the messages from the first to the last without us knowing how many messages are in the folder.
First we shall fetch using fast, all and full options (these refer to the headers).
. fetch 1 fast
* 1 FETCH (FLAGS (\Seen hasatt) INTERNALDATE " 1-Feb-2006 08:37:23 -0500" RFC822.SIZE 15013)
. OK Completed (0.000 sec)
. fetch 1 all
* 1 FETCH (FLAGS (\Seen hasatt) INTERNALDATE " 1-Feb-2006 08:37:23 -0500" RFC822.SIZE 15013 ENVELOPE ("Wed, 1 Feb 2006 13:37:19 UT" "IMPORTANT: Click here to begin using your account" (("Email Administrator" NIL "bounce" "myserver.com")) (("Email Administrator" NIL "bounce" "myserver.com")) ((NIL NIL "webmaster" "myserver.com")) (("Joe Bloggs" NIL "accountname" "myserver.com")) NIL NIL NIL "<cmu-lmtpd-28871-1138801043-0@server2.messagingengine.com>"))
. OK Completed (0.000 sec)
. fetch 1 full
* 1 FETCH (FLAGS (\Seen hasatt) INTERNALDATE " 1-Feb-2006 08:37:23 -0500" RFC822.SIZE 15013 ENVELOPE ("Wed, 1 Feb 2006 13:37:19 UT" "IMPORTANT: Click here to begin using your account" (("Email Administrator" NIL "bounce" "myserver.com")) (("Email Administrator" NIL "bounce" "myserver.com")) ((NIL NIL "webmaster" "myserver.com")) (("Joe Bloggs" NIL "accountname" "myserver.com")) NIL NIL NIL "<cmu-lmtpd-28871-1138801043-0@server2.messagingengine.com>") BODY ((("TEXT" "PLAIN" NIL NIL NIL "8BIT" 5599 137)("TEXT" "HTML" NIL NIL NIL "8BIT" 7434 141) "ALTERNATIVE")("TEXT" "PLAIN" ("NAME" "This_is_how_attachments_appear.txt") NIL NIL "8BIT" 247 6) "MIXED"))
. OK Completed (0.000 sec)
As you can see this returns differing amounts of data about the IMAP flags, size and ENVELOPE information. It's maybe more informative to use either 'fetch message body[header]'
or 'fetch message rfc822.header' both of which return the data below.
. fetch 1 rfc822.header
* 1 FETCH (RFC822.HEADER {824}
Return-Path: <nobody@server2.messagingengine.com>
Received: from web2.internal (web2.internal [10.202.2.211])
by server2.messagingengine.com (Cyrus v2.3-alpha) with LMTPA;
Wed, 01 Feb 2006 08:37:23 -0500
X-Sieve: CMU Sieve 2.3
X-Attached: This_is_how_attachments_appear.txt
X-Resolved-to: accountname
X-Mail-from: nobody
Content-Transfer-Encoding: 8bit
Content-Type: multipart/mixed; boundary="_----------=_1138801039165120"
MIME-Version: 1.0
X-Mailer: MIME::Lite 5022 (F2.73; T1.15; A1.64; B3.05; Q3.03)
Date: Wed, 1 Feb 2006 13:37:19 UT
From: "Email Administrator" <bounce@myserver.com>
Reply-To: webmaster@myserver.com
To: "Joe Bloggs" <accountname@myserver.com>
Subject: IMPORTANT: Click here to begin using your account
Message-ID: <cmu-lmtpd-28871-1138801043-0@server2.messagingengine.com>
)
. OK Completed (0.000 sec)
To fetch only some headers we can select the header fields we wish to see.
. fetch 1 (body[header.fields (from to subject date)])
* 1 FETCH (BODY[HEADER.FIELDS (from to subject date)] {195}
Date: Wed, 1 Feb 2006 13:37:19 UT
From: "Email Administrator" <bounce@myserver.com>
To: "Joe Bloggs" <accountname@myserver.co>
Subject: IMPORTANT: Click here to begin using your account
)
. OK Completed (0.000 sec)
To read the body of the email message we can use either 'fetch message body[text]' or 'fetch message rfc822.text' as shown here.
. fetch 2 rfc822.text
* 2 FETCH (RFC822.TEXT {11658}
This is a multi-part message in MIME format.
--_----------=_1138865560223950
Content-Disposition: inline
Content-Length: 5194
Content-Transfer-Encoding: binary
Content-Type: text/plain
more text here.............
. OK Completed (0.000 sec)
STORE command.
This command allows us to add, remove or replace the IMAP flags on the messages. These are flags that denote a message as replied to, deleted, seen etc. and allow
the message information, as well as the message itself, to be synchronized across different computers. Note that the STORE command causes an automatic FETCH
command of the message flags so we can see the change immediately. There are 3 ways to use STORE:
- STORE message +flags [flag list] - this adds the [flag list] flags to the chosen messages.
- STORE message -flags [flag list] - this removes the [flag list] flags from the chosen messages.
- STORE message flags [flag list] - resets the flags to [flag list] on the chosen messages (the same as removing all flags and then adding [flag list].
The list of flags to add include \Answered \Flagged \Draft \Deleted \Seen and many more. All the IMAP flags used as part of the standard installation have the
backslash in front of them. However some email clients (Thunderbird is one) also allow you to set labels or mark a message as junk, if you add labels do not use
the backslash. First we shall mark all the messages as deleted.
. store 1:2 flags \Deleted
* 1 FETCH (FLAGS (\Recent \Deleted))
* 2 FETCH (FLAGS (\Recent \Deleted))
. OK Completed
Next replace the flags with $label1
. store 1:* flags $label1
* FLAGS (\Answered \Flagged \Draft \Deleted \Seen hasatt Junk label1)
* OK [PERMANENTFLAGS (\Answered \Flagged \Draft \Deleted \Seen hasatt Junk $label1 \*)]
* 1 FETCH (FLAGS ($label1))
* 2 FETCH (FLAGS ($label1))
. OK Completed
Finally we can add the flag NonJunk so that Thunderbird recognises them as not being junk mail.
. store 1:* +flags NonJunk
* FLAGS (\Answered \Flagged \Draft \Deleted \Seen hasatt NonJunk Junk label1)
* OK [PERMANENTFLAGS (\Answered \Flagged \Draft \Deleted \Seen hasatt NonJunk Junk $label1 \*)]
* 1 FETCH (FLAGS ($label1 NonJunk))
* 2 FETCH (FLAGS ($label1 NonJunk))
. OK Completed
Note that the \Deleted flag is used by an IMAP server to mark an email ready for deletion, it is not actually deleted until the server receives either the CLOSE
or EXPUNGE command shown below.
CLOSE and EXPUNGE commands.
Both these commands have the effect of permanently deleting any messages in the current folder marked for deletion with the \Deleted flag. EXPUNGE just deletes the
messages but does nothing else (this command is the equivalent of compacting folders in Thunderbird), while CLOSE deletes the messages and deselects the current
folder (you cannot carry out more action on messages until you select a new folder). Assuming the two messages in our INBOX had the \Deleted flag set then the output
looks like the following.
. expunge
* 1 EXPUNGE
* 1 EXPUNGE
* 0 EXISTS
* 0 RECENT
. OK Completed
COPY command.
IMAP has no built in move command, when you move a message you actually copy it to another folder and then delete the original. We can easily copy any number of
messages using the COPY message [destination] format. Here I copy both messages from the INBOX (that I already have selected) to INBOX.test2 folder, after that I
select INBOX.test2 to confirm the messages are there. Note that after copying the RECENT flag is reset.
. copy 1:2 inbox.test2
. OK [COPYUID 1138801117 1:2 1:2] Completed
. select inbox.test2
* FLAGS (\Answered \Flagged \Draft \Deleted \Seen hasatt)
* OK [PERMANENTFLAGS (\Answered \Flagged \Draft \Deleted \Seen hasatt \*)]
* 2 EXISTS
* 2 RECENT
* OK [UIDVALIDITY 1138801117]
* OK [UIDNEXT 3]
. OK [READ-WRITE] Completed
IDLE command.
IDLE allows us to constantly monitor a folder so that we will be instantly be notified if a new message arrives in the current folder. This is of little use
while in a telnet session but I'll show it here just so you know how it works. First start IDLE on the folder.
. idle
+ idling
The server responds with +idling and will stay this way until either a message is received, we stop idling or carry out another command to break the idle. If non
of these things happen then the connection will eventually time out after a pre-set period depending on your IMAP provider (30 minutes in my case). To stop the IDLE
command use DONE (note this is the only command WITHOUT the preceding command tag).
done
. OK Completed
LSUB, SUBSCRIBE and UNSUBSCRIBE commands.
These are more commands that only really apply to email clients since they involve subscribing to folders, however they are shown here for completeness. First LSUB
works like LIST with the same arguments but returns a list of the currently subscribed folders.
. lsub "" "*"
* LSUB (\HasChildren) "." "INBOX"
* LSUB () "." "INBOX.Drafts"
* LSUB () "." "INBOX.Sent Items"
* LSUB () "." "INBOX.Trash"
* LSUB () "." "INBOX.test2"
. OK Completed (0.000 secs 6 calls)
This shows that all folders except INBOX.test3 are currently subscribed, to subscribe a new folder use SUBSCRIBE [foldername].
. subscribe INBOX.test3
. OK Completed
To unsubscribe from this folder use UNSUBSCRIBE [foldername].
. unsubscribe INBOX.test3
. OK Completed
LOGOUT command.
Of course we need to log out of the server, we do this with the LOGOUT command.
. logout
* BYE LOGOUT received
. OK Completed
That's the main commands covered however there are a few more just 3 of which I'll mention here as they could be useful.
CAPABILITY, GETQUOTAROOT AND GETACL commands.
These 3 commands return general information on the server environment and your account information. CAPABILITY returns a long list of the mail servers option most of
which are not very exciting, the most important one listed is probably IDLE letting you know that your provider supports the IDLE command. The CHILDREN entry we saw
returned when we did a LIST command (\HasChildren or \HasNoChildren depending on whether a folder has subfolders).
. capability
* CAPABILITY IMAP4 IMAP4rev1 ACL QUOTA LITERAL+ MAILBOX-REFERRALS NAMESPACE UIDPLUS ID NO_ATOMIC_RENAME UNSELECT CHILDREN MULTIAPPEND BINARY SORT THREAD=ORDEREDSUBJECT THREAD=REFERENCES ANNOTATEMORE CATENATE IDLE LOGINDISABLED
. OK Completed
GETQUOTAROOT return the amount of space you are using and the amount you have available.
. getquotaroot inbox
* QUOTAROOT inbox user.accountname
* QUOTA user.accountname (STORAGE 31306 2048000)
As you can see I'm using 31Mb but have 2Gb capacity, so plenty to spare! Finally GETACL returns the access control list, basically a list of permission you have on
your mail folders.
. getacl inbox
* ACL inbox accountname lrswipcd admin lrswipcda anyone p
. OK Completed
These letters each refer to a different permission, the letters after the user are that users rights, the full list is explained here:
- l - lookup_flag: mailbox is visible to LIST/LSUB commands
- r - read_flag: SELECT the mailbox, perform CHECK, FETCH, PARTIAL SEARCH, COPY from mailbox
- s - seen_flag: keep seen/unseen information across session
- w - write_flag: STORE flags other than SEEN and DELETED
- i - insert_flag: perform APPEND, COPY into mailbox
- p - post_flag: send mail to submission address for mailbox
- c - create_flag: CREATE new sub-mailboxes in any implementation defined hierarchy
- d - delete_flag: STORE DELETED flag perform EXPUNGE
- a - administer_flag: perform SETACL
Wednesday, June 10, 2009
How to add a man doc manually
$export MANPATH=$MANPATH:/the/path/of/the/man/page/
Dont keep any space on either sides of "=" as it gives error as
"bash: export: `=': not a valid identifier".
To add permanently, you need to make changes in /etc/login.defs file. I am looking into it and will update this post as soon as i come to know of it

