<?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>Dirname &#8211; Hostry Help Center</title>
	<atom:link href="https://help.hostry.com/article-tags/dirname/feed/" rel="self" type="application/rss+xml" />
	<link>https://help.hostry.com</link>
	<description>Full information on how to use HOSTRY, provided by 24/7 community based support</description>
	<lastBuildDate>Wed, 10 Jun 2020 07:23:31 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=5.9.12</generator>

<image>
	<url>https://help.hostry.com/wp-content/uploads/cache/2021/01/cropped-apple-icon-180x180-1/836712163.png</url>
	<title>Dirname &#8211; Hostry Help Center</title>
	<link>https://help.hostry.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>How To Use The Dirname Command on Linux Bash scripts</title>
		<link>https://help.hostry.com/knowledge-base/how-to-use-the-dirname-command-on-linux-bash-scripts/</link>
					<comments>https://help.hostry.com/knowledge-base/how-to-use-the-dirname-command-on-linux-bash-scripts/#comments</comments>
		
		<dc:creator><![CDATA[Alex]]></dc:creator>
		<pubDate>Wed, 10 Jun 2020 07:23:31 +0000</pubDate>
				<guid isPermaLink="false">https://help.hostry.com/?post_type=ht_kb&#038;p=1761</guid>

					<description><![CDATA[The dirname command on Linux prints the path to the file with the last component removed. This basically gives you the directory path from the file path. The dirname command complements the basename command. The basename command retrieves the file name from the path, while dirname retrieves the directory path. [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p>The <strong><em>dirname</em></strong> command on Linux prints the path to the file with the last component removed. This basically gives you the directory path from the file path. The dirname command complements the basename command. The basename command retrieves the file name from the path, while dirname retrieves the directory path.</p>



<h2 id="dirname-command-examples" >Dirname Command Examples</h2>



<p>Dirname command has very simple syntax</p>



<pre class="wp-block-preformatted">dirname OPTION PATH</pre>



<p>Using the command will give the directory path:</p>



<pre class="wp-block-preformatted">dirname /home/user/data/filename.txt
/home/user/data</pre>



<p>Like the basename command, the dirname command is actually primitive. It really does not recognize the file path. It just searches for slashes (/) and prints everything that is before the last slash. In fact, you can ask him any line with / in it, and it will work with it. For example: a random string without a file name is very often used. It is possible to see that it still works the same way and displays a line, deleting the last / and the text after it</p>



<pre class="wp-block-preformatted">destroyer@hostry: ~$ dirname dir1/dir2/dir3/dir4
dir1/dir2/dir3
destroyer@hostry: ~$</pre>



<p>If there is no forward slash <strong>(/) </strong>in the path, a period <strong>(.)</strong> Will be displayed, indicating the current directory</p>



<pre class="wp-block-preformatted">destroyer@hostry: ~$ dirname hostry.txt
.
destroyer@hostry: ~$</pre>



<p>You can also use dirname with several paths. It will return the output for each path in a new line:</p>



<pre class="wp-block-preformatted">destroyer@histry: ~$ dirname dir1/file dir2/file
dir1
dir2
destroyer@hostry: ~$</pre>



<p>You can use the <strong>-z</strong> option to get the result on the same line as the output, separated by a NULL character.</p>



<h2 id="using-dirname-in-a-bash-script" >Using Dirname in a <strong>B</strong>ash Script </h2>



<p>Some examples of using the dirname command have been shown. Now, for example, the following will be taken: you have a file path variable and you need to get the path to the directory where this file is located. It could be a very simple script</p>



<pre class="wp-block-preformatted">pathname="/home/dir/data/filename"
result=$(dirname "$pathname")
echo $result</pre>



<p>As mentioned earlier, the dirname command is complemented by the basename command. Unlike dirname, the basename command prints only the last component of the path.</p>



<p></p>
]]></content:encoded>
					
					<wfw:commentRss>https://help.hostry.com/knowledge-base/how-to-use-the-dirname-command-on-linux-bash-scripts/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
	</channel>
</rss>
