<?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>Chris JeanChris Jean &#187; command line</title>
	<atom:link href="http://chrisjean.com/tag/command-line/feed/" rel="self" type="application/rss+xml" />
	<link>http://chrisjean.com</link>
	<description>Linux, WordPress, programming, anime, and other stuff</description>
	<lastBuildDate>Tue, 08 May 2012 20:36:53 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Updating Multiple Git Repositories Easily Using Bash for Loop</title>
		<link>http://chrisjean.com/2009/09/15/updating-multiple-git-repositories-easily-using-bash-for-loop/</link>
		<comments>http://chrisjean.com/2009/09/15/updating-multiple-git-repositories-easily-using-bash-for-loop/#comments</comments>
		<pubDate>Tue, 15 Sep 2009 16:42:14 +0000</pubDate>
		<dc:creator>Chris Jean</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Tips 'n Tricks]]></category>
		<category><![CDATA[command line]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[Mastering The Command Line]]></category>

		<guid isPermaLink="false">http://gaarai.com/?p=1508</guid>
		<description><![CDATA[All of the WordPress themes that I work on for iThemes are managed as Git repositories. Recently, we moved past the 100 repositories mark. That&#8217;s a lot of repositories to manage, and unfortunately, too many of those repositories contain duplicated information. Later on, I might delve into how we use Git to manage our theme [...]]]></description>
			<content:encoded><![CDATA[<!-- filtered -->
<p>All of the <a href="http://wordpress.org/" target="_blank">WordPress</a> themes that I work on for <a href="http://ithemes.com/" target="_blank">iThemes</a> are managed as Git repositories. Recently, we moved past the 100 repositories mark. That&#8217;s a lot of repositories to manage, and unfortunately, too many of those repositories contain duplicated information.</p>
<p>Later on, I might delve into how we use Git to manage our theme repos. For today, however, I&#8217;d like to focus on how I quickly and easily pushed up changes to more than a dozen repos in a single, albeit long, Bash command.</p>
<p>I had finished making updates to 16 <a href="http://ithemes.com/purchase/flexx-theme-wordpress-blog-themes/" target="_blank">Flexx</a> repos, and I needed to push all of those changes up. Since I had multiple working repos in that folder, I was lucky that each of these repos began with the text &#8220;Flexx&#8221;. Also, since they are all part of the same series and need to keep the same version number, that simplified the tagging as all could be tagged as 2.5.0.</p>
<p>Given this information, I simply ran the following command from the directory that contained all the repository directories:</p>
<div class="code">for i in `ls|grep Flexx`; do echo &#8220;&#8212; Pushing $i&#8221;; cd $i; git commit -am &#8217;2.5.0&#8242; &amp;&amp; git push &amp;&amp; git tag 2.5.0 &amp;&amp; git push &#8211;tags; cd ..; echo &#8220;&#8212; Finished $i&#8221;; done</div>
<p>There&#8217;s a lot going on here, so I&#8217;ll break it up and explain what I&#8217;m doing.</p>
<p><span id="more-1508"></span></p>
<div class="code">for i in `ls|grep Flexx`</div>
<p>This is basically a compound command. Bash&#8217;s <code>for</code> command is being used to step through the results of <code>ls|grep Flexx</code>. Each result will be stored to the variable <code>i</code> which can be referred to with <code>$i</code>.</p>
<p>In other words, I&#8217;m going to loop through each directory that contains the text &#8220;Flexx&#8221; (technically, it isn&#8217;t limited to just directories, but I don&#8217;t have any files containing &#8220;Flexx&#8221;, so I&#8217;m safe). For each iteration of the loop, the variable <code>$i</code> will contain the name of the folder I&#8217;m interested in.</p>
<div class="code">do echo &#8220;&#8212; Pushing $i&#8221;</div>
<p>The most important bit here is <code>do</code>. <code>do</code> simply begins the functional part of the loop and could be followed by any command that I wanted to start the loop with.</p>
<p>The <code>echo</code> command isn&#8217;t technically necessary. I simply have it there so that I can better determine what output belongs to which repository.</p>
<div class="code">cd $i</div>
<p>This is a very important command. It changes the directory to the repository I wish to run commands on.</p>
<div class="code">git commit -am &#8217;2.5.0&#8242; &amp;&amp; git push &amp;&amp; git tag 2.5.0 &amp;&amp; git push &#8211;tags</div>
<p>This is the command that actually does what I want to do in each repo directory. This adds all the modified files, commits them with a message of &#8220;2.5.0&#8243;, pushes the changes to the remote repository, creates a new tag of 2.5.0, and pushes up the new tag.</p>
<p>I have all of these commands chained together with <code>&amp;&amp;</code> so that if one command fails, the other ones won&#8217;t run. This prevents tagging in the event that the repository couldn&#8217;t be committed or pushed.</p>
<div class="code">cd ..</div>
<p>It&#8217;s a small command but necessary. This switches back to the main directory that holds all the repos, thus returning us back to a state that the next loop iteration can work with.</p>
<div class="code">echo &#8220;&#8212; Finished $i&#8221;</div>
<p>As with the other <code>echo</code> command, this simply allows me to keep track of what is going on more easily.</p>
<div class="code">done</div>
<p>The <code>done</code> command finishes out the loop iteration.</p>
<p>I hope that by sharing this you can gain a bit of insight into how I work with repositories while also learning more about how you can do things with Bash.</p>
]]></content:encoded>
			<wfw:commentRss>http://chrisjean.com/2009/09/15/updating-multiple-git-repositories-easily-using-bash-for-loop/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Command Line History in Ubuntu Terminal</title>
		<link>http://chrisjean.com/2009/03/09/command-line-history-in-ubuntu-terminal/</link>
		<comments>http://chrisjean.com/2009/03/09/command-line-history-in-ubuntu-terminal/#comments</comments>
		<pubDate>Mon, 09 Mar 2009 06:00:30 +0000</pubDate>
		<dc:creator>Chris Jean</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Tips 'n Tricks]]></category>
		<category><![CDATA[BASH]]></category>
		<category><![CDATA[command line]]></category>
		<category><![CDATA[history]]></category>
		<category><![CDATA[Mastering The Command Line]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://gaarai.com/?p=1304</guid>
		<description><![CDATA[I&#8217;ve had a lot of fun recently posting about how to do stuff on the command line in Linux. My focus is specifically for Ubuntu users, but the information and techniques can be used for any Linux distro. Since I&#8217;m probably going to end up with a lot of content under this topic, I&#8217;ve decided [...]]]></description>
			<content:encoded><![CDATA[<!-- filtered -->
<p>I&#8217;ve had a lot of fun recently posting about how to do stuff on the command line in Linux. My focus is specifically for Ubuntu users, but the information and techniques can be used for any Linux distro.</p>
<p>Since I&#8217;m probably going to end up with a lot of content under this topic, I&#8217;ve decided to create a dedicated tag: <a href="http://chrisjean.com/tag/mastering-the-command-line/">Mastering the Command Line</a>. I&#8217;ve gone through my older posts on this topic and tagged them as well. So, make sure to check out <a href="http://chrisjean.com/tag/mastering-the-command-line/" target="_blank">Mastering the Command Line</a> if you want to know how to become a command line power user.</p>
<p>Back to today&#8217;s topic. You&#8217;re starting to learn how to use the command line, but it&#8217;s annoying to always have to type in similar commands over and over. If only there were a way to pull up commands that you&#8217;ve already run to run again as is or to quickly modify. Today, I&#8217;m going to teach you how to do exactly this.</p>
<p><span id="more-1304"></span></p>
<h3>Introduction to BASH Command Line History</h3>
<p><a href="http://www.gnu.org/software/bash/" target="_blank">BASH</a> (Bourne Again SHell) is the default command line shell that is used in Ubuntu, and most other distros for that matter. The instructions that I give here are specific to BASH and may or may not work in other shells. Since most people don&#8217;t modify which shell they access through Terminal, I only point this out to inform those who have changed their shell that their experiences may differ depending on the shell used.</p>
<p>When you close a Terminal session, BASH writes all the commands you&#8217;ve run for that session to your ~/.bash_history file. When you load a new session, this file is read and those commands along with the new commands you execute for that session become your new command history.</p>
<p>It&#8217;s important to keep in mind that commands executed for a session are only written when you exit. If you have two sessions running concurrently, they cannot cross-reference the newly-executed commands run in the other session. Furthermore, if you force a Terminal session to quit, the command history will not be updated.</p>
<h3>Simple Command History Navigation</h3>
<p>The easy way to get started with your command history is to simply navigate with the up and down arrow keys. Using the up key, you can scroll through previous commands one command at a time. To scroll back down the list, you can use the down arrow key.</p>
<p>Once you&#8217;ve found the desired command, you can treat it as if you&#8217;ve typed that command in the command line. You can simply press Enter to execute the command again, or you can modify the command as needed before executing it.</p>
<p>This method is very good for quickly running commands that you have to execute repeatedly without many other commands between.</p>
<h3>Listing and Searching Command History</h3>
<p>BASH provides the history command that when executed with no options will list the entire command history. Each command will be preceeded with a number that represents that command&#8217;s command number. I&#8217;ll tell you how to use these numbers below.</p>
<p>You can also have the history command produce just the last certain number of commands by supplying a number. For example, if you want to see the previous ten commands, you can run the following:</p>
<div class="code">user:~$ <strong>history 10</strong><br />
510  which bash<br />
511  echo $$<br />
512  ps aux|grep 32115<br />
513  which sh<br />
514  history<br />
515  man history<br />
516  history|grep echo<br />
517  vi ~/.bash_history<br />
518  tail -10 ~/.bash_history<br />
519  history 10</div>
<p>Notice that the last command is the same as the command you ran to produce it. So, &#8220;history 1&#8243; will just show you &#8220;[command number] history 1&#8243;.</p>
<h4>Searching History</h4>
<p>If you remember that you ran a really cool command and can&#8217;t quite remember how you did it, combining history with <a href="http://chrisjean.com/2009/01/21/grep-why-i-love-linux/" target="_blank">grep</a> provides an easy way to find that command with just a piece of the command.</p>
<p>For example, let&#8217;s say that I ran a command that listed all the files that end in &#8220;.php&#8221; inside the ~/wordpress folder it then filters for just matches that contain the text &#8220;link&#8221; and then reverses the output. I was quite proud of that command, but I can&#8217;t remember how I did it. So, I search through my history.</p>
<p>Since I don&#8217;t think that I have the word &#8220;link&#8221; in many of my commands, I pick it as the target to search for and run the following:</p>
<div class="code">user:~$ <strong>history|grep link</strong><br />
412  find ~/wordpress -type f | grep \.php$ | grep link | sort -r</div>
<p>That&#8217;s what I was looking for. Now I can bask in the glory of my ingenious command and use it as the inspiration for other inspired words of command line magic.</p>
<h4>Running Previous Commands Again</h4>
<p>Searching through the history is great and all, but I&#8217;d rather not have to copy and paste found commands. I&#8217;d like to just run them immediately. BASH to the rescue again.</p>
<p>If you&#8217;d like to run the previous command again quickly, you can simply run &#8220;!!&#8221;. The first exclamation point tells BASH that you are running a previous commands. The second exclamation point tells BASH that it&#8217;s the last command that you&#8217;d like to run again. It&#8217;s a double exclamation point simply to make it quick and easy to type in.</p>
<p>I&#8217;ve already shown you how to look through your history and find a specific command in your history complete with the command number. Now is the time to make use of that number. If I wanted to execute command number 510 (which bash) again using the history, I can simply run the following:</p>
<div class="code">user:~$ <strong>!510</strong><br />
which bash<br />
/bin/bash</div>
<p>Notice how running the command again first lists the actual command and then the output.</p>
<p>BASH substitutes the !number command with the actual command from the history. This allows you to supply additional parameters to the command. The following is a silly example, but it gets the point across.</p>
<div class="code">user:~$ <strong>!510 dash</strong><br />
which bash dash<br />
/bin/bash<br />
/bin/dash</div>
<p>Notice how the command now has the additional parameter added to the original command. As expected, the full command is listed followed by the command output.</p>
<p>You can also do the standard manipulations such as piping the output, &#8220;!412 | grep wp-admin&#8221;, or redirecting the output, &#8220;!510 &gt; shell_locations.txt&#8221;.</p>
<h4>Searching and Running Previous Commands</h4>
<p>The &#8220;!&#8221; functionality of BASH also allows you to search through the history and execute the first match.</p>
<p>The basic form of this simply searches for matches at the beginning of the command. &#8220;!find&#8221; executes the most recent command that begins with &#8220;find&#8221;.</p>
<p>You can also search the entire command for a match. &#8220;!?link?&#8221; executes the most recent command that contains &#8220;link&#8221;.</p>
<h3>Advanced History with Regular Expressions</h3>
<p>As with many tools in the Linux world, you can attain great power by combining the tool with <a href="http://www.regular-expressions.info/" target="_blank">regular expressions</a>. The history in BASH allows you to run previous commands with a search and replace in Regex fashion.</p>
<p>Let&#8217;s take my searching through the ~/wordpress example, command number 412, and run it again with some modifications. This time, instead of searching ~/wordpress, I&#8217;d like to search through /home/site/public_hmtl/wordpress. I&#8217;d do that with the following:</p>
<div class="code">user:~$ <strong>!412:s|~/wordpress|/home/site/public_html/wordpress|</strong><br />
find /home/site/public_html/wordpress -type f | grep \.php$ | grep link | sort -r<br />
/home/site/public_html/wordpress/wp-links-opml.php<br />
/home/site/public_html/wordpress/wp-includes/link-template.php<br />
/home/site/public_html/wordpress/wp-admin/update-links.php<br />
/home/site/public_html/wordpress/wp-admin/options-permalink.php<br />
/home/site/public_html/wordpress/wp-admin/link.php<br />
/home/site/public_html/wordpress/wp-admin/link-parse-opml.php<br />
/home/site/public_html/wordpress/wp-admin/link-manager.php<br />
/home/site/public_html/wordpress/wp-admin/link-category.php<br />
/home/site/public_html/wordpress/wp-admin/link-add.php<br />
/home/site/public_html/wordpress/wp-admin/edit-link-form.php<br />
/home/site/public_html/wordpress/wp-admin/edit-link-category-form.php<br />
/home/site/public_html/wordpress/wp-admin/edit-link-categories.php</div>
<p>Note that the search and replace is done by adding &#8220;:s|find|replace|&#8221; to the end of the history command. I used the pipes, &#8220;|&#8221;, to deliminate the find and replace portions to make it easier to add the forward slashes, &#8220;/&#8221;, to the terms. You can also use &#8220;:s/find/replace/&#8221;.</p>
<h3>Closing Thoughts</h3>
<p>I hope that you enjoy my Mastering the Command Line series. If you have any command line-specific requests, please leave a comment, and I will see about creating a tutorial on that topic.</p>
<p>Remember, those who forget history, are doomed to repeat it by manual entry.</p>
]]></content:encoded>
			<wfw:commentRss>http://chrisjean.com/2009/03/09/command-line-history-in-ubuntu-terminal/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Multitasking from the Linux Command Line + Process Prioritization</title>
		<link>http://chrisjean.com/2009/03/06/multitasking-from-the-linux-command-line-plus-process-prioritization/</link>
		<comments>http://chrisjean.com/2009/03/06/multitasking-from-the-linux-command-line-plus-process-prioritization/#comments</comments>
		<pubDate>Fri, 06 Mar 2009 06:00:31 +0000</pubDate>
		<dc:creator>Chris Jean</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Tips 'n Tricks]]></category>
		<category><![CDATA[command line]]></category>
		<category><![CDATA[job]]></category>
		<category><![CDATA[Mastering The Command Line]]></category>
		<category><![CDATA[process]]></category>

		<guid isPermaLink="false">http://gaarai.com/?p=1263</guid>
		<description><![CDATA[Did you know that you aren&#8217;t limited to working on one thing at a time while on a Linux command line? You can actually &#8220;minimize&#8221; a program that you are in, get back to the command line, and then return to the program whenever you&#8217;d like. When you run a program or script on the [...]]]></description>
			<content:encoded><![CDATA[<!-- filtered -->
<p>Did you know that you aren&#8217;t limited to working on one thing at a time while on a Linux command line? You can actually &#8220;minimize&#8221; a program that you are in, get back to the command line, and then return to the program whenever you&#8217;d like.</p>
<p>When you run a program or script on the Linux command line (from now on referred to as the shell), you are creating a new job. For those that are used to GUI environments, each of these jobs is somewhat like a window on the desktop. Just as you can have multiple windows and switch between them, the shell is capable of managing multiple jobs and allows you to switch between them.</p>
<p>There is a lot to cover, so let&#8217;s start simple by describing what states a shell job can be in.</p>
<p><span id="more-1263"></span></p>
<h3>Jobs States</h3>
<h4>Foreground Jobs</h4>
<p>Up to now, you may have only worked with foreground jobs in the shell. Foreground jobs are ones that don&#8217;t return you to the command prompt until you exit out of the job or the job finishes.</p>
<p>If you run &#8220;<code>ping yahoo.com</code>&#8221; from the shell, the ping process will become a foreground job and will not return you to the command prompt until you stop it.</p>
<p>Just in case you didn&#8217;t know, you can stop the ping process by pressing <kbd>Ctrl+c</kbd>. Unlike in many applications that you may be used to, <kbd>Ctrl+c</kbd> does not mean &#8220;copy&#8221; in a Linux shell. Instead of copying text, this signals the foreground process to terminate by sending it the <a href="http://en.wikipedia.org/wiki/SIGINT_(POSIX)"><code>SIGINT</code></a> (Signal Interrupt) signal.</p>
<p>An example of a foreground job that won&#8217;t return you to the command prompt until it is finished is the <code>zip</code> command. Imagine that you have a large amount of files inside a folder called &#8220;stuff&#8221;. If I run &#8220;<code>zip -r stuff.zip stuff</code>&#8221; and don&#8217;t know about job management, I won&#8217;t have access to the shell until <code>zip</code> finishes its task and returns me to the prompt.</p>
<h4>Background Jobs</h4>
<p>Putting a job in the background allows the job to run exactly as if it were in the foreground except that it does not receive user input. If a command produces output and is put in the background, it will still produce the output.</p>
<p>Why would putting a job in the background be helpful then you may wonder. There are a number of reasons, and they will become clear in the examples below.</p>
<h4>Stopped Jobs</h4>
<p>There is technically a third state that a job can be in. Jobs that aren&#8217;t in the foreground yet are also not in the background have been stopped.</p>
<p>Like background jobs, stopped jobs do not receive user input. Unlike background jobs, stopped jobs do not produce output. As a matter of fact, they don&#8217;t do anything. They have essentially been put on hold and won&#8217;t do any processing until they are resumed or killed.</p>
<h3>Multitasking 101: Stopping and Resuming Processes</h3>
<p>It may seem like stopped jobs are the odd man out, but they are actually the key to getting started with multitasking on the Linux shell. I use stopped jobs every day, and I couldn&#8217;t imagine using the shell without them.</p>
<p>Imagine that you are in your favorite shell text editor working on a program or modifying config files, and you can&#8217;t remember what the IP address you need is but you could easily look it up with dig. You could easily open up another shell connection and run the command, but it would be quicker to simply stop the editor, run the command quickly, copy the text, and bring your editor to the foreground.</p>
<p>The following is a sequence that illustrates how this example would look on your shell.</p>
<pre class="terminal"><span style="color:#8FED99;">[<span style="color:#BBFF33;">chris@local</span> <span style="color:#729FCF;">~</span>]$</span> <span style="color:#FFF;">sudo vi /etc/httpd/conf/httpd.conf</span>
[sudo] password for chris:
<em style="color:white;">Ctrl+z</em>
[1]+  Stopped          sudo vi /etc/httpd/conf/httpd.conf
<span style="color:#8FED99;">[<span style="color:#BBFF33;">chris@local</span> <span style="color:#729FCF;">~</span>]$</span> <span style="color:#FFF;">dig +short chrisjean.com</span>
96.125.165.12
<span style="color:#8FED99;">[<span style="color:#BBFF33;">chris@local</span> <span style="color:#729FCF;">~</span>]$</span> <span style="color:#FFF;">fg %1</span></pre>
<p>After running these commands, you will be back in your editor.</p>
<p>The key to stopping a running job is the <kbd>Ctrl+z</kbd> key combination. Again, some of you may be used to <kbd>Ctrl+z</kbd> as the shortcut to undo, but in the Linux shell, <kbd>Ctrl+z</kbd> sends the <a href="http://en.wikipedia.org/wiki/SIGTSTP"><code>SIGTSTP</code></a> (Signal Tty SToP) signal to the foreground job. When you press this key combination, the running program will be stopped and you will be returned to the command prompt.</p>
<p>You may notice the &#8220;<code>%1</code>&#8221; after <code>fg</code>. The &#8220;1&#8243; is the job number that is to be brought to the foreground. The job number is listed in brackets when the job was stopped. These numbers are crucial when you have multiple jobs in stopped states. At any time, you can run &#8220;jobs&#8221; to get a list of the current jobs.</p>
<p>I stop jobs every day, and it greatly reduces the number of active shell sessions I have running. Sometimes I have stopped jobs that I set up ahead of time when I first access the shell. For example, I may open up a MySQL session, connect it to the database of the site I&#8217;m working on, and then stop it. Any time I need to run a query, I can load up the job by running &#8220;<code>fg 1</code>&#8220;, run the query, and then stop the job again.</p>
<h3>Multitasking 202: Running Jobs in the Background</h3>
<p>Stopping jobs is great, but what if we want to be returned to the command prompt while still allowing the job to run? Sending a job to the background will do exactly that.</p>
<p>As I talked about in my post about <a href="http://chrisjean.com/2009/03/04/4-great-tools-to-find-files-quickly-in-ubuntu/">finding files</a>, the locate command is extremely helpful. Sometimes you need to manually run the <code>updatedb</code> command in order for the locate database to update. The problem is that the <code>updatedb</code> command can take a very long time to run, sometimes it can take more than an hour.</p>
<p>I&#8217;ll use the example of the <code>updatedb</code> command to show how you can take a foreground process and put it in the background so that you can free up the shell.</p>
<pre class="terminal"><span style="color:#8FED99;">[<span style="color:#BBFF33;">chris@local</span> <span style="color:#729FCF;">~</span>]$</span> <span style="color:#FFF;">sudo updatedb</span>
[sudo] password for chris:
<em style="color:white;">Ctrl+z</em>
[1]+  Stopped            sudo updatedb
<span style="color:#8FED99;">[<span style="color:#BBFF33;">chris@local</span> <span style="color:#729FCF;">~</span>]$</span> <span style="color:#FFF;">bg %1</span>
[1]+ sudo updatedb &amp;
<span style="color:#8FED99;">[<span style="color:#BBFF33;">chris@local</span> <span style="color:#729FCF;">~</span>]$</span> <span style="color:#FFF;"></span></pre>
<p>There are a few items of note here.</p>
<ol>
<li>I&#8217;m back at the command prompt and can do anything I&#8217;d like while the job works merrily away in the background.</li>
<li>Notice how I used &#8220;%1&#8243; with bg just as I did with fg. Both commands accept a job number to tell it which job is to be sent to the foreground/background.</li>
<li>After running bg, a line similar to when I pressed Ctrl+z was printed showing the command and job number. However, there is also the addition of the &#8220;&amp;&#8221; at the end. We&#8217;ll get into the reason for that in the next section.</li>
</ol>
<p>When a process that is running in background finishes, you will receive a message the next time your command prompt refreshes. The prompt refreshes when you run another command or simply hit <kbd>Enter</kbd> to get a new prompt.</p>
<p>Continuing from the previous example, I receive output similar to the following when the <code>updatedb</code> command finishes:</p>
<pre class="terminal"><span style="color:#8FED99;">[<span style="color:#BBFF33;">chris@local</span> <span style="color:#729FCF;">~</span>]$</span> <span style="color:#FFF;"></span>
[1]+  Done              sudo updatedb
<span style="color:#8FED99;">[<span style="color:#BBFF33;">chris@local</span> <span style="color:#729FCF;">~</span>]$</span> <span style="color:#FFF;"></span></pre>
<p>As with all the other job-related output, you will be notified of the job number and the command.</p>
<h3>Multitasking 303: Starting Jobs in the Background</h3>
<p>Now that you see the value of having jobs run in the background, you might wonder if you can just start the command in the background to begin with. In fact, you can!</p>
<p>Remember that odd ampersand &#8220;<code>&amp;</code>&#8221; after the command in the output of the <code>bg</code> command? The ampersand means that the job is running in the background. You can run a command with the ampersand at the end to automatically put the job in the background.</p>
<p>Going back to the <code>updatedb</code> example again, we could have simply run the following to have the job in the background and get our command prompt back immediately:</p>
<pre class="terminal"><span style="color:#8FED99;">[<span style="color:#BBFF33;">chris@local</span> <span style="color:#729FCF;">~</span>]$</span> <span style="color:#FFF;">sudo date</span>
...
<span style="color:#8FED99;">[<span style="color:#BBFF33;">chris@local</span> <span style="color:#729FCF;">~</span>]$</span> <span style="color:#FFF;">sudo updatedb &amp;</span>
[sudo] password for chris:
[1] 15231
<span style="color:#8FED99;">[<span style="color:#BBFF33;">chris@local</span> <span style="color:#729FCF;">~</span>]$</span> <span style="color:#FFF;"></span></pre>
<p>You might wonder what that completely unnecessary &#8220;<code>sudo date</code>&#8221; command is all about. Remember that when you send a job to the background, it cannot receive input from the user. Since <code>sudo</code> prompts for the password when it hasn&#8217;t been run recently, I ran a throwaway command before running the background <code>sudo</code> command to ensure that the password wouldn&#8217;t be prompted for. If you do send a <code>sudo</code> command to the background and <code>sudo</code> prompts for a password, you need to bring it to the foreground first to enter the password and then send it to the background again.</p>
<p>The output when sending the job directly to the background is different than running <code>bg</code>. Instead of telling you the command, it tells you the actual process ID. Every program that runs in Linux is a process and has a process ID. You can use these process IDs to kill a specific process, change the process&#8217; execution priority, and isolate the resource utilization by that process.</p>
<p>Even though you&#8217;ve put a task in the background, you can still bring it to the foreground using the <code>fg</code> command. In the previous example, I can pull the background process to the foreground by running &#8220;<code>fg %1</code>&#8220;.</p>
<h3>Multitasking Graduate School: Killing and Prioritizing Jobs</h3>
<p>Now that you know the fundamentals of managing jobs, it&#8217;s time to get more advanced and tell you how to terminate jobs and modify their execution priority.</p>
<h4>Terminating Jobs</h4>
<p>Sometimes a process goes rogue and either won&#8217;t respond to input, is consuming massive amounts of resources, or both. At times like this, it&#8217;s very important to know how to kill a job which will cease the program&#8217;s execution and free up its used resources.</p>
<p>The command used to kill processes is appropriately called <code>kill</code>. The kill command can accept either process IDs or job numbers (the job number must be preceded by a percent sign, &#8220;%&#8221;).</p>
<p>If my <code>updatedb</code> job from before fails to respond, the job has a job number of &#8220;1&#8243;, and I want to tell the job to stop, I could run the following command:</p>
<pre class="terminal"><span style="color:#8FED99;">[<span style="color:#BBFF33;">chris@local</span> <span style="color:#729FCF;">~</span>]$</span> <span style="color:#FFF;">sudo kill %1</span>
[sudo] password for chris:
<span style="color:#8FED99;">[<span style="color:#BBFF33;">chris@local</span> <span style="color:#729FCF;">~</span>]$</span> <span style="color:#FFF;"></span></pre>
<p>Notice that there isn&#8217;t any confirmation that the kill command was successful. You can check to ensure that the job has been terminated by running the &#8220;<code>jobs</code>&#8221; command and looking for that job&#8217;s listing.</p>
<p>By default, the <code>kill</code> command sends a <a href="http://en.wikipedia.org/wiki/SIGTERM"><code>SIGTERM</code></a> (Signal Terminate) signal to the process; however, sometimes this is not enough to stop the execution of an out of control process. To shut down these processes, we need something more powerful.</p>
<pre class="terminal"><span style="color:#8FED99;">[<span style="color:#BBFF33;">chris@local</span> <span style="color:#729FCF;">~</span>]$</span> <span style="color:#FFF;">sudo kill -9 %1</span>
[sudo] password for chris:
<span style="color:#8FED99;">[<span style="color:#BBFF33;">chris@local</span> <span style="color:#729FCF;">~</span>]$</span> <span style="color:#FFF;"></span></pre>
<p>This may not look much different, but the addition of the &#8220;-9&#8243; option tells the command that things are serious now. This option causes a <a href="http://en.wikipedia.org/wiki/SIGKILL"><code>SIGKILL</code></a> (Signal Kill) signal to be sent to the process. A kill signal cannot be intercepted by a process and causes the process to immediately terminate without allowing it to clean up after itself. It&#8217;s for this reason that you should only use <code>SIGKILL</code> after first sending the process a <code>SIGTERM</code>.</p>
<p>As mentioned before, you can also run a <code>kill</code> command on a process ID rather than a job number. If we wished to kill a process with a process ID of 12267, we can run the following command:</p>
<pre class="terminal"><span style="color:#8FED99;">[<span style="color:#BBFF33;">chris@local</span> <span style="color:#729FCF;">~</span>]$</span> <span style="color:#FFF;">sudo kill 12267</span>
<span style="color:#8FED99;">[<span style="color:#BBFF33;">chris@local</span> <span style="color:#729FCF;">~</span>]$</span> <span style="color:#FFF;"></span></pre>
<p>Note that you don&#8217;t have to always run the <code>kill</code> command with <code>sudo</code>, you just have to ensure that whatever privilege level you are running the <code>kill</code> command at has the ability to control that process. In other words, if you are trying to kill a process run with <code>sudo</code>, you&#8217;ll need to use <code>sudo</code> to kill it as well.</p>
<h4>Prioritizing Jobs</h4>
<p>Linux does a great job of prioritizing tasks automatically; however, what Linux thinks is best isn&#8217;t always what you want. Basically, Linux always wants to make a process finish as soon as possible, which means that you get a nice bit of lag when you try to do your work as a CPU or disk hungry process churns away. Fortunately, there are tools that will let you tell Linux what you want.</p>
<p>First, let&#8217;s deal with managing a process&#8217; use of CPU time. If you are going to run a command that will eat up large amounts of CPU cycles and you want to make sure that this process doesn&#8217;t keep you from doing your work, you can run the command with <code>nice</code> to give the command a lower-than-default priority.</p>
<pre class="terminal"><span style="color:#8FED99;">[<span style="color:#BBFF33;">chris@local</span> <span style="color:#729FCF;">~</span>]$</span> <span style="color:#FFF;">sudo date</span>
[sudo] password for chris:
Fri Mar  6 10:55:11 CST 2009
<span style="color:#8FED99;">[<span style="color:#BBFF33;">chris@local</span> <span style="color:#729FCF;">~</span>]$</span> <span style="color:#FFF;">sudo nice updatedb &amp;</span>
[1] 16312
<span style="color:#8FED99;">[<span style="color:#BBFF33;">chris@local</span> <span style="color:#729FCF;">~</span>]$</span> <span style="color:#FFF;"></span></pre>
<p>As before, a junk sudo command was run first to take care of the password prompt.</p>
<p>Running the command in <code>nice</code> lowers the processes CPU priority and will result in smoother CPU performance for your other applications.</p>
<p>What if you already ran a command whose process is now greedily chewing away at your CPU resources? That&#8217;s where the <code>renice</code> command comes into play.</p>
<p>With <code>renice</code>, you can change the CPU priority of an existing process.</p>
<pre class="terminal"><span style="color:#8FED99;">[<span style="color:#BBFF33;">chris@local</span> <span style="color:#729FCF;">~</span>]$</span> <span style="color:#FFF;">sudo date</span>
[sudo] password for chris:
Fri Mar  6 10:56:25 CST 2009
<span style="color:#8FED99;">[<span style="color:#BBFF33;">chris@local</span> <span style="color:#729FCF;">~</span>]$</span> <span style="color:#FFF;">sudo updatedb &amp;</span>
[1] 16324
<span style="color:#8FED99;">[<span style="color:#BBFF33;">chris@local</span> <span style="color:#729FCF;">~</span>]$</span> <span style="color:#FFF;">sudo renice 10 16324</span>
16324: old priority 0, new priority 10
<span style="color:#8FED99;">[<span style="color:#BBFF33;">chris@local</span> <span style="color:#729FCF;">~</span>]$</span> <span style="color:#FFF;"></span></pre>
<p>The <code>renice</code> command accepts a priority as the first argument and the process ID as the second argument. The priority argument has a range from -20 to 19 where -20 is the highest priority and 19 is the lowest. In other words, a higher numeric value priority results in lower CPU priority.</p>
<p>That takes care of the CPU, but admittedly, the <code>updatedb</code> command does more damage to the IO or disk traffic than it does to the processor. How can we reign in a process&#8217; use of the disk so that performance for the rest of the system improves? For that, we use the <code>ionice</code> command.</p>
<p>With the <code>ionice</code> command, you can set the IO priority for a process to one of three classes: Idle (3), Best Effort (2), and Real Time (1). The Idle class means that the process will only be able to read and write to the disk when all other processes are not using the disk. The Best Effort class is the default and has eight different priority levels from 0 (top priority) to 7 (lowest priority). The Real Time class results in the process having first access to the disk irregardless of other process and should never be used unless you know what you are doing.</p>
<p>If we wish to run the <code>updatedb</code> process in the background with an Idle IO class priority, we can run the following:</p>
<pre class="terminal"><span style="color:#8FED99;">[<span style="color:#BBFF33;">chris@local</span> <span style="color:#729FCF;">~</span>]$</span> <span style="color:#FFF;">sudo date</span>
[sudo] password for chris:
Fri Mar  6 11:02:43 CST 2009
<span style="color:#8FED99;">[<span style="color:#BBFF33;">chris@local</span> <span style="color:#729FCF;">~</span>]$</span> <span style="color:#FFF;">sudo updatedb &amp;</span>
[1] 16324
<span style="color:#8FED99;">[<span style="color:#BBFF33;">chris@local</span> <span style="color:#729FCF;">~</span>]$</span> <span style="color:#FFF;">sudo ionice -c3 -p16324</span>
<span style="color:#8FED99;">[<span style="color:#BBFF33;">chris@local</span> <span style="color:#729FCF;">~</span>]$</span> <span style="color:#FFF;"></span></pre>
<p>If we&#8217;d rather just lower the Best Effort class priority (defaults to 4) for the command so the process isn&#8217;t limited to idle IO periods, we can run the following:</p>
<pre class="terminal"><span style="color:#8FED99;">[<span style="color:#BBFF33;">chris@local</span> <span style="color:#729FCF;">~</span>]$</span> <span style="color:#FFF;">sudo date</span>
[sudo] password for chris:
Fri Mar  6 11:07:12 CST 2009
<span style="color:#8FED99;">[<span style="color:#BBFF33;">chris@local</span> <span style="color:#729FCF;">~</span>]$</span> <span style="color:#FFF;">sudo updatedb &amp;</span>
[1] 16324
<span style="color:#8FED99;">[<span style="color:#BBFF33;">chris@local</span> <span style="color:#729FCF;">~</span>]$</span> <span style="color:#FFF;">sudo ionice -c2 -n7 -p16324</span>
<span style="color:#8FED99;">[<span style="color:#BBFF33;">chris@local</span> <span style="color:#729FCF;">~</span>]$</span> <span style="color:#FFF;"></span></pre>
<p>Again, the Real Time class should not be used as it can prevent you from being able to interact with your system.</p>
<p>You may wonder where you can get the process ID if you don&#8217;t know it, can&#8217;t remember it, or didn&#8217;t start the process (an automated script may have launched it). You can find process IDs with the <code>ps</code> command.</p>
<p>For example, if I had an updatedb program running in the background, and I wanted to find its process ID, I can run the following:</p>
<pre class="terminal"><span style="color:#8FED99;">[<span style="color:#BBFF33;">chris@local</span> <span style="color:#729FCF;">~</span>]$</span> <span style="color:#FFF;">ps -C updatedb</span>
PID TTY          TIME CMD
4234 ?        00:00:42 updatedb</pre>
<p>This tells me that the process&#8217; process ID (PID) is 4234.</p>
<p>Another useful command is &#8220;<code>ps -u <em>user</em></code>&#8221; (replace &#8220;<code>user</code>&#8221; with your username) which lists all processes your user has access to. Basically, these are processes that your user or some process using your user&#8217;s permissions started.</p>
<p>Another really helpful use of <code>ps</code> is &#8220;<code>ps aux</code>&#8220;. This command will list all the system&#8217;s processes, which user owns the process, and even detail the resource usage of the process. This is very helpful for finding processes that you don&#8217;t know enough about to find using other methods.</p>
<h3>Mutitasking Doctorate: Using Job Management in Scripts</h3>
<p>Keep in mind that many scripts execute from inside shell environments. This means that you can manage the script&#8217;s job using the tools I&#8217;ve given you here.</p>
<p>If you look in the <code>/etc/cron.daily</code> folder, you&#8217;ll find many scripts that execute once a day. These scripts can create a huge load on a system while they execute. If around the clock performance is crucial, you can prioritize the shells that the scripts run in which causes all the commands run inside that shell to follow the same prioritization rules.</p>
<p>This all sounds very complex, but it&#8217;s actually very simple.</p>
<p>Let&#8217;s open up the <code>/etc/cron.daily/mlocate</code> file (pick another file if you don&#8217;t have this one). At the top, you should see a line like the following:</p>
<div class="code">#!/bin/bash</div>
<p>This <a href="http://en.wikipedia.org/wiki/Shebang_(Unix)">shebang</a> line tells Linux what interpreter is used to execute the script. My example script uses the bash shell as the interpreter. Other scripts may use the sh shell instead of the bash shell, but that won&#8217;t make any difference.</p>
<p>Below the first line, put the following:</p>
<div class="code">renice 10 $$<br />
ionice -c3 -p$$</div>
<p>The $$ variable is a special variable that contains the shell&#8217;s own process ID. The two commands above cause the CPU priority to lower to 10 and changes the IO priority to class 3 (Idle).</p>
<p>Add this type of customization to your resource hungry scripts, and your system will perform more smoothly around the clock. Keep in mind that this also can result in the scripts taking much longer to complete.</p>
<p>You can use those same commands above using the <code>$$</code> variable to change the CPU and IO priority of shells that you open in order to lower the impact you have while working on the system. This can be a smart thing to do if you need to compile software or run other intensive processes on production machines.</p>
<h3>Important Commands</h3>
<p>Here&#8217;s a list of all the commands, key combos, and other important bits that I went over with a brief description for each. It&#8217;s like the word list at the end of children&#8217;s books.</p>
<ul>
<li><code>fg</code> &#8211; Brings a stopped or background job to the foreground</li>
<li><code>bg</code> &#8211; Sends a stopped job to the background</li>
<li><code>jobs</code> &#8211; Lists the current jobs and their corresponding job number</li>
<li><code>Ctrl+c</code> &#8211; Key combination that sends a <code>SIGINT</code> signal to the foreground process. Use this to close processes that don&#8217;t stop (such as ping or top) or terminate a process that no longer responds or is no longer needed.</li>
<li><code>Ctrl+z</code> &#8211; Key combination that sends the <code>SIGTSTP</code> signal to the foreground process. Use this to send a foreground process to a stopped state.</li>
<li><code>&amp;</code> &#8211; Use an ampersand at the end of a command to send the resulting job to the background immediately</li>
<li><code>kill</code> &#8211; Sends signals to processes based on process ID or job number. Useful to send <code>SIGTERM</code> or <code>SIGKILL</code> signals to forcibly stop processes.</li>
<li><code>nice</code> &#8211; Runs the given command with a lower-than-default CPU priority</li>
<li><code>renice</code> &#8211; Changes an existing process&#8217; CPU priority</li>
<li><code>ionice</code> &#8211; Changes an existing process&#8217; IO priority</li>
</ul>
<h3>Closing Thoughts</h3>
<p>Frankly, I didn&#8217;t expect to make such a long post. If this post has helped you, please leave a comment and let me know what you thought.</p>
<p>I&#8217;d greatly appreciate it if you&#8217;d share the post by using one of the icons below. Or you can <a href="http://digg.com/submit?url=http%3A%2F%2Fgaarai.com%2F2009%2F03%2F06%2Fmultitasking-from-the-linux-command-line-plus-process-prioritization%2F&amp;title=Multitasking+from+the+Linux+Command+Line+%2B+Process+Prioritization">click here</a> to Digg this post.</p>
]]></content:encoded>
			<wfw:commentRss>http://chrisjean.com/2009/03/06/multitasking-from-the-linux-command-line-plus-process-prioritization/feed/</wfw:commentRss>
		<slash:comments>21</slash:comments>
		</item>
		<item>
		<title>4 Great Tools to Find Files Quickly in Ubuntu</title>
		<link>http://chrisjean.com/2009/03/04/4-great-tools-to-find-files-quickly-in-ubuntu/</link>
		<comments>http://chrisjean.com/2009/03/04/4-great-tools-to-find-files-quickly-in-ubuntu/#comments</comments>
		<pubDate>Wed, 04 Mar 2009 06:00:32 +0000</pubDate>
		<dc:creator>Chris Jean</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Tips 'n Tricks]]></category>
		<category><![CDATA[command line]]></category>
		<category><![CDATA[find]]></category>
		<category><![CDATA[locate]]></category>
		<category><![CDATA[Mastering The Command Line]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[whereis]]></category>
		<category><![CDATA[which]]></category>

		<guid isPermaLink="false">http://gaarai.com/?p=1225</guid>
		<description><![CDATA[Many of you fellow Ubuntu users will be familiar with the &#8220;Search for Files&#8221; tool that allows you to look for files. As is true with most things in Linux, there are great desktop tools, but more power can be found in Terminal than any streamlined desktop tool can match. Today, I&#8217;d like to introduce [...]]]></description>
			<content:encoded><![CDATA[<!-- filtered -->
<p>Many of you fellow Ubuntu users will be familiar with the &#8220;Search for Files&#8221; tool that allows you to look for files. As is true with most things in Linux, there are great desktop tools, but more power can be found in Terminal than any streamlined desktop tool can match.</p>
<p>Today, I&#8217;d like to introduce you to a few tools that can turn a chore of finding files into an easy process.</p>
<p><span id="more-1225"></span></p>
<h3>locate</h3>
<p>The first tool that you should become comfortable with is also one of the simplest. The locate program works in a similar fashion to most graphical search tools.</p>
<h4>Using</h4>
<p>Let&#8217;s say that you&#8217;ve read up on how to modify <a href="http://www.x.org/" target="_blank">X</a> to provide enhanced video performance. The document that you are reading says to modify the xorg.conf file, but the document doesn&#8217;t say where that is and you don&#8217;t know how to find it. You can use locate to find it for you quickly:</p>
<div class="code">locate xorg.conf</div>
<p>Most likely, your system will return a number of results. For example, on one of my systems, I receive the following output:</p>
<div class="code">/etc/X11/xorg.conf<br />
/usr/share/man/man5/xorg.conf.5.gz<br />
/var/lib/x11/xorg.conf.md5sum<br />
/var/lib/x11/xorg.conf.roster</div>
<p>It&#8217;s clear that /etc/X11/xorg.conf is the file we&#8217;re looking for, but what if dozens or even hundreds of results were returned? How could you manage all of that? If you know a little bit about <a href="http://www.regular-expressions.info/" target="_blank">regular expressions</a> (every Linux user really should learn <a href="http://www.regular-expressions.info/tutorial.html" target="_blank">the basics</a>), you can easily use regular expressions to search for directories or files. For example, we can search for an exact match for xorg.conf with the following command:</p>
<pre style="padding-left:20px;">locate -r '/xorg.conf$'</pre>
<p>If you want to look for files without case sensitivity, you can use the &#8216;-i&#8217; option. For example:</p>
<pre style="padding-left:20px;">locate -i 'monthly report'</pre>
<p>Something that may confuse you when you first start using locate is that it not only returns matches, but if the match is a directory, it also lists all of the directories and files under that directory. To stop this behavior, use the &#8216;-b&#8217; option. For example:</p>
<div class="code">locate -b Desktop</div>
<p>This will return a much shorter list of results than if you did not include the &#8216;-b&#8217; option and all the matches will contain the search term as the final portion of the path.</p>
<h4>Important Note</h4>
<p>The locate command relies on a slocate database to function. This database caches the file system directory and file names and allows the locate command to operate in moments rather than taking long periods of time to search the entire file system.</p>
<p>This ability doesn&#8217;t come without cost though. By default, your system will run a command to update this database once a day at 6:25am. This command will update the database with any changes made to the file system since the last update.</p>
<p>If you&#8217;ve made changes recently, such as added or removed large amounts of files and directories, and you want to use the locate command to search through these new directories and files, you can manually update the slocate database at any time with the following command:</p>
<div class="code">sudo updatedb</div>
<p>Depending on the volume of changes made since the slocate database was last updated, this could take a few seconds to a few minutes to update. Once it&#8217;s done, you&#8217;re ready to search again with locate.</p>
<h3>which</h3>
<p>locate is great for searching the entire file system. However, sometimes you just want to find where a command lives. That&#8217;s where which comes into play.</p>
<p>which only does one thing, but it does it well. Given the name of a command, which will tell you where the file for that command resides in the file system.</p>
<p>Let&#8217;s imagine that we want to find out where there firefox command resides. We can simply run the following to find out:</p>
<div class="code">which firefox</div>
<p>On my system, and most likely on your&#8217;s as well, which will tell us that it is located at /usr/bin/firefox.</p>
<p>Why would you ever want to search specifically for a command? Imagine that you have some code that needs to replace an old command. You really need to remove the the old one (I usually rename it to the same name followed by &#8220;.bak&#8221; to keep it around in case I need it) first before putting the new one in its place. which will help you find the file quickly and easily so you don&#8217;t have to search everywhere to find it.</p>
<h3>whereis</h3>
<p>The whereis command is similar to which but goes one step further. Not only does it tell you where the executable file is located at, but it will also locate the source, man page, and other associated directories as well.</p>
<p>Keeping with the which example, let&#8217;s ask whereis about the firefox command:</p>
<div class="code">whereis firefox</div>
<p>On my system, I get the following output:</p>
<div class="code">firefox: /usr/bin/firefox /usr/lib/firefox /usr/lib64/firefox /usr/share/firefox</div>
<p>This helped me find /usr/lib/firefox/plugins earlier when working on the solution for Flash. That location is where the global add-ons for Firefox are stored.</p>
<h3>find</h3>
<p>find is the ultimate search tool, the Swiss Army knife of Linux search if you will. find can do everything from search for files based on last modified times, owners and groups, permissions, type (file, directory, symbolic link, etc), whether the file is readable/writable/executable by the current user, file size, whether the file or directory is empty, and much more. You can also search for matches by regular expression.</p>
<p>When you use this tool in combination with the xargs command (which I&#8217;ll have to cover some other time), you can do truly amazing things on the command line. Imagine being able to recursively search through the current directory for files ending with &#8220;.bak&#8221; that were last modified more than 100 days ago and then deleting them with one command:</p>
<pre style="padding-left:20px;">find . -name '*.bak' -type f -mtime +100 -print0 | xargs -0 /bin/rm -f</pre>
<p>It will look very complex at first, but when you master the art of using find, it will become second nature. Soon, you&#8217;ll wonder how you ever searched for things without it.</p>
<p>To be frank, there is much more to find than I am willing to cover and there are many, many great introductions to the tool that do a better job than I would. So, I&#8217;ll simply point you to three great references that can be used to get going with find.</p>
<ul>
<li><a href="http://linux.about.com/od/commands/a/blcmdl1_findx.htm" target="_blank">Example uses of the Linux Command find</a></li>
<li>(I apologize for the horrible colors in advance) <a href="http://content.hccfl.edu/pollock/Unix/FindCmd.htm" target="_blank">Unix/Linux &#8220;find&#8221; Command Tutorial</a></li>
<li><a href="http://www.linux.ie/newusers/beginners-linux-guide/find.php" target="_blank">Using the find command</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://chrisjean.com/2009/03/04/4-great-tools-to-find-files-quickly-in-ubuntu/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Change Timezone in CentOS</title>
		<link>http://chrisjean.com/2009/03/03/change-timezone-in-centos/</link>
		<comments>http://chrisjean.com/2009/03/03/change-timezone-in-centos/#comments</comments>
		<pubDate>Tue, 03 Mar 2009 06:00:52 +0000</pubDate>
		<dc:creator>Chris Jean</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Tips 'n Tricks]]></category>
		<category><![CDATA[CentOS]]></category>
		<category><![CDATA[command line]]></category>
		<category><![CDATA[Mastering The Command Line]]></category>
		<category><![CDATA[Timezone]]></category>
		<category><![CDATA[zoneinfo]]></category>

		<guid isPermaLink="false">http://gaarai.com/?p=1228</guid>
		<description><![CDATA[You just got your new CentOS dedicated server, and you notice that times in your logs aren&#8217;t quite right. You check the time from the command line (run &#8220;date&#8221;), and find that the timezone is set to US Eastern or some other timezone. How do you get this changed? Unfortunately, this is not an easy [...]]]></description>
			<content:encoded><![CDATA[<!-- filtered -->
<p>You just got your new CentOS dedicated server, and you notice that times in your logs aren&#8217;t quite right. You check the time from the command line (run &#8220;date&#8221;), and find that the timezone is set to US Eastern or some other timezone. How do you get this changed?</p>
<p>Unfortunately, this is not an easy thing to figure out. Fortunately though, it&#8217;s not hard to do with the right directions.</p>
<p><span id="more-1228"></span></p>
<p><em>Please note that you have to have root access to be able to make the changes detailed below.</em></p>
<p>There are a series of time zone files located at /usr/share/zoneinfo. Select the appropriate named timezone for your location. For my location, Oklahoma, USA, I actually have two that I can select from: America/Chicago or US/Central. Make note of the appropriate folder and file for your timezone.</p>
<p>The active timezone used on your system is in the /etc/localtime file. The default will vary depending on your server host but often seems to be EST or EDT (depending on the time of year you are checking). We simply need to replace this file with the file we selected in the previous step.</p>
<p>Now, I say replace, but I actually recommend creating a link to the pertinent file rather than actually making a copy. Let me explain the reasoning for this quickly.</p>
<p>A crucial part of the timezone shift calculations is the daylight savings calculations. Many people don&#8217;t realize this, but the daylight savings days were changed in 2007. When this change happened, all servers needed to be updated with new zoneinfo files.</p>
<p>If your server has an automated process to update these files when daylight savings calculations change, your /usr/share/zoneinfo files will be updated but the /etc/localtime file will not be. So, if you simply made a copy of the file, you&#8217;ll have to know when these updates come out and manually copy the file over. If you create a link, everything will take care of itself.</p>
<p>Enough of the banter. On with the show.</p>
<p>First, make a backup of the existing localtime file. It&#8217;s always good practice to make backups of original config files.</p>
<div class="code">mv /etc/localtime /etc/localtime.bak</div>
<p>Next, create the link:</p>
<div class="code">ln -s /usr/share/zoneinfo/<strong>America/Chicago</strong> /etc/localtime</div>
<p>Make sure to replace &#8220;America/Chicago&#8221; with the directory (if your zone has one) and filename of the timezone you wish to use.</p>
<p>Now you just need to test your change. Run &#8220;date&#8221; from the command line, and ensure that the appropriate time, date, and timezone are reported.</p>
]]></content:encoded>
			<wfw:commentRss>http://chrisjean.com/2009/03/03/change-timezone-in-centos/feed/</wfw:commentRss>
		<slash:comments>27</slash:comments>
		</item>
		<item>
		<title>Unzip Multiple Files from Linux Command Line</title>
		<link>http://chrisjean.com/2009/02/26/unzip-multiple-files-from-linux-command-line/</link>
		<comments>http://chrisjean.com/2009/02/26/unzip-multiple-files-from-linux-command-line/#comments</comments>
		<pubDate>Thu, 26 Feb 2009 06:00:45 +0000</pubDate>
		<dc:creator>Chris Jean</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Tips 'n Tricks]]></category>
		<category><![CDATA[command line]]></category>
		<category><![CDATA[Mastering The Command Line]]></category>
		<category><![CDATA[unzip]]></category>
		<category><![CDATA[zip]]></category>

		<guid isPermaLink="false">http://gaarai.com/?p=1196</guid>
		<description><![CDATA[Here&#8217;s a quick tip that will help you work with multiple zip files on the command line. If you are in a folder and have three zip files in it (a.zip, b.zip, c.zip) that you want to unzip, &#8220;no problem,&#8221; you think, &#8220;I can take care of that with one command.&#8221; So, you quickly run [...]]]></description>
			<content:encoded><![CDATA[<!-- filtered -->
<p>Here&#8217;s a quick tip that will help you work with multiple zip files on the command line.</p>
<p>If you are in a folder and have three zip files in it (a.zip, b.zip, c.zip) that you want to unzip, &#8220;no problem,&#8221; you think, &#8220;I can take care of that with one command.&#8221; So, you quickly run the following:</p>
<div class="code">unzip *.zip</div>
<p>However, rather than having the unzip program nicely unzip each file one after another, you receive the following:</p>
<div class="code">Archive:  a.zip<br />
caution: filename not matched:  b.zip<br />
caution: filename not matched:  c.zip</div>
<p>I&#8217;m sure that this is not what you were expecting. I know I certainly wasn&#8217;t expecting this when I first tried it. However, this problem can help us understand more of how the command line works.<br />
<span id="more-1196"></span></p>
<h3>The Problem</h3>
<p>Whenever you use a wildcard (*), the shell itself will expand that and pass the results to the program rather than the program handling the expansion itself. That means that our previous command was actually expanded to the following before being executed:</p>
<div class="code">unzip a.zip b.zip c.zip</div>
<p>Again, this may not look odd since other programs (such as mkdir, chmod, etc) can take one or more arguments and repeat the process for each. However, unzip is different and actually has use for the additional arguments. If you specify additional arguments after the zip file name, unzip will try to only extract those specific files from the archive rather than all the files.</p>
<p>The previous command told unzip that it should extract b.zip and c.zip from inside the a.zip archive. Since those files don&#8217;t exist inside a.zip, we get the nasty output seen earlier.</p>
<p>You might think that you will have to manually unzip each archive one at a time, but you&#8217;d be wrong.</p>
<h3>The Solution</h3>
<p>Just because the shell expands out wildcard characters automatically doesn&#8217;t mean that programs can&#8217;t as well. The simple solution to this problem is to quote the argument to prevent the shell from interpreting it:</p>
<div class="code">unzip &#8216;*.zip&#8217;</div>
<p>That&#8217;s all there is to it. I&#8217;ve seen solutions from coding loops in bash script to running find combined with xargs, but none of that is necessary. Simply let unzip itself take care of things for you.</p>
]]></content:encoded>
			<wfw:commentRss>http://chrisjean.com/2009/02/26/unzip-multiple-files-from-linux-command-line/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>

