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>

Logwatch for Linux Systems.

2010-06-02 2 min read Fedora Linux

On my personal <a class="zem_slink freebase/en/client" title="Client (computing)" rel="wikipedia" href="http://en.wikipedia.org/wiki/Client_%28computing%29">desktop at home, I like to see the <a class="zem_slink freebase/en/statistics" title="Statistics" rel="wikipedia" href="http://en.wikipedia.org/wiki/Statistics">statistics at least once a day, for what was installed, what was run with <a class="zem_slink freebase/en/sudo" title="Sudo" rel="homepage" href="http://www.sudo.ws/">sudo and other such details like <a class="zem_slink freebase/en/kernel" title="Kernel (computing)" rel="wikipedia" href="http://en.wikipedia.org/wiki/Kernel_%28computing%29">kernel errors.

Running this monotonously every day is quite boring, so comes to rescue is logwatch. I have <a class="zem_slink freebase/en/fedora" title="Fedora" rel="homepage" href="http://fedoraproject.org/">Fedora <a class="zem_slink freebase/en/installation" title="Installation (computer programs)" rel="wikipedia" href="http://en.wikipedia.org/wiki/Installation_%28computer_programs%29">installation so I will talk about the location with respect to that so for your distribution it might be a little different.

Continue reading

phpMan: Unix Man page/ Perldoc / Info page Web Interface

2010-06-02 1 min read Linux

<a href="http://phpunixman.sourceforge.net/">Link

A web interface to browse the man pages along with perldoc or info pages for all the Linux commands.

Quite useful if you are on windows and want to quickly look at some reference for Linux command. Otherwise too quite intuitive and interesting and easy to browse.

Google staff dropping Windows for Macs, Linux PCs

2010-06-02 1 min read Linux Uncategorized
For those who keep saying this is not the year of linux and probably it will never be 🙂

Google staff dropping <a class="zem_slink freebase/en/microsoft_windows" title="Windows" rel="homepage" href="http://www.microsoft.com/WINDOWS">Windows for Macs, <a class="zem_slink freebase/en/linux" title="Linux" rel="wikipedia" href="http://en.wikipedia.org/wiki/Linux">Linux <a class="zem_slink freebase/en/personal_computer" title="Personal computer" rel="wikipedia" href="http://en.wikipedia.org/wiki/Personal_computer">PCs

Google is abandoning the use of Windows by its staff as it\’s too much of a security threat, multiple staffers said Monday night. Recent concerns about Chinese hacks have the search firm requiring either a Mac or Linux for all new recruits to provide better security. Those who want Windows now often require explicit approval from executives and may not have any choice on desktops where it\’s only an option for notebooks.
\"Reblog

Key bindings for screen command

2010-06-01 3 min read Linux

Key bindings

screen commands consist of a command character (Ctrl-a by default) followed by another character. For many of the commands, you can also specify the character as Ctrl-character–e.g., Ctrl-a Ctrl-d as well as Ctrl-a d. The default key bindings are listed here. You can change the bindings for yourself in the $HOME/.screenrc configuration file, or for all users in /etc/screenrc. The term in parentheses that follows the description is the equivalent configuration-file command for changing the key binding.

Continue reading

Deleting lines from the text file

2010-06-01 1 min read Linux

Really useful for pretty big <a class="zem_slink freebase/en/computer_file" title="Computer file" rel="wikipedia" href="http://en.wikipedia.org/wiki/Computer_file">files.

<a class="zem_slink freebase/en/sed" title="Sed" rel="wikipedia" href="http://en.wikipedia.org/wiki/Sed">sed –silent &#8217;1,100 d&#8217; <a class="zem_slink freebase/en/filename" title="Filename" rel="wikipedia" href="http://en.wikipedia.org/wiki/Filename">filename

here the command will delete the first 100 lines. You can specify whatever range you want. This will not delete the lines from the file but only display the contents on the console after deleting the 100 lines from begining.

If you want to store it in different file then you can use &#8221;>&#8221; or &#8221;»&#8221;<h6 class="zemanta-related-title">Related articles by Zemanta <ul class="zemanta-article-ul"> <li class="zemanta-article-ul-li"><a href="http://www.centernetworks.com/guhmshoo-quit-facebook-day-cartoon">Guhmshoo Looks at Quit Facebook Day (cartoon) (centernetworks.com) <li class="zemanta-article-ul-li"><a href="http://blogs.securiteam.com/index.php/archives/1374">Sometimes it&#8217;s just Windows … (blogs.securiteam.com) <li class="zemanta-article-ul-li"><a href="http://www.makeuseof.com/tag/2-ingenious-apps-to-help-organize-files-and-folders-on-your-mac/">2 Ingenious Apps To Help Organize Files and Folders On Your Mac (makeuseof.com) <li class="zemanta-article-ul-li"><a href="http://www.labnol.org/software/windows-problems-and-solutions/13766/">Simple Solutions to Common Windows Problems (labnol.org) <li class="zemanta-article-ul-li"><a href="http://techblissonline.com/bluray-dvd-cd-data-file-recovery-software-free-download/">Blu Ray/DVD/CD Data file recovery software (free) to recover damaged files (techblissonline.com) <li class="zemanta-article-ul-li"><a href="http://www.ghacks.net/2010/05/23/get-rid-of-gnome-keyring-password-reminder/">Get rid of GNOME keyring password reminder (ghacks.net) <div class="zemanta-pixie"><a class="zemanta-pixie-a" title="Reblog this post [with Zemanta]" href="http://reblog.zemanta.com/zemified/a2e0d6ba-15f8-4a53-9f52-a28012b689cb/"><img class="zemanta-pixie-img" src="http://blog.amit-agarwal.co.in/wp-content/uploads/2010/08/reblog_b93.png" alt="Reblog this post [with Zemanta]" /><span class="zem-script more-related more-info pretty-attribution paragraph-reblog">

Continue reading
1