dirname

The dirname command will give you the path of the file that you provide as parameter, up to its parent directory. If the parameter is an absolute path, the absolute containing directory will be returned, otherwise it will be the relative path.

For example, for the file /home/marios/.bash_aliases:

{% highlight bash %} [email protected]:~$ dirname /home/marios/.bashaliases /home/marios [email protected]:~$ dirname ~/.bashaliases /home/marios ma[email protected]:~$ dirname .bash_aliases . {% endhighlight %}

See also

Posted on