Commands

basename

NAME [SUFFIX]

This command takes a full UNIX path and displays only the last element. It is generally used in scripting. If the optional suffix is supplied and it matches the last element, it is stripped away as well.

Example: Suppose your current working directory is /var/spool/ mail. In that case,

basename $PWD

would display

mail

Of course, basename can be used on text strings as well as environment variables, and

basename /var/spool/mail

would also display

mail

--help Display usage information.
--version Display version information.

dirname

NAME

This command takes a full UNIX path and displays all but the last element. The command is generally used in scripting.

Example: Suppose you were writing a script that needed ...

Get Linux® Desk Reference, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.