Nushell
Get Nu!
Getting Started
  • The Nushell Book
  • Command Reference
  • Cookbook
  • Language Reference Guide
  • Contributing Guide
Blog
  • English
  • 中文
  • Deutsch
  • Français
  • Español
  • 日本語
  • Português do Brasil
  • Русский язык
GitHub
Get Nu!
Getting Started
  • The Nushell Book
  • Command Reference
  • Cookbook
  • Language Reference Guide
  • Contributing Guide
Blog
  • English
  • 中文
  • Deutsch
  • Français
  • Español
  • 日本語
  • Português do Brasil
  • Русский язык
GitHub
  • Categories

    • Bits
    • Bytes
    • Chart
    • Conversions
    • Core
    • Database
    • Dataframe
    • Dataframe Or Lazyframe
    • Date
    • Debug
    • Default
    • Env
    • Experimental
    • Expression
    • Filesystem
    • Filters
    • Formats
    • Generators
    • Hash
    • History
    • Lazyframe
    • Math
    • Misc
    • Network
    • Path
    • Platform
    • Plugin
    • Prompt
    • Random
    • Removed
    • Shells
    • Strings
    • System
    • Viewers

path parse for path

Convert a path into structured data.

Signature

> path parse {flags}

Flags

  • --extension, -e {string}: Manually supply the extension (without the dot)

Input/output types:

inputoutput
stringrecord
list<string>table

Examples

Parse a path

> '/home/viking/spam.txt' | path parse
╭───────────┬──────────────╮
│ parent    │ /home/viking │
│ stem      │ spam         │
│ extension │ txt          │
╰───────────┴──────────────╯

Replace a complex extension

> '/home/viking/spam.tar.gz' | path parse --extension tar.gz | upsert extension { 'txt' }

Ignore the extension

> '/etc/conf.d' | path parse --extension ''
╭───────────┬────────╮
│ parent    │ /etc   │
│ stem      │ conf.d │
│ extension │        │
╰───────────┴────────╯

Parse all paths in a list

> [ /home/viking.d /home/spam.txt ] | path parse
╭───┬────────┬────────┬───────────╮
│ # │ parent │  stem  │ extension │
├───┼────────┼────────┼───────────┤
│ 0 │ /home  │ viking │ d         │
│ 1 │ /home  │ spam   │ txt       │
╰───┴────────┴────────┴───────────╯

Notes

Each path is split into a table with 'parent', 'stem' and 'extension' fields. On Windows, an extra 'prefix' column is added.