Usually, pathnames are modified through the two utilities
dirname, or through parameter substitutions, rather than by line-based text editing utilities.
This is because, technically, pathnames may contain newlines, which would make it difficult to work on the reliably with line-based tools such as
The example that you have is to get the pathname of the parent directory of
/home/test/var/opt. This is best done with
This would return
/home/test/var. This would work even if the given pathname had a
/ at the end.