How to get the directory path and file name from a absolute path in Bash on Linux?

How to get the directory path and file name from a absolute path in Bash on Linux? For example, with "/foo/bar/baz.txt", it will produce: "/foo/bar/" and "baz.txt".

asked Feb 15, 2015 by anonymous

1 Answer

You also have the basename and dirname commands besides of the basename and dirname C API in Linux:

[zma@laptop:~]$ p="/foo/bar/baz.txt"
[zma@laptop:~]$ dirname $p
/foo/bar
[zma@laptop:~]$ basename $p
baz.txt
answered Feb 15, 2015 by Eric Z Ma (44,280 points)

Please log in or register to answer this question.

Copyright © SysTutorials. User contributions licensed under cc-wiki with attribution required.
Hosted on Dreamhost

...