redet – build regular expression (regex) for any program.

2010-06-04 1 min read Fedora

Even if someone is  a regex guru there are times that people get confused with some regular expression and want to either test it out or want to some help. Behold, redet is here. Lets start with installing redet:

sudo yum install redet

Once you are done with installation, just run it with redet. First you need to load the sample data, select your program and then enter the regex to test it out. Here are some screenshots to get you started.

Continue reading

Modifying the <dot>bashrc or bash startup files.

2010-06-03 20 min read Linux

Find the article <a href="http://blog.infinitered.com/entries/show/4">here.

Copy here:<div class="entrybody">

If you&#8217;ve been learning the <a set="yes" linkindex="8" href="http://en.wikipedia.org/wiki/Command_line_interface" title="Wikipedia Entry: Command line interface">command-line and you have the basics down (you should be, as the most effective way to use a computer is a combination of a GUI and command-line), the next step is to customize your environment.<div class="info_box">

<span class="info_box_title">Beginner&#8217;s Tip: &#8221;command-line&#8221; and &#8221;shell&#8221; are often used synonymously. In unix, technically speaking, the shell is what processes the command-line, but usually, they mean the same thing

The ability to fully customize your <a set="yes" linkindex="9" href="http://en.wikipedia.org/wiki/Unix_shell" title="Wikipedia Entry: Unix Shell (computing)">shell is one of the most powerful things about the command-line. It&#8217;s a dry subject, and mastering it won&#8217;t get you favors from the opposite sex (although it should), but it can be very useful.

There are many ways to customize your shell, but the first one you should learn is modifying your <a linkindex="10" href="http://en.wikipedia.org/wiki/bash" title="Wikipedia Entry: bash">Bash startup files (assuming your shell is Bash, which is the default in OS X, Linux, and many other unices).

When I first learned how to customize bash, I found an overwhelming amount of information and opinion, which made it difficult. This article is intended to give you the fundamental concepts so that you can create your own startup files, and understand how they work. To give you an example, I go through a subset of my own files, section by section.

Let&#8217;s install the example startup files<div class="info_box">

<span class="info_box_title">Beginner&#8217;s Tip: Directory and folder are synonymous. Often folder is used in Windows and OS X and directory is used in Linux, however even Linux represents a directory as a folder graphically

Below are the two example startup files: .bashrc and .bash_profile.

If you would like to use these as your startup files, follow the following directions for your OS.

OS X:

  1. If you want a backup of your existing files, use the following commands (if the files don&#8217;t already exist, you will get an error. The files will be named .bashrc_ORIGINAL and .bash_profile_ORIGINAL in your home folder):<pre class="textmate-source">cp ~/.bashrc ~/.bashrc_ORIGINAL ; cp ~/.bash_profile ~/.bash_profile_ORIGINAL

  2. Copy <a linkindex="11" href="http://www.infinitered.com/settings/dotfiles/osx/.bash_profile">.bash_profile and <a linkindex="12" href="http://www.infinitered.com/settings/dotfiles/osx/.bashrc">.bashrc to your home folder.
    There are a variety of ways to do this, but the simplest is to use the <a linkindex="13" href="http://en.wikipedia.org/wiki/cURL" title="Wikipedia Entry: cURL">curl command:<pre class="textmate-source">curl -o ~/.bash#1 "http://www.infinitered.com/settings/dotfiles/osx/.bash{rc,_profile}"

  3. You do not need to log out, just create a new window or tab in iTerm, or a new window in Terminal.

Linux and other unices:

  1. If you want a backup of your existing files, use the following commands (if the files don&#8217;t already exist, you will get an error. The files will be named .bashrc_ORIGINAL and .bash_profile_ORIGINAL in your home folder):<pre class="textmate-source">cp ~/.bashrc ~/.bashrc_ORIGINAL ; cp ~/.bash_profile ~/.bash_profile_ORIGINAL

  2. Copy <a linkindex="14" href="http://www.infinitered.com/settings/dotfiles/generic/.bash_profile">.bash_profile and <a linkindex="15" href="http://www.infinitered.com/settings/dotfiles/generic/.bashrc">.bashrc to your home directory.
    There are a variety of ways to do this, but the simplest is to use the <a linkindex="16" href="http://en.wikipedia.org/wiki/Wget" title="Wikipedia Entry: Wget">wget (or curl for BSD and others) commands:<pre class="textmate-source">wget -O ~/.bashrc "http://www.infinitered.com/settings/dotfiles/generic/.bashrc"

wget -O ~/.bash\_profile \"http://www.infinitered.com/settings/dotfiles/generic/.bash\_profile\"</pre> 
**or** <pre class=\"textmate-source\">curl -o ~/.bash#1 \"http://www.infinitered.com/settings/dotfiles/generic/.bash{rc,_profile}\"</pre> 
  1. Log out then log back in in order to load .bash_profile. Alternatively, you can do a source ~/.bash_profile to run the files.

What the heck are bash Startup Files?<div class="info_box">

<span class="info_box_title">Beginner&#8217;s Tip: ~ represents your home folder, it is short-hand notation so that you don&#8217;t have to type the whole thing; it is also used when you don&#8217;t know the home folder; for example, my code above works, no matter where your home folder/directory is.

<a linkindex="17" href="http://en.wikipedia.org/wiki/bash" title="Wikipedia Entry: bash">Bash, as well as other <a linkindex="18" href="http://en.wikipedia.org/wiki/Unix_shell" title="Wikipedia Entry: Unix shell">unix shells, have files that run when they start. You can modify these files to set preferences, create aliases and functions (a kind of micro-script), and other such fun.

When you start an interactive shell (log into the console, open terminal/xterm/iTerm, or create a new tab in iTerm) the following files are read and run, in this order:

  1. /etc/profile
  2. /etc/bashrc
  3. ~/.bash_profile
  4. ~/.bashrc (Note: only if you call it in .bash_profile or somewhere else)

When an interactive shell, that is not a login shell, is started (when you call &#8221;bash&#8221; from inside a login shell, or open a new tab in Linux) the following files are read and executed, in this order:

  1. /etc/bashrc
  2. ~/.bashrc<div class="info_box"><span class="info_box_title">Beginner&#8217;s Tip: Normally you can&#8217;t see the . files (files that start with a period) because they are hidden. Depending on your OS, you can simply turn on hidden files. Another option is to open the file in the command-line. Here are a few examples:

In shell: pico .bashrc
In shell: vi .bashrc
In OS X: open .bashrc
In GNOME: gedit .bashrc

/etc/profile and /etc/bashrc are run for all users on the system. Often on your workstation, there is only one user, you. But in systems with more than one user, these files can be used to set generic settings for all users. The files in your home folder, ~/.bashrc and ~/.bash_profile, are only for your particular user (since /etc/bashrc is run before ~/.bashrc, you can override anything in /etc/bashrc by simply setting it again in ~/.bashrc). Normally I only change these, since they are in your home folder, and only you have rights to them, you can change them without worry of affecting anyone else.

When your session starts, these files are run, just as if you typed the commands in yourself. Anything that normally works in the shell works in these files. Since .bash_profile only runs when you first login, you set very little there; the only important thing is your <a linkindex="19" href="http://www.linfo.org/path_env_var.html" title="Path definition">PATH. bashrc is where the meat goes, and will be where you spend all your time.

Continue reading

let a cow tell you your fortune

2010-06-03 1 min read Bash Linux
Here\’s something that I saw on commandlinefu yesterday. That sent me thinking about some command to have the cow file picked randomly 🙂 So, here\’s the original command from the commandlinefu:

let a cow tell you your fortune

    <td>
      <div class="text codecolorer">
        $ fortune | <a class="zem_slink freebase/en/cowsay" title="Cowsay" rel="homepage" href="http://www.nog.net/%7Etony/warez/cowsay.shtml">cowsay</a> -f tux
      </div>
    </td>
  </tr>
</table>

Checking the links to your site (from affiliates) using cron and bash script.

2010-05-27 2 min read Fedora Learning Linux Uncategorized

If you have some affiliate links and are concerned about their presence then you can setup <a class="zem_slink freebase/guid/9202a8c04000641f80000000045c9c5b" title="Cron" rel="wikipedia" href="http://en.wikipedia.org/wiki/Cron">cron to check the links for you regularly. For this you need a very simple script (as below) and a cron entry (example further down).

#!/bin/bash –
#===============================================================================

#          FILE:  checklinks.sh

#         USAGE:  ./checklinks.sh

#   DESCRIPTION:  Check if the links exists on affiliate sites

#       OPTIONS:  —
#  REQUIREMENTS:  —
#          BUGS:  —
#         NOTES:  —
#        AUTHOR:  <a class="zem_slink" title="Amit Agarwal" rel="homepage" href="http://amit-agarwal.co.in">Amit Agarwal (AKA), amit.agarwal@amit-agarwal.co.in
#       COMPANY:  Individual
#       VERSION:  1.0
#       CREATED:  04/07/2010 08:19:29 AM IST
#      REVISION:  —
#===============================================================================

Continue reading

Pimp your ls

2010-05-27 1 min read Bash

Here are some of the things that you can do with your ls command.

First off you can use alias&#8217;s to help you type the most typical ls commands. I will give you some examples:

alias ls =&#8221;ls –color –classify&#8221;
alias ls.=&#8221;ls -d .*&#8221;

Very commonly used :

1
  <td>
    <div class="text codecolorer">
      alias ll="ls -lhvrt"<br /> lsd="ls -lUd */" # List directories only
    </div>
  </td>
</tr>
1
2

And after all this you can download the l script from pixelbeat. Quite interesting:

Continue reading

Filename handling with space and newline character.

2010-05-25 1 min read Linux

<a target="_blank" href="http://www.andreaplanet.com/andreamosaic/download/">
<a href="http://calypso.tux.org/pipermail/novalug/2009-February/017524.html">[Novalug] Filename handling: correctness vs. convenience has a nice post from Michael Henry on Filename handling.

Menu driven ssh.

2010-05-24 1 min read Bash

I have quite a lot of servers where I need to ssh at workplace and I generally don&#8217;t remember all of them, so I wrote a simple yet useful script. In all the servers I have already copied my key so I dont need a password to login. Without much ado, here is the script.

echo &#8221;Enter the server name:&#8221;
echo &#8221;1. redhat&#8221;
echo &#8221;2. fedora&#8221;

read server

if [ &#8221;$server&#8221; = &#8221;1&#8221; ]; then
ssh amit@redhat
else if [ &#8221;$server&#8221; = &#8221;2&#8221; ]; then
ssh amit@fedora
else
echo &#8221;Not a valid choice&#8221;
fi
fi

Continue reading
Older posts Newer posts