<?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>gHacks Technology News &#124; Latest Tech News, Software And Tutorials &#187; $PATH</title> <atom:link href="http://www.ghacks.net/tag/path/feed/" rel="self" type="application/rss+xml" /><link>http://www.ghacks.net</link> <description>A technology news blog covering software, mobile phones, gadgets, security, the Internet and other relevant areas.</description> <lastBuildDate>Sat, 11 Feb 2012 09:52:46 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3.1</generator> <atom:link rel="hub" href="http://pubsubhubbub.appspot.com"/><atom:link rel="hub" href="http://superfeedr.com/hubbub"/> <item><title>Adding directories to your PATH</title><link>http://www.ghacks.net/2010/06/07/adding-directories-to-your-path/</link> <comments>http://www.ghacks.net/2010/06/07/adding-directories-to-your-path/#comments</comments> <pubDate>Mon, 07 Jun 2010 11:23:55 +0000</pubDate> <dc:creator>Jack Wallen</dc:creator> <category><![CDATA[Advice]]></category> <category><![CDATA[Linux]]></category> <category><![CDATA[Open Source]]></category> <category><![CDATA[Tutorials Basic]]></category> <category><![CDATA[$PATH]]></category> <category><![CDATA[bash profile]]></category> <category><![CDATA[linux PATH]]></category> <category><![CDATA[profile]]></category> <guid
isPermaLink="false">http://www.ghacks.net/?p=26273</guid> <description><![CDATA[One of the things I really like about Linux is how it handles a file&#8217;s ability to be executable. If you create a script and you want that script to be executable, you just set the permissions as such. Say you&#8217;ve created the script myscript.sh and you&#8217;ve placed it in your home directory. To execute that [...]]]></description> <content:encoded><![CDATA[<p>One of the things I really like about Linux is how it handles a file&#8217;s ability to be executable. If you create a script and you want that script to be executable, you just set the permissions as such. Say you&#8217;ve created the script <em>myscript.sh</em> and you&#8217;ve placed it in your home directory. To execute that script all you would have to do is issue the command <em>~/myscript.sh</em>. That&#8217;s all fine and good, but what if you wanted that script to be globally accessible for yourself? And let&#8217;s say you don&#8217;t want to copy that file, for whatever reason, to either the <strong>/usr/bin </strong>or the <strong>/usr/local/ </strong>directory. What would you do? That&#8217;s simple &#8211; you could place that file within a subdirectory of your home directory and add that directory to your PATH.</p><p>You see, any directory in your users&#8217;s PATH is global. That means you can issue a command by simply entering the command &#8211; you do not have to enter the full path to the command. That is why you don&#8217;t always have to enter <em>/usr/bin/ls</em> and you can just enter <em>ls.</em></p><p>In this article, we step back for a bit of Linux basics and learn how to add directories to your path.</p><p><span
id="more-26273"></span><strong>See what&#8217;s already there</strong></p><p>If you are curious to know what is already in your PATH you can do so by entering the command <em>echo $PATH</em>. You should see something like:</p><p><em>/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games</em></p><p>The above is pretty standard for a default Linux path. What you are seeing is global paths, each separated by a &#8220;:&#8221;. Any file in:</p><ul><li>/usr/bin</li><li>/usr/local/sbin</li><li>/usr/local/bin</li><li>/usr/sbin</li><li>/usr/bin</li><li>/sbin</li><li>/usr/games</li></ul><p>will be global for the user.</p><p><strong>Adding a new directory</strong></p><p>There are three ways to add a new directory to your path. Let&#8217;s take a look at them individually. The first method only adds the new directory to the PATH temporarily. This is great for testing purposes, but know that the minute you log out that directory is removed from the users&#8217; path.</p><p>Let&#8217;s say you have the directory <strong>~/scripts</strong> that you want to add temporarily. To do this open up a terminal window and issue the command:</p><p><em>PATH=$PATH:/home/USERNAME/scripts</em></p><p>Where USERNAME is the actual name of the user you are using. Now if you issue the command <em>echo $PATH</em> that new directory will be listed. Log out and log in and issue that same command and the directory will be gone.</p><p>Now let&#8217;s say you want to make that addition permanent for the user. This was typically done in the users&#8217; <strong>~/.bash_profile </strong>file. You might notice that you don&#8217;t have such a file. Newer Ubuntu releases have opted for the <strong>~/.profile</strong> file instead. I still prefer to create a <strong>~/.bash_profile</strong> for these purposes.  So if you don&#8217;t have a <strong>~/.bash_profile</strong> create one and open it. If you have a <strong>~/.bash_profile</strong> open it. and add a line like:</p><p><em>PATH=&#8221;$HOME/bin:$PATH:/home/USER/scripts:&#8221;</em></p><p>Where USER is the actual user name.</p><p>You might think you would have to log out and log back in. You don&#8217;t. Just issue the command <em>source .bash_profile</em> and the changes will take effect.</p><p>You can also add this path to every users PATH by adding the same line to the <strong>/etc/profile. </strong>You probably won&#8217;t find a reference to PATH in that file. So what you have to do is add the following lines to the end of that file:<br
/> <em>PATH=$PATH:/home/USER/scripts<br
/> export PATH</em><br
/> Where USER is the actual user name. Of course you probably don&#8217;t want to add a directory of one user to everyone&#8217;s PATH, so you might want to create a new directory (like <strong>/data/scripts</strong>) and add that the to <strong>/etc/profile</strong>. Once you are done save that and the next time someone logs in they will have that new directory in their PATH.</p><p><strong>Final thoughts</strong></p><p>Linux is all about flexibility. As you can see it is possible to really stretch the usability of your directory structure to make it work for you instead of against you. Adding directories to your PATH variable allows you to create scripts that can be run globally, and by anyone.</p> ]]></content:encoded> <wfw:commentRss>http://www.ghacks.net/2010/06/07/adding-directories-to-your-path/feed/</wfw:commentRss> <slash:comments>2</slash:comments> </item> <item><title>Adding a directory to your $PATH</title><link>http://www.ghacks.net/2009/06/03/adding-a-directory-to-your-path/</link> <comments>http://www.ghacks.net/2009/06/03/adding-a-directory-to-your-path/#comments</comments> <pubDate>Wed, 03 Jun 2009 17:59:39 +0000</pubDate> <dc:creator>Jack Wallen</dc:creator> <category><![CDATA[Advice]]></category> <category><![CDATA[Linux]]></category> <category><![CDATA[Open Source]]></category> <category><![CDATA[Tutorials Basic]]></category> <category><![CDATA[$PATH]]></category> <category><![CDATA[executable files]]></category> <guid
isPermaLink="false">http://www.ghacks.net/2009/06/03/adding-a-directory-to-your-path/</guid> <description><![CDATA[In the Linux operating system the $PATH is a listing of all directories where the system will look for commands. What this means is that all of the commands located in the directories included in your path will be globally executable. For example: The /usr/bin directory contains quite a lot of commands that can be [...]]]></description> <content:encoded><![CDATA[<p>In the Linux operating system the $PATH is a listing of all directories where the system will look for commands. What this means is that all of the commands located in the directories included in your path will be globally executable. For example: The <strong>/usr/bin</strong> directory contains quite a lot of commands that can be excuted from within any directory on your system. Because of this you can issue the <em>ls</em> command from within any directory and get the listing of the contents of that directory. If the <em>ls</em> command wasn&#8217;t in a directory in your path you would have to include the explicite path to that command (i.e. <strong>/usr/bin/ls</strong>).</p><p>As a Linux user you can add directories to your $PATH. This is helpful when you don&#8217;t want to add a command to a directory in your $PATH but you want that command to be globally executable. Doing this is actually quite easy.</p><p><span
id="more-13264"></span><strong>What is currently in your $PATH?</strong></p><p>NOTE: This article applies only when you are using the Bash shell. To find out what directories are included in your current $PATH issue the command:</p><p><em>echo $PATH</em></p><p>You should see something like:</p><p><code>/usr/lib/qt-3.3/bin:/usr/kerberos/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/jlwallen/bin</code></p><p>Notice the <strong>/opt</strong> directory is missing. Often the <strong>/opt</strong> directory is a great place to &#8220;install&#8221; other applications for global use. But if this directory is not in your $PATH, you will always have to use the explicit path to call a command. With that in mind let&#8217;s add <strong>/opt</strong>.</p><p><strong>.bash_profile</strong></p><p>In order to add a directory you have to edit a file in your ~/ (home) directory. The <strong>.bash_profile</strong> file determines user specific environment and start up programs. This file also  checks for a <strong>.bashrc</strong> file for aliases and functions, but that has nothing to do with your $PATH.</p><p>There is one particular line you need to examine in your <strong>.bash_profile</strong>:</p><p><code>PATH=$PATH:$HOME/bin</code></p><p>This is the line that determines anything extra in your $PATH. As you can see, in the example above, the extra directory added to the users&#8217; $PATH is the <strong>~/bin</strong> directory. Of course in most distributions this isn&#8217;t used (or even created during installation). Why <strong>~/bin</strong> is still included I do not know. In order to add another directory to your $PATH in this line you would seperate the directories with a &#8220;:&#8221;. To add the <strong>/opt</strong> directory that line would now look like:</p><p><code>PATH=$PATH:$HOME/bin:/opt</code></p><p>As you can see the <strong>/opt</strong> directory has been added proceeding a &#8220;:&#8221;. Complete this addition and save the file. You&#8217;re not done yet.</p><p>If you issue the command <em>echo $PATH </em>you will still not see <strong>/opt</strong> in the users&#8217; $PATH. Why? You have to log out and log back in before this change will take effect. So log out, log back in, and issue the command again. Issuing the command <em>echo $PATH</em> will not issue:</p><p><code>/usr/lib/qt-3.3/bin:/usr/kerberos/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/jlwallen/bin:/opt</code></p><p>Any command found in the <strong>/opt</strong> directory is now global.</p><p><strong>Final thoughts</strong></p><p>The $PATH is a very powerful tool to take advantage of in Linux. By using it you can install applications in directories outside of the norm and still make them global. I often install applications in the <strong>/opt</strong> directory or will create a <strong>/data</strong> directory for a more temporary application installation.</p> ]]></content:encoded> <wfw:commentRss>http://www.ghacks.net/2009/06/03/adding-a-directory-to-your-path/feed/</wfw:commentRss> <slash:comments>4</slash:comments> </item> </channel> </rss>
