<?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>TuxArena &#187; bash</title>
	<atom:link href="http://www.tuxarena.com/tag/bash/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.tuxarena.com</link>
	<description>Ubuntu/Debian/Mint news and tutorials &#124; Linux stuff</description>
	<lastBuildDate>Sat, 11 May 2013 13:35:05 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>Tutorial: How to Color Man Pages &amp; How It Works</title>
		<link>http://www.tuxarena.com/2012/04/tutorial-colored-man-pages-how-it-works/</link>
		<comments>http://www.tuxarena.com/2012/04/tutorial-colored-man-pages-how-it-works/#comments</comments>
		<pubDate>Sun, 01 Apr 2012 16:08:05 +0000</pubDate>
		<dc:creator>Craciun Dan</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[cli]]></category>
		<category><![CDATA[terminal]]></category>

		<guid isPermaLink="false">http://www.tuxarena.com/?p=2066</guid>
		<description><![CDATA[In this tutorial I&#8217;ll show how to get some nicely colored man pages by adding several lines inside the .bashrc file, explaining what the code means and how it works. Except for the eye-candy, colors may help when it comes to clarity, although some prefer the default monochrome approach. At the start of this article [...]]]></description>
				<content:encoded><![CDATA[<p>In this tutorial I&#8217;ll show how to get some nicely colored man pages by adding several lines inside the .bashrc file, explaining what the code means and how it works.</p>
<p><a href="http://www.tuxarena.com/wp-content/uploads/2012/04/colored_man_pages.png"><img src="http://www.tuxarena.com/wp-content/uploads/2012/04/colored_man_pages-640x357.png" alt="" title="colored_man_pages" width="640" height="357" class="aligncenter size-large wp-image-2096" /></a></p>
<p><span id="more-2066"></span></p>
<p>Except for the eye-candy, colors may help when it comes to clarity, although some prefer the default monochrome approach. At the start of this article there is the actual code which can be copied and pasted inside the ~/.bashrc file, and which can be modified depending on each person&#8217;s preferences. If you don&#8217;t care about what it does you can just insert it in ~/.bashrc, restart your terminal and start reading some man pages to see how it looks (e.g. man man). After this part I tried to explain how this code works and how to modify it in order to get new &#8216;themes&#8217;.</p>
<div class="subtitle">The code</div>
<p>For this tutorial we&#8217;ll be editing the ~/.bashrc file, which is a hidden file located in your home directory which gets read each time a new Bash instance starts up. Bash reads all the commands found in this file and executes them (hence the <b>rc</b> part, which stands for <b>r</b>un <b>c</b>ommands).</p>
<p>We will edit this file and add some lines which specify certain colors for the $LESS_TERMCAP variables.</p>
<div class="code">
export LESS_TERMCAP_mb=$(printf &#8216;\e[01;31m&#8217;) # enter blinking mode &#8211; red<br />
export LESS_TERMCAP_md=$(printf &#8216;\e[01;35m&#8217;) # enter double-bright mode &#8211; bold, magenta<br />
export LESS_TERMCAP_me=$(printf &#8216;\e[0m&#8217;) # turn off all appearance modes (mb, md, so, us)<br />
export LESS_TERMCAP_se=$(printf &#8216;\e[0m&#8217;) # leave standout mode<br />
export LESS_TERMCAP_so=$(printf &#8216;\e[01;33m&#8217;) # enter standout mode &#8211; yellow<br />
export LESS_TERMCAP_ue=$(printf &#8216;\e[0m&#8217;) # leave underline mode<br />
export LESS_TERMCAP_us=$(printf &#8216;\e[04;36m&#8217;) # enter underline mode &#8211; cyan
</div>
<p>Don&#8217;t forget to reset your terminal after entering this code in order for the changes to take effect, e.g. type <b>reset</b> or <b>exit</b> and start up another shell.</p>
<p>This will mostly use magenta and cyan as the colors. Next, I&#8217;ll explain what these lines mean and how you can modify the colors.</p>
<div class="subtitle">Explaining it</div>
<p>As you can see, there are several variables which are assigned different values. As shown in the comments after the # sign, every one is used when needed. When text is in bold (double-bright mode), the formatting option is set to bold and the color magenta.</p>
<p>Let&#8217;s take, for example, the following line:</p>
<div class="code">
export LESS_TERMCAP_md=$(printf &#8216;\e[01;35m&#8217;) # enter double-bright mode &#8211; bold, magenta
</div>
<p>This line could be broken into this:</p>
<ul>
<li>the environment variable LESS_TERMCAP_md will be assigned the value to the right of the equal sign
<li>the right side says execute the command between the <b>$(</b> and <b>)</b> characters, just like the older <b>` `</b> did
<li>printf is a command similar with C&#8217;s printf and means &#8220;print with format&#8221;. The characters between the double quotes specify a color and a font style (e.g. in this case, bold and magenta).
</ul>
<p>The part that is inside the double quotes are format specifiers like bold, regular, or color to be used. More on these can be found on Wikipedia, <a href="http://en.wikipedia.org/wiki/ANSI_escape_code">here</a>.</p>
<div class="subtitle">Color codes</div>
<p>The color codes are as follows:</p>
<ul>
<li>30 &#8211; <font color="black">black</font>
<li>31 &#8211; <font color="red">red</font>
<li>32 &#8211; <font color="green">green</font>
<li>33 &#8211; <font color="orange">orange</font>
<li>34 &#8211; <font color="blue">blue</font>
<li>35 &#8211; <font color="magenta">magenta</font>
<li>36 &#8211; <font color="cyan">cyan</font>
<li>37 &#8211; <font color="black">white</font>
</ul>
<p>Some other escape codes which you could use include:</p>
<ul>
<li>0 &#8211; reset/normal
<li>1 &#8211; bold
<li>3 &#8211; italic/reversed
<li>4 &#8211; underlined
<li>5 &#8211; blink
</ul>
<p>You can check this by typing in a terminal something like:</p>
<div class="code">
printf &#8216;\e[31m&#8217;<br />
printf &#8216;\e[32m&#8217;<br />
printf &#8216;\e[37m&#8217;
</div>
<p>So, if we have something like <b>printf &#8216;\e[01;33m&#8217;</b> it means enter bold and color yellow, according to the listing above.</p>
<div class="subtitle">What about &#8216;export&#8217;?</div>
<p><b>export</b> is a Bash built-in used to assign values to variables in such a manner that any subsequent application that runs in that shell will be aware of the variable&#8217;s value. If, for example, we would simply assign a value to a variable, say <b>MYVAR=&#8221;this is my variable&#8221;</b> and we would then issue <b>echo $MYVAR</b>, we would see that the variable&#8217;s value will be printed. However, try to make a simple script which would echo it, for example:</p>
<div class="code">
#!/bin/bash</p>
<p>echo $MYVAR
</p></div>
<p>And then run it e.g. <b>bash myscript.sh</b> &#8211; you will see that the value is lost, not visible in the script. So this is where <b>export</b> is useful, because it will make any further script or application &#8220;see&#8221; the variable. When we invoke the <b>man</b> command, it will need to see the values for our LESS_TERMCAP variables.</p>
<div class="subtitle">More color schemes</div>
<p>Here is another color scheme:</p>
<div class="code">
export LESS_TERMCAP_mb=$(printf &#8216;\e[01;31m&#8217;) # enter blinking mode<br />
export LESS_TERMCAP_md=$(printf &#8216;\e[01;38;5;75m&#8217;) # enter double-bright mode<br />
export LESS_TERMCAP_me=$(printf &#8216;\e[0m&#8217;) # turn off all appearance modes (mb, md, so, us)<br />
export LESS_TERMCAP_se=$(printf &#8216;\e[0m&#8217;) # leave standout mode<br />
export LESS_TERMCAP_so=$(printf &#8216;\e[01;33m&#8217;) # enter standout mode<br />
export LESS_TERMCAP_ue=$(printf &#8216;\e[0m&#8217;) # leave underline mode<br />
export LESS_TERMCAP_us=$(printf &#8216;\e[04;38;5;200m&#8217;) # enter underline mode
</div>
<div class="subtitle">References</div>
<ul>
<li><a href="http://www.ibm.com/developerworks/linux/library/l-bash/index.html">http://www.ibm.com/developerworks/linux/library/l-bash/index.html</a>
<li><a href="en.wikipedia.org/wiki/ANSI_escape_code">en.wikipedia.org/wiki/ANSI_escape_code</a>
<li><a href="http://www.gnu.org/software/termutils/manual/termcap-1.3/html_mono/termcap.html">http://www.gnu.org/software/termutils/manual/termcap-1.3/html_mono/termcap.html</a>
<li><a href="https://wiki.archlinux.org/index.php/Man_Page">https://wiki.archlinux.org/index.php/Man_Page</a>
<li><a href="http://tips4linux.com/color-man-pages-in-linux/">http://tips4linux.com/color-man-pages-in-linux/</a>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.tuxarena.com/2012/04/tutorial-colored-man-pages-how-it-works/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>8 More Bash Tips for Working Faster With the Shell (Part 2 of 2)</title>
		<link>http://www.tuxarena.com/2010/12/8-more-bash-tips-for-working-faster-with-the-shell-part-2-of-2/</link>
		<comments>http://www.tuxarena.com/2010/12/8-more-bash-tips-for-working-faster-with-the-shell-part-2-of-2/#comments</comments>
		<pubDate>Thu, 23 Dec 2010 06:45:49 +0000</pubDate>
		<dc:creator>Craciun Dan</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[cli]]></category>
		<category><![CDATA[command-line]]></category>

		<guid isPermaLink="false">http://www.tuxarena.com/?p=508</guid>
		<description><![CDATA[This is the second article in this series, and brings eight additional tips for working faster with the shell. Here is the first article of the series, containing 10 tips. Create aliases for quick access to commands or one-liners Aliases are handy custom commands which can be used to make shortcuts to various commands, scripts [...]]]></description>
				<content:encoded><![CDATA[<p>This is the second article in this series, and brings eight additional tips for working faster with the shell. <a href="http://www.tuxarena.com/?p=257">Here</a> is the first article of the series, containing 10 tips.</p>
<div class="subtitle">Create aliases for quick access to commands or one-liners</div>
<p>Aliases are handy custom commands which can be used to make shortcuts to various commands, scripts or one-liners. Aliases can be added in the <b>~/.bashrc</b> file like this:</p>
<div class="code">
<pre>
alias name='command'
</pre>
</div>
<p><span id="more-508"></span><br />
Alternately, you can specify an external file and load it in .bashrc, like for example the default one, called <b>.bash_aliases</b>. Edit .bashrc and uncomment or add (if it doesn&#8217;t already exist) the following code:</p>
<div class="code">
<pre>
if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases
fi
</pre>
</div>
<p>This code checks to see if the file <b>~/.bash_aliases</b> exists, and if it does, it reads the contents from it. Here are examples of aliases and what they do:</p>
<pre><textarea cols=78 rows=6 wrap=off>
alias killfx='kill -9 $(pidof firefox-bin) # kills Firefox by sending SIGKILL using its process ID
alias upgrade='sudo apt-get update &#038;&#038; sudo apt-get upgrade' # upgrade a Ubuntu-based system
alias xterm='xterm -geometry 1280x1024' # start xterm with a custom geometry
alias src='. ~/.bash_profile' # source the ~/.bash_profile (read its contents and execute them)
alias lsh='ls -lhXG' # alias for ls to use long listing format, human readable sizes, sort and don't show groups
</textarea></pre>
<p>You can virtually define any aliases you want here. The <b>#</b> sign used after each alias means what follows is comment, it will be ignored by Bash when reading the file.</p>
<div class="subtitle">Use Page Up and Page Down to Search Through History</div>
<p>Here&#8217;s another tip. Adding the following two lines to ~/.inputrc will make PageUp and PageDown keys to search through history (if <b>~/.inputrc</b> doesn&#8217;t already exist create it):</p>
<div class="code">
<pre>
"\e[5~": history-search-backward
"\e[6~": history-search-forward
</pre>
</div>
<p>Now if you type a command followed by PageUp it will search for the last command that started with the pattern you specified.</p>
<p><i>Special thanks go to <a href="http://www.tuxarena.com/?p=257#comment-373">Alex Dekker</a> for this tip</i>.</p>
<div class="subtitle">Working with files starting with &#8220;-&#8221;</div>
<p>For this we will precede the files (or arguments) that start with &#8220;-&#8221; with &#8220;&#8211;&#8221;. For example:</p>
<div class="code">
<pre>
man gcc | grep -- -ansi
</pre>
</div>
<p>Will show only the lines which contain the pattern <b>-ansi</b> in the gcc manual page. Or:</p>
<div class="code">
<pre>
touch -- -file
rm -- -file
</pre>
</div>
<p>Will create a file called <b>-file</b> and then it will remove it. Also, <b>ls -l &#8212; -file</b> will use long listing format to show details about <b>-file</b>.</p>
<p><i>Special thanks go to <a href="http://www.tuxarena.com/?p=257#comment-284">Lawrence D&#8217;Oliveiro</a> for this tip.</i></p>
<div class="subtitle">Use Emacs-like shortcuts</div>
<p>The big advantage of these is that they use Ctrl and Alt (Meta) combination, which for a person who knows blind-typing is very useful, since he will not need to move his hand to reach keys like arrows, PgUp, PgDown, Home or End. Most of these shortcuts are used in the shell for fetching commands from history, edit text in a fast manner, or even navigate quickly in <b>less</b> pagers or in a manual page. Here are the shortcuts (^A means &#8220;press Ctrl and A at the same time&#8221;):</p>
<ul>
<li><b>^A</b> &#8211; go to the start of line
<li><b>^E</b> &#8211; go to the end of line
<li><b>^H</b> &#8211; erase one character to the left
<li><b>^D</b> &#8211; erase one character to the right, it also exits the shell by default if there is no character to delete
<li><b>^U</b> &#8211; erase everything from the cursor to start
<li><b>^K</b> &#8211; erase everything from the cursor to end
<li><b>^P</b> &#8211; bring the previous command in history
<li><b>^N</b> &#8211; bring the next command in history
<li><b>^C</b> &#8211; interrupt character, sends SIGTERM to the current application
</ul>
<div class="subtitle">Colored manual pages</div>
<p>Colored manual pages can really make text clearer and easier to read. Here&#8217;s a snippet I took from the web a while ago (I really don&#8217;t remember the address where I found this particular customization scheme &#8211; could it be from <a href="http://forums.opensuse.org/english/development/programming-scripting/414983-color-man-pages.html">here</a>?). Put the following inside <b>~/.bashrc</b>:</p>
<div class="code">
<pre>
export LESS_TERMCAP_mb=$'\E[01;31m' # begin blinking
export LESS_TERMCAP_md=$'\E[01;38;5;74m' # begin bold
export LESS_TERMCAP_me=$'\E[0m' # end mode
export LESS_TERMCAP_se=$'\E[0m' # end standout-mode
export LESS_TERMCAP_so=$'\E[38;5;246m' # begin standout-mode - info box
export LESS_TERMCAP_ue=$'\E[0m' # end underline
export LESS_TERMCAP_us=$'\E[04;38;5;146m' # begin underline
</pre>
</div>
<p>And then source your .bashrc file:</p>
<div class="code">
<pre>
. ~/.bashrc
</pre>
</div>
<p>Here&#8217;s how the manual pages will look now:</p>
<div class="blank"></div>
<p><a href="http://www.tuxarena.com/wp-content/uploads/2010/12/colored_man_pages.png"><img src="http://www.tuxarena.com/wp-content/uploads/2010/12/colored_man_pages-300x177.png" alt="" title="colored_man_pages" width="300" height="177" class="aligncenter size-medium wp-image-530" /></a></p>
<div class="subtitle">Copy/paste with Shift+Insert</div>
<p>This is yet another tip for working faster using either Shift+Insert or the middle mouse button. They both do the same thing: enter text from the clipboard in either the command-line or a shell text editor, like Nano (also works in Emacs, together with ^Y).</p>
<div class="subtitle">Using your custom-made scripts</div>
<p>With only basic Bash knowledge you can create your own time-savers scripts, or just fun ones. I have my own scripts inside the <b>~/bin</b> directory, which is included in my $PATH. For example, here is a greeting script:</p>
<div class="code">
<pre>
echo "Welcome to the dark side of the moon, $USER!"
echo 'System uptime:'
uptime
cal
</pre>
</div>
<p>Save it with a suggestive name, say <b>greeting.sh</b> and put it inside ~/bin. Now edit your <b>~/.bashrc</b> file and add the following line:</p>
<div class="code">
<pre>
. ~/bin/greeting.sh # or "source ~/bin/greeting.sh"
</pre>
</div>
<p>Now open a new shell to see the new greeting, or just source your ~/.bashrc file:</p>
<div class="code">
<pre>
. ~/.bashrc
</pre>
</div>
<p>Here&#8217;s how this looks like on my system:</p>
<div class="blank"></div>
<p><a href="http://www.tuxarena.com/wp-content/uploads/2010/12/bash_greeting.png"><img src="http://www.tuxarena.com/wp-content/uploads/2010/12/bash_greeting-300x85.png" alt="" title="bash_greeting" width="300" height="85" class="aligncenter size-medium wp-image-537" /></a></p>
<div class="subtitle">Create backup files faster</div>
<p>This tip can be used with virtually any command, since Bash will expand it, but it&#8217;s very useful for creating backup files. Say you have a filename called <b>very_long_filename</b>. To rename it you would normally do something like <b>mv very_long_filename very_long_filename.backup</b>. But here&#8217;s how to do it faster:</p>
<div class="code">
<pre>
mv very_long_filename{,.backup}
</pre>
</div>
<p>Bash will expand this command into the one showed above, and then execute it.</p>
<div class="blank"></div>
<p>Do you have some more additions to this? Please feel free to use the comments below and share them with us!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tuxarena.com/2010/12/8-more-bash-tips-for-working-faster-with-the-shell-part-2-of-2/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>10 Bash Tips for Working Faster With the Shell (Part 1 of 2)</title>
		<link>http://www.tuxarena.com/2010/12/10-bash-tips-for-working-faster-with-the-shell-part-1-of-2/</link>
		<comments>http://www.tuxarena.com/2010/12/10-bash-tips-for-working-faster-with-the-shell-part-1-of-2/#comments</comments>
		<pubDate>Mon, 20 Dec 2010 07:29:16 +0000</pubDate>
		<dc:creator>Craciun Dan</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[cli]]></category>
		<category><![CDATA[command-line]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://www.tuxarena.com/?p=257</guid>
		<description><![CDATA[Using !! This command is used to bring back and automatically execute the last command in history. It is the same as pressing C^P followed by Enter). Here&#8217;s an example: debian$ cat /etc/debian_version 5.0.7 debian$ !! cat /etc/debian_version 5.0.7 Using !text Replacing &#8216;text&#8217; with any command will call the last command in the history which [...]]]></description>
				<content:encoded><![CDATA[<p><strong>Using !!</strong><br />
This command is used to bring back and automatically execute the last command in history. It is the same as pressing C^P followed by Enter). Here&#8217;s an example:</p>
<pre><textarea cols="78" rows="5">debian$ cat /etc/debian_version
5.0.7
debian$ !!
cat /etc/debian_version
5.0.7
</textarea></pre>
<p><span id="more-257"></span><br />
<strong>Using !text</strong><br />
Replacing &#8216;text&#8217; with any command will call the last command in the history which starts with &#8216;text&#8217;. Example:</p>
<pre><textarea cols="78" rows="9">debian$ ls /etc/apt/
apt-file.conf  sources.list.d  trustdb.gpg  trusted.gpg~  sources.list~
apt.conf.d     secring.gpg     trusted.gpg  sources.list
debian$ pwd
/home/embryo
debian$ !ls
ls /etc/apt/
apt-file.conf  sources.list.d  trustdb.gpg  trusted.gpg~  sources.list~
apt.conf.d     secring.gpg     trusted.gpg  sources.list
</textarea></pre>
<p>As you can see after issuing the first ls command we printed the working directory, then we called back the last ls command with !ls.</p>
<p><strong>Using !n</strong><br />
This will bring up the nth command in history. This will vary depending on your history. Here&#8217;s an example:</p>
<pre><textarea cols="78" rows="7">debian$ history | grep 399
  399  cd
  562  history | grep 399
debian$ !399
cd
debian$ pwd
/home/embryo
</textarea></pre>
<p><strong>Using !?text?</strong><br />
This will execute the most recent command that contains the word &#8216;text&#8217;. Example:</p>
<pre><textarea cols="78" rows="3">debian$ !?xjf?
tar -xjf hedgewars-src-0.9.14.1.tar.bz2
tar: hedgewars-src-0.9.14.1.tar.bz2: Cannot open: No such file or directory
</textarea></pre>
<p>The most recent command containing the text &#8216;xjf&#8217; was executed. This trick should be applied carefully though, especially for sensitive commands like <strong>rm</strong>.</p>
<p><strong>Using !! in combination with another command</strong><br />
!! can also be used in combination with some other command, because the shell expands it first and then it executes the current command. For example, this can be very useful in combination with <strong>sudo</strong>, since sometimes we forget to use administrative privileges for commands that need it. For example:</p>
<pre><textarea cols="78" rows="6">debian$ apt-get update
E: Could not open lock file /var/lib/apt/lists/lock - open (13 Permission denied)
E: Unable to lock the list directory
debian$ sudo !!
sudo apt-get update
</textarea></pre>
<p><strong>Changing the color of the Bash prompt</strong><br />
There are many ways of customizing your Bash prompt, and I will list here only a few pre-defined sets.<br />
To make the user&#8217;s prompt green, put this inside your ~/.bashrc file, where ~ is your home directory:</p>
<pre><textarea cols=78 rows=2 wrap=off>
PS1='\[\e[1;32m\][\u@\h \W]\$\[\e[0m\] '
</textarea></pre>
<p>Now run <b>source ~/.bashrc</b> or <b>. ~/.bashrc</b> to read the settings again. Here&#8217;s how your prompt should look like:</p>
<p><a href="http://www.tuxarena.com/wp-content/uploads/2010/12/bash_prompt_011.png"><img src="http://www.tuxarena.com/wp-content/uploads/2010/12/bash_prompt_011.png" alt="" title="bash_prompt_01" width="530" height="52" class="aligncenter size-full wp-image-357" /></a></p>
<p>Here&#8217;s another example, which will make your prompt look really fancy:</p>
<pre><textarea cols=78 rows=2 wrap=off>
PS1='\[\e[0;32m\]\u\[\e[m\] \[\e[1;34m\]\w\[\e[m\] \[\e[1;32m\]\$\[\e[m\] \[\e[1;37m\]'
</textarea></pre>
<p>And this is how it will look like:</p>
<p><a href="http://www.tuxarena.com/wp-content/uploads/2010/12/bash_prompt_021.png"><img src="http://www.tuxarena.com/wp-content/uploads/2010/12/bash_prompt_021.png" alt="" title="bash_prompt_02" width="521" height="45" class="aligncenter size-full wp-image-358" /></a></p>
<p>A pretty good tutorial on this can be found <a href="http://networking.ringofsaturn.com/Unix/Bash-prompts.php">here</a> (Bash Prompts How-To) and several  prompt schemes on the Arch Wiki, <a href="https://wiki.archlinux.org/index.php/Color_Bash_Prompt">here</a>. The <a href="http://www.gnu.org/software/bash/manual/bashref.html#Printing-a-Prompt">Bash Reference manual section</a> on this includes some useful information too.</p>
<p><strong>Catch the exit status of a command with $?</strong><br />
If a command is successful, its exit status will be 0, otherwise it will be different from 0. This can be useful in scripts.</p>
<pre><textarea cols="78" rows="3">sudo: pam_authenticate: Conversation error
debian$ echo $?
1
</textarea></pre>
<p><strong>Using reversed search: Ctrl-R</strong><br />
Ctrl-R will prompt you to enter a pattern for a command, and will search the history in reversed order for any the first command that contains the pattern and execute it. Example</p>
<pre><textarea cols=78 rows=8>
$ ls -lh
total 16K
drwxr-xr-x 2 embryo embryo 4.0K 2010-12-19 15:12 Downloads
drwxr-xr-x 2 embryo embryo 4.0K 2010-12-19 15:12 Music
drwxr-xr-x 3 embryo embryo 4.0K 2010-12-19 19:16 myfolder
drwxr-xr-x 2 embryo embryo 4.0K 2010-12-19 15:21 my_stuff
-rw-r--r-- 1 embryo embryo    0 2010-12-19 15:21 textfile
(reverse-i-search)`-': ls -lh 
</textarea></pre>
<p>In the above example we issued the <b>ls -lh</b> command, the pressed Ctrl-R and typed in the letter L. The command was brought up and then executed with Enter.</p>
<p><strong>Using cd &#8211; to go to the previous working directory</strong><br />
This command will have the same effect as <b>cd $OLDPWD</b>, where $OLDPWD is a variable that holds the previous working directory.</p>
<pre><textarea cols=78 rows=7>
debian$ pwd
/home/embryo/myhome
debian$ cd
debian$ pwd
/home/embryo
debian$ cd -
/home/embryo/myhome
</textarea></pre>
<p><strong>Using grep -e -pattern to show the lines that start with a &#8211; sign</strong><br />
This will be useful if piped to commands like man, for example:</p>
<pre><textarea cols=78 rows=1>
$ man gcc | grep -e -ansi
</textarea></pre>
<p>This will query the manual page for <b>gcc</b> and will only print lines that contain the text <b>-ansi</b>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tuxarena.com/2010/12/10-bash-tips-for-working-faster-with-the-shell-part-1-of-2/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>TuxArena Free PDF Guide! Introduction to Linux Command-Line for Beginners</title>
		<link>http://www.tuxarena.com/2010/12/tuxarena-free-pdf-guide-introduction-to-linux-command-line-for-beginners/</link>
		<comments>http://www.tuxarena.com/2010/12/tuxarena-free-pdf-guide-introduction-to-linux-command-line-for-beginners/#comments</comments>
		<pubDate>Sun, 19 Dec 2010 18:42:03 +0000</pubDate>
		<dc:creator>Craciun Dan</dc:creator>
				<category><![CDATA[Ebooks]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[cli]]></category>
		<category><![CDATA[terminal]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.tuxarena.com/?p=338</guid>
		<description><![CDATA[The first TuxArena PDF ebook &#8220;Introduction to Linux Command-Line for Beginners&#8221; is now available completely free as a Christmas gift! You can read it online here or download the PDF version. The guide covers the following topics: What Is Linux? Basic Commands and Concepts Moving Around More Useful CLI Commands The Power of the Shell [...]]]></description>
				<content:encoded><![CDATA[<p>The first TuxArena PDF ebook &#8220;<strong>Introduction to Linux Command-Line for Beginners</strong>&#8221; is now available <strong>completely free</strong> as a Christmas gift! You can <a href="http://www.tuxarena.com/static/intro_linux_cli.php">read it online here</a> or <a href="http://www.tuxarena.com/static/tuxarena_intro_linux_cli.pdf">download the PDF version</a>.</p>
<p>The guide covers the following topics:</p>
<p><span id="more-338"></span></p>
<p>What Is Linux?<br />
Basic Commands and Concepts<br />
Moving Around<br />
More Useful CLI Commands<br />
The Power of the Shell<br />
Creating and Editing Files<br />
Linux Directory Structure<br />
Environment Variables<br />
Bash built-ins<br />
Pipes and Redirecting Output<br />
Getting Help<br />
Helpful Links &amp; Further Reading</p>
<p>This is the first release so more improvements and corrections will be added, as well as new chapters.</p>
<p>If you have suggestions or corrections to this guide, please feel free to use the comments below.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tuxarena.com/2010/12/tuxarena-free-pdf-guide-introduction-to-linux-command-line-for-beginners/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
