Bootstrap FreeKB - Linux Commands - Return directory name using dirname
Linux Commands - Return directory name using dirname

Updated:   |  Linux Commands articles

The dirname command returned the full directory name, for example.

~]# dirname /home/john.doe/Documents/foo.txt
/home/john.doe

 

You can pass is multiple paths.

~]$ dirname /home/john.doe/Documents/foo.txt /home/jane.doe/Documents/bar.txt
/home/john.doe
/home/jane.doe

 

And here is an example in a bash shell script.

#!/bin/bash

files=(/home/john.doe/Documents/foo.txt /home/john.doe/Documents/bar.txt /home/jane.doe/Documents/foo.txt /home/jane.doe/Documents/bar.txt)

for file in ${files[@]}; do
        dirname $file
done

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 708dbe in the box below so that we can be sure you are a human.