Extract Directory and Filename from File Paths in Bash
When you have an absolute path like /foo/bar/baz.txt and need to split it into its components, Bash provides two essential utilities: dirname and basename. Using dirname and basename The dirname command returns the directory portion of a path, while basename returns just the filename: p=”/foo/bar/baz.txt” dirname “$p” # Output: /foo/bar basename “$p” # Output: baz.txt…
