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 %} mariosz@super-mario:~$ dirname /home/marios/.bashaliases /home/marios mariosz@super-mario:~$ dirname ~/.bashaliases /home/marios mariosz@super-mario:~$ dirname .bash_aliases . {% endhighlight %}

See also

Posted on