path basename

For path.

Get the final component of a path.

Command Type

built-in

Signature

> path basename {flags}

Flags

  • --replace, -r {string}: Return original path with basename replaced by this string.

Input/output types:

input output
string string
list<string> list<string>

Examples

Get basename of a path.

> '/home/joe/test.txt' | path basename
test.txt

Get basename of a list of paths.

> [ /home/joe, /home/doe ] | path basename
╭───┬─────╮
│ 0 │ joe │
│ 1 │ doe │
╰───┴─────╯

Replace basename of a path.

> '/home/joe/test.txt' | path basename --replace 'spam.png'
/home/joe/spam.png

Ported from nushell/nushell.github.io. Copyright (c) 2021 Nushell Project. MIT License.