<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Lindesk &#187; customize</title>
	<atom:link href="http://lindesk.com/tag/customize/feed/" rel="self" type="application/rss+xml" />
	<link>http://lindesk.com</link>
	<description>Linux - on the Desktop</description>
	<lastBuildDate>Tue, 23 Jun 2009 14:03:08 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Customizing the Terminal: Create Useful Aliases</title>
		<link>http://lindesk.com/2009/03/customizing-the-terminal-create-useful-aliases/</link>
		<comments>http://lindesk.com/2009/03/customizing-the-terminal-create-useful-aliases/#comments</comments>
		<pubDate>Fri, 27 Mar 2009 19:05:56 +0000</pubDate>
		<dc:creator>BinnyVA</dc:creator>
				<category><![CDATA[Command Line]]></category>
		<category><![CDATA[Configuration]]></category>
		<category><![CDATA[alias]]></category>
		<category><![CDATA[cli]]></category>
		<category><![CDATA[command]]></category>
		<category><![CDATA[customize]]></category>
		<category><![CDATA[terminal]]></category>

		<guid isPermaLink="false">http://lindesk.com/?p=183</guid>
		<description><![CDATA[This is part two of the 'Customizing the Terminal' series. Part one is '<a href="http://lindesk.com/2009/03/customizing-the-terminal-the-prompt/">Customizing the Terminal: The Prompt</a>'. In this part, we'll see how to create aliases to make working in the console easier.]]></description>
			<content:encoded><![CDATA[<p><img src="http://lindesk.com/wp-content/uploads/2008/02/terminal.png" alt="Terminal" title="Terminal" width="128" height="128" class="alignnone size-full wp-image-96 intro" align="right" /></p>
<p class="intro">This is part two of the &#8216;Customizing the Terminal&#8217; series. Part one is &#8216;<a href="http://lindesk.com/2009/03/customizing-the-terminal-the-prompt/">Customizing the Terminal: The Prompt</a>&#8216;. In this part, we&#8217;ll see how to create aliases to make working in the console easier.</p>
<h2>How To Create an Alias</h2>
<p>You can create a temporary alias using this command&#8230;</p>
<pre><code class="bash">alias new_name='old command'</code></pre>
<p>This will stop working when you exit the terminal. If you want to make the alias permanent, put the same command in your <code>~/.bashrc</code> file.</p>
<p>There is another way to create an alias &#8211; create a executable file and place it in a folder in your path. This is not technically an alias &#8211; but it works the same way. I use this for alias that tend to change often. Its easier to find a file in a folder and edit it. <abbr title="YMMV">YMMV</abbr>.</p>
<h2>My Aliases</h2>
<p>This is a incomplete list of the aliases I use. Feel free to copy them to your .bashrc file.</p>
<h3>Quick Directory Jumps</h3>
<p>Create an alias to jump to folders you have to visit often. This is my list&#8230;</p>
<pre><code class="bash">alias www='cd /var/www/html'
alias e='cd /mnt/x'</code></pre>
<h4>Relative Jumps</h4>
<p>The above jumps are absolute jumps &#8211; relative jumps are possible too&#8230;</p>
<pre><code class="bash">alias ..='cd ..'
alias ...='cd ../..'
alias ....='cd ../../..'
alias .....='cd ../../../..'</code></pre>
<p>Some prefer this syntax&#8230;</p>
<pre><code class="bash">alias ..='cd ..'
alias ..2='cd ../..'
alias ..3='cd ../../..'
alias ..4='cd ../../../..'</code></pre>
<h3>Often Used Commands</h3>
<p>If you use some commands a lot, create smaller alternative for it&#8230;</p>
<pre><code class="bash">alias x='exit'
alias q='exit'
alias rmdir='rm â€“rf'</code></pre>
<p>Many of my own scripts are also alias&#8217;ed this way&#8230;</p>
<pre><code class="bash">alias bk='perl "/home/binnyva/Scripts/Perl/Maintenance/<a href="http://lindesk.com/2008/05/shell-script-to-backup-files-locally-using-rsync/">Rsync Backup/RsyncBackup</a>.pl"'
alias rbk='perl "/home/binnyva/Scripts/Perl/Maintenance/<a href="http://lindesk.com/2008/06/script-to-backup-files-over-a-network-using-rsync/">Rsync Backup/RsyncRemoteBackup</a>.pl"'
alias nbk='perl "/home/binnyva/Scripts/Perl/Maintenance/Rsync Backup/RsyncNetworkBackup.pl"'
alias bdb='perl "/home/binnyva/Scripts/Perl/Maintenance/<a href="http://lindesk.com/2008/06/perl-script-to-backup-mysql-databases/">Database Backup/Dbbackup</a>.pl"'</code></pre>
<h3>Complex Commands</h3>
<p>Create a short version of long and complex command using alias&#8230;</p>
<pre><code class="bash">alias gitstat='git status | perl -pe "exit if(/Untracked files\:/)"'
alias ra='ruby script/server'
alias wikipedia='cd /mnt/x/Data/Wikipedia/mywiki; firefox "http://localhost:8001/"; python manage.py runserver 8001; '
alias sup='svn update'</code></pre>
<p>and more.</p>
<h3>Command Changes</h3>
<p>When I came from Windows to Linux, I was used to the dos commands &#8211; but not to the linux&#8217;s mv,cp commands. So I used to have aliases for those(I don&#8217;t have these now)</p>
<pre><code class="bash">alias move='mv'
alias copy='cp'
alias ren='mv'
alias del='rm'</code></pre>
<p>If you go from Red Hat/Fedora to Debian/Ubuntu(or vise versa), you can set up a few alias to make the change easier&#8230;</p>
<pre><code class="bash">alias yum='apt-get'</code></pre>
<p>You can get a lot of ideas for more aliases by looking at <a href="http://dotfiles.org/.bashrc">others .bashrc files</a>.</p>
<p>Now tell me you aliases&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://lindesk.com/2009/03/customizing-the-terminal-create-useful-aliases/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Customizing the Terminal: The Prompt</title>
		<link>http://lindesk.com/2009/03/customizing-the-terminal-the-prompt/</link>
		<comments>http://lindesk.com/2009/03/customizing-the-terminal-the-prompt/#comments</comments>
		<pubDate>Tue, 10 Mar 2009 18:04:13 +0000</pubDate>
		<dc:creator>BinnyVA</dc:creator>
				<category><![CDATA[Command Line]]></category>
		<category><![CDATA[Configuration]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[command]]></category>
		<category><![CDATA[customize]]></category>
		<category><![CDATA[prompt]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[terminal]]></category>

		<guid isPermaLink="false">http://lindesk.com/?p=181</guid>
		<description><![CDATA[Most Linux 'gurus' spend a lot of time working in the terminal. If you belong to that group, this post is for you. This is a tutorial to configure the terminal prompt to the best possible value for your use. Note: This tutorial is for bash users - these instructions will not work in other shells.]]></description>
			<content:encoded><![CDATA[<p><img src="http://lindesk.com/wp-content/uploads/2008/02/terminal.png" alt="Terminal" title="Terminal" width="128" height="128" class="alignnone size-full wp-image-96 intro" align="right" /></p>
<p class="intro">Most Linux &#8216;gurus&#8217; spend a lot of time working in the terminal. If you belong to that group, this post is for you. This is a tutorial to configure the terminal prompt to the best possible value for your use. Note: This tutorial is for bash users &#8211; these instructions will not work in other shells.</p>
<h2>The Prompt</h2>
<p>You must have seen the prompt if you have use the terminal &#8211; it is the first few characters in each line. Usually, it will be&#8230;</p>
<pre><code class="bash">[username@localhost] ~ $</code></pre>
<p>In this case, the user is shown three piece of information in the prompt &#8211; </p>
<ul>
<li>Username of the current user</li>
<li>Hostname</li>
<li>Current folder name</li>
</ul>
<p>This post will show you how to customize this prompt to your needs.</p>
<h3>Editing the Prompt</h3>
<p>Editing the prompt is very simple &#8211; you just have to edit a shell variable. To see the current prompt&#8217;s value, open a shell and type the command&#8230;</p>
<pre><code class="bash">echo $PS1</code></pre>
<p>The result will be something like this(in Ubuntu)&#8230;</p>
<pre><code class="bash">binnyva@binlap:~$ echo $PS1
\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\u@\h:\w\$</code></pre>
<p>Which is functionally the same as&#8230;</p>
<pre><code class="bash">\u@\h:\W\$ </code></pre>
<p>To edit this variable, run the command&#8230;</p>
<pre><code class="bash">export PS1=&lt;New Prompt Value&gt;</code></pre>
<p>Most desktop systems don&#8217;t need the username and hostname in the prompt &#8211; this is only relevent if your are connected to a remote system. So the first thing to do, if you are on a desktop system, is to remove those two. To do that, run the command&#8230;</p>
<pre><code class="bash">export PS1="[\W]\$ "</code></pre>
<p>This will change the prompt in the current terminal. To make it permanent, edit the ~/.bashrc and set the PS1 variable there. Just add this line at the end of the file&#8230;</p>
<pre><code class="bash">export PS1="[\W]\$ "</code></pre>
<h2>A Better Prompt</h2>
<p>Currently, the prompt has the basename of the current working directory. That is, if we are in &#8216;~/Sites/Lindesk/posts&#8217;, the prompt will be &#8216;[posts]$ &#8216;. This is good enough for most people. But I have a problem with this. If I go to another folder, say, &#8216;~/Sites/<a href="http://www.openjs.com/">OpenJS</a>/posts&#8217;, the prompt is still &#8216;[posts]$ &#8216;. The prompt is a bit ambiguous in this case. This can be done using a different character &#8211; in this case \w(small &#8216;w&#8217; &#8211; the default was capital &#8216;W&#8217;).</p>
<pre><code class="bash">[posts]$ export PS1="[\w]$ "
[~/Sites/OpenJS/posts]$ _</code></pre>
<p>This is nice &#8211; but you will have a problem if the directory you are in is several levels deep. It might be something like this&#8230;</p>
<pre><code class="bash">[/var/www/html/sites/Lindesk/lindesk.com/wp-content/plugins/eventr/langs]$ _</code></pre>
<p>That&#8217;s long &#8211; and inconvenient. There are better ways of doing this.</p>
<h3>Show the Beginning and the End.</h3>
<p>A better way of doing this is to cut of a part of the folder &#8211; so the above path will look something like&#8230;</p>
<pre><code class="bash">[/var/www/html.../eventr/langs] $ _</code></pre>
<p>This option will show the first 15 characters of the path and then the last 15 characters &#8211; if the directory path is bigger than 30 characters. To enable this mode, open up the file <code>~/.bashrc</code> and add this code&#8230;</p>
<pre><code class="bash">PROMPT_COMMAND='DIR=`pwd|sed -e "s!$HOME!~!"`; if [ ${#DIR} -gt 30 ]; then CurDir=${DIR:0:12}...${DIR:${#DIR}-15}; else CurDir=$DIR; fi'
PS1="[\$CurDir] \$ "</code></pre>
<h3>The First Character of Each Directory</h3>
<p>There is yet another method &#8211; I got this idea from the <a href="http://lindesk.com/2007/04/fishfriendly-interactive-shell/">fish shell</a>. In this approach, the big path will appear as&#8230;</p>
<pre><code class="bash">[/v/w/h/s/L/l/w/p/e/langs] $ _</code></pre>
<p>In this option, only the first character of each parent folder will be shown. Only the base folder name will be shown entirely. This is the approach I use. If you want to use this, open the <code>~/.bashrc</code> file and add this&#8230;</p>
<pre><code class="bash">PROMPT_COMMAND='CurDir=`pwd|sed -e "s!$HOME!~!"|sed -re "s!([^/])[^/]+/!\1/!g"`'
PS1="[\$CurDir] \$ "</code></pre>
<h3>Prompt Variables</h3>
<p>The other values you can insert into the prompt are&#8230;</p>
<dl>
<dt>\d</dt>
<dd>the date in &#8220;Weekday Month Date&#8221; format (e.g., &#8220;Tue May 26&#8243;)</dd>
<dt>\D{format}</dt>
<dd>the format is passed to strftime(3) and the result is inserted into the prompt string; an empty format results in a locale-specific time representation. The braces are required</dd>
<dt>\e</dt>
<dd>an ASCII escape character (033)</dd>
<dt>\h</dt>
<dd>the hostname up to the first â€˜.â€™</dd>
<dt>\H</dt>
<dd>the hostname</dd>
<dt>\j</dt>
<dd>the number of jobs currently managed by the shell</dd>
<dt>\l</dt>
<dd>the basename of the shellâ€™s terminal device name</dd>
<dt>\n</dt>
<dd>newline</dd>
<dt>\r</dt>
<dd>carriage return</dd>
<dt>\s</dt>
<dd>the name of the shell, the basename of $0 (the portion following the final slash)</dd>
<dt>\t</dt>
<dd>the current time in 24-hour HH:MM:SS format</dd>
<dt>\T</dt>
<dd>the current time in 12-hour HH:MM:SS format</dd>
<dt>\@</dt>
<dd>the current time in 12-hour am/pm format</dd>
<dt>\A</dt>
<dd>the current time in 24-hour HH:MM format</dd>
<dt>\u</dt>
<dd>the username of the current user</dd>
<dt>\v</dt>
<dd>the version of bash (e.g., 2.00)</dd>
<dt>\V</dt>
<dd>the release of bash, version + patch level (e.g., 2.00.0)</dd>
<dt>\w</dt>
<dd>the current working directory, with $HOME abbreviated with a tilde</dd>
<dt>\W</dt>
<dd>the basename of the current working directory, with $HOME abbreviated with a tilde</dd>
<dt>\!</dt>
<dd>the history number of this command</dd>
<dt>\#</dt>
<dd>the command number of this command</dd>
<dt>\$</dt>
<dd>if the effective UID is 0, a #, otherwise a $</dd>
<dt>\nnn</dt>
<dd>the character corresponding to the octal number nnn</dd>
<dt>\\</dt>
<dd>a backslash</dd>
<dt>\[</dt>
<dd>begin a sequence of non-printing characters, which could be used to embed a terminal control sequence into the prompt</dd>
<dt>\]</dt>
<dd>end a sequence of non-printing characters</dd>
</dl>
]]></content:encoded>
			<wfw:commentRss>http://lindesk.com/2009/03/customizing-the-terminal-the-prompt/feed/</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
	</channel>
</rss>
