Extract directory from path

Matt picture Matt · Jun 28, 2011 · Viewed 76.3k times · Source

In my script I need the directory of the file I am working with. For example, the file="stuff/backup/file.zip". I need a way to get the string "stuff/backup/" from the variable $file.

Answer

Matthieu picture Matthieu · Jun 28, 2011
dirname $file

is what you are looking for