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”. 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 Related posts:How to get the directory path and file name from a absolute path in C on Linux How to find Linux absolute path for a relative path How to test whether PATH has a specific directory in it in Bash on Linux? How to test whether a given path is a directory or a file in C++? How to get another user’s PATH in Bash on Linux? How to get the full path and directory of a Makefile itself? How to remove trailing / in path in Bash? Maximum allowed file path length for C programming on Linux?