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
  • Introduction
  • Installation
    • Default Shell
  • Getting Started
    • Quick Tour
    • Moving Around the System
    • Thinking in Nu
    • Nushell Cheat Sheet
  • Nu Fundamentals
    • Types of Data
    • Loading Data
    • Data Formats
    • Working with SQLite
    • Pipelines
    • Working with Strings
    • Regular Expressions
    • Working with Binary Data
    • Working with Lists
    • Working with Records
    • Working with Numbers
    • Working with Tables
    • Working with Paths
    • Navigating and Accessing Structured Data
    • Special Variables
  • Programming in Nu
    • Custom Commands
    • Aliases
    • Operators
    • Variables
    • Control Flow
    • Scripts
    • Modules
      • Using Modules
      • Creating Modules
    • Overlays
    • Sorting
    • Testing your Nushell Code
    • Debugging Scripts
    • Language Server
    • Best Practices
  • Nu as a Shell
    • Configuration
    • Configuration Reference
    • Environment
    • Stdout, Stderr, and Exit Codes
    • Working with the Terminal
    • Running System (External) Commands
    • How to Configure 3rd Party Prompts
    • Directory Stack
    • Reedline, Nu's Line Editor
    • Custom Completions
    • Externs
    • Coloring and Theming in Nu
    • Hooks
    • Background Jobs
  • Coming to Nu
    • Coming from Bash
    • Coming from CMD.EXE
    • Coming from PowerShell
    • Nu map from other shells and domain specific languages
    • Nu Map from Imperative Languages
    • Nu Map from Functional Languages
    • Nushell operator map
  • Design Notes
    • How Nushell Code Gets Run
  • (Not So) Advanced
    • Standard Library
      • std/assert
      • std/bench
      • std/clip
      • std/config
      • std/dt
      • std/formats
      • std/help
      • std/input
      • std/iter
      • std/log
      • std/math
      • std/random
      • std/util
      • std/xml
      • std-rfc
    • Dataframes
      • Dataframe Operations
      • Column Selectors
      • Math Expressions
      • String Expressions
      • Dates and Times in Dataframes
      • Masks and Conditionals
      • Aggregations and Window Functions
    • Metadata
    • Creating Your Own Errors
    • Parallelism
    • Plugins
    • explore
    • Building TUIs with tui
    • MCP Server

Coming from Bash

Tips

If you're coming from Git Bash on Windows, then the external commands you're used to (e.g, ln, grep, vi, etc) will not be available in Nushell by default unless you have already explicitly made them available in the Windows Path environment variable. To make these commands available in Nushell as well, add the following line to your config.nu with either append or prepend.

$env.Path = ($env.Path | prepend 'C:\Program Files\Git\usr\bin')

Command Equivalents:

BashNuTask
lslsLists the files in the current directory
ls <dir>ls <dir>Lists the files in the given directory
ls pattern*ls pattern*Lists files that match a given pattern
ls -lals --long --all or ls -laList files with all available information, including hidden files
ls -d */ls | where type == dirList directories
find . -name *.rsls **/*.rsFind recursively all files that match a given pattern
find . -name Makefile | xargs vimls **/Makefile | get name | vim ...$inPass values as command parameters
cd <directory>cd <directory>Change to the given directory
cdcdChange to the home directory
cd -cd -Change to the previous directory
mkdir <path>mkdir <path>Creates the given path
mkdir -p <path>mkdir <path>Creates the given path, creating parents as necessary
touch test.txttouch test.txtCreate a file
> <path>out> <path> or o> <path>Save command output to a file
| save <path>Save command output to a file as structured data
>> <path>out>> <path> or o>> <path>Append command output to a file
| save --append <path>Append command output to a file as structured data
> /dev/null| ignoreDiscard command output
> /dev/null 2>&1out+err>| ignore or o+e>| ignoreDiscard command output, including stderr
command 2>&1 | lesscommand out+err>| less or command o+e>| lessPipe stdout and stderr of an external command into less (NOTE: use explore for paging output of internal commands)
cmd1 | tee log.txt | cmd2cmd1 | tee { save log.txt } | cmd2Tee command output to a log file
command | head -5command | first 5Limit the output to the first 5 rows of an internal command (see also last and skip)
cat <path>open --raw <path>Display the contents of the given file
open <path>Read a file as structured data
cat <(<command1>) <(<command2>)[(command1), (command2)] | str joinConcatenate the outputs of command1 and command2
cat <path> <(<command>)[(open --raw <path>), (command)] | str joinConcatenate the contents of the given file and output of command
mv <source> <dest>mv <source> <dest>Move file to new location
for f in *.md; do echo $f; donels *.md | each { $in.name }Iterate over a list and return results
for i in $(seq 1 10); do echo $i; donefor i in 1..10 { print $i }Iterate over a list and run a command on results
cp <source> <dest>cp <source> <dest>Copy file to new location
cp -r <source> <dest>cp -r <source> <dest>Copy directory to a new location, recursively
rm <path>rm <path>Remove the given file
rm -t <path>Move the given file to the system trash
rm -rf <path>rm -r <path>Recursively removes the given path
date -d <date>"<date>" | into datetime -f <format>Parse a date (format documentation)
date -d "tomorrow""tomorrow" | date from-humanParse a human-readable date
date from-human --listShow example phrases that date from-human understands
sedstr replaceFind and replace a pattern in a string
grep <pattern>where $it =~ <substring> or find <substring>Filter strings that contain the substring
grep -i <pattern>find -i <substring>Filter strings that contain the substring, ignoring case
grep -o <regex>find -o -r <regex>Output only the matched text, one value per match
grep -v <pattern>find -v <substring>Filter strings that don't contain the substring
man <command>help <command>Get the help for a given command
help commandsList all available commands
help --find <string>Search for match in all available commands
command1 && command2command1; command2Run a command, and if it's successful run a second
command1 || command2try { command1 } catch { command2 }Run a command, and if it fails run a second
stat $(which git)stat ...(which git).pathUse command output as argument for other command
echo /tmp/$RANDOM$"/tmp/(random int)"Use command output in a string
cargo b --jobs=$(nproc)cargo b $"--jobs=(sys cpu | length)"Use command output in an option
echo $PATH$env.PATH (Non-Windows) or $env.Path (Windows)See the current path
echo $?$env.LAST_EXIT_CODESee the exit status of the last executed command
set -o pipefail(default behavior)Fail a pipeline if any external command in it fails
<update ~/.bashrc>vim $nu.config-pathUpdate PATH permanently
export PATH = $PATH:/usr/other/bin$env.PATH = ($env.PATH | append /usr/other/bin)Update PATH temporarily
export$envList the current environment variables
<update ~/.bashrc>vim $nu.config-pathUpdate environment variables permanently
FOO=BAR ./binFOO=BAR ./binUpdate environment temporarily
export FOO=BAR$env.FOO = "BAR"Set environment variable for current session
echo $FOO$env.FOOUse environment variables
echo ${FOO:-fallback}$env.FOO? | default "ABC"Use a fallback in place of an unset variable
unset FOOhide-env FOOUnset environment variable for current session
alias s="git status -sb"alias s = git status -sbDefine an alias temporarily
type FOOwhich FOODisplay information about a command (builtin, alias, or executable)
type -a FOOwhich -a FOOList the Nushell command and each executable in PATH with that name
type -P FOOwhich ^FOOLook up only the external program, skipping Nushell commands
compgen -cwhichList every Nushell command and every executable in PATH
<update ~/.bashrc>vim $nu.config-pathAdd and edit alias permanently (for new shells)
bash -c <commands>nu -c <commands>Run a pipeline of commands
bash <script file>nu <script file>Run a script file
\( <command> )A command can span multiple lines when wrapped with ( and )
pwd or echo $PWDpwd or $env.PWDDisplay the current directory (pwd returns $env.PWD)
pwd -Ppwd -P or pwd --physicalDisplay the current directory with symbolic links resolved
read varlet var = inputGet input from the user
read -s secretlet secret = input -sGet a secret value from the user without printing keystrokes

Tips

In Nushell, type is the keyword that declares a type alias, so type FOO is a parse error rather than a command lookup. Use which FOO instead. If your system has an external type program (macOS has /usr/bin/type), run it as ^type FOO.

which returns a table with command, path and type columns. path is empty for a built-in command, and for a custom command or an alias it names the file that defines it. An alias also gets a definition column. Pass several names to look them up at once. A name that isn't found adds no row, so which nosuch returns an empty list.

Tips

Nushell rejects &&, ||, 2> and 2>&1 with a parse error that names the Nushell replacement. A lone > gets no error and writes no file. But it's not Bash shows what it does instead.

More about find and date from-human

find also searches tables. It keeps the rows where any cell matches, or only the cells in the columns you name with --columns. It wraps each match in ANSI color codes so that it stands out. Add --no-highlight (-n) to keep the values unchanged, for example before saving them. A number or file size used as the search term matches equal numbers and file sizes, not digits inside other numbers, so [1 10 21] | find 1 returns only 1.

With several search terms, find keeps the values that match any of them, so [apple banana cherry date] | find an er returns banana and cherry. --regex (-r) takes the pattern as its value, as in find --regex 'an|er', and replaces the search terms, so passing both is an Incompatible parameters error. The same error comes from --invert (-v) together with --only-matching (-o), and from --dotall without --regex.

find splits a multi-line string into lines and returns the lines that match. With --multiline (-m), it searches the whole string as one value. --multiline doesn't take a byte stream, such as the output of an external command, so collect the output into a string first: ^cat notes.txt | collect | find -m 'a'. In regex mode, --dotall (-s) lets . match a newline. --rfind (-R) highlights only the last match, and with -o it returns only the last match.

date from-human understands phrases such as Last Friday at 19:45, In 5 minutes and 30 seconds, 10 hours and 5 minutes ago and Now. date from-human --list shows more, with the date each one gives right now. Piping in a list converts each string. A phrase it can't parse fails with "Cannot parse as humanized date", and running it with no input fails with "Pipeline empty".

History Substitutions and Default Keybindings:

BashNuTask
!!!!Insert last command-line from history
!$!$Insert last spatially separated token from history
!<n> (e.g., !5)!<n>Insert <n>th command from the beginning of the history
Tip: history | enumerate | last 10 to show recent positions
!<-n> (e.g., !-5)!<-n>Insert <n>th command from the end of the history
!<string> (e.g., !ls)!<string>Insert the most recent history item that begins with the string
Ctrl/Cmd+RCtrl/Cmd+RReverse history search
(Emacs Mode) Ctrl+XCtrl+ECtrl/Cmd+OEdit the command-line in the editor defined by $env.EDITOR
(Vi Command Mode) VCtrl/Cmd+OEdit the command-line in the editor defined by $env.EDITOR

Most common Emacs-mode and Vi-mode keybindings are also available. See the Reedline Chapter.

Tips

In Bash, history substitution occurs immediately after pressing Enter to execute the command-line. Nushell, however, inserts the substitution into the command-line after pressing Enter. This allows you to confirm the substitution and, if needed, make additional edits before execution.

With SQLite history, !<string> first looks for the most recent matching command that was run in the current directory. Only when there is none does it search the rest of the history. The plain-text history file doesn't record directories, so with it !<string> always searches the whole history.

This behavior extends to "Edit command-line in Editor" as well. While Bash immediately executes the command after exiting the editor, Nushell (like other, more modern shells such as Fish and Zsh) inserts the editor contents into the command-line, allowing you to review and make changes before committing it to execution.

Edit this page on GitHub
Contributors: Carson Black, Ibraheem Ahmed, Jonathan Turner, ammkrn, JT, Hristo Filaretov, Tw, Arnout Engelen, jntrnr, fdncred, Justin Ma, Herlon Aguiar, chtenb, Kyle J Strand, Carson Riker, Homa Wong, Christopher Durham, Kayla Washburn, 1submarine, Zhora Trush, Alex Saveau, Leon, debemdeboas, Aidan Gauland, Tomas Zemanovic, amtoine, Lucas Kent, Motalleb Fallahnezhad, c4lliope, Vladimir Budylnikov, Ian Manske, NotTheDr01ds, Hofer-Julian, paulie4, Kieron Wilkinson, 0x4D5352, Roland Marchand, Jan Klass, tkr-sh, acxz, Taeyoon Kim, ImgBotApp, google-labs-jules[bot], deepthought, wahidrizka
Prev
Coming to Nu
Next
Coming from CMD.EXE