Home Explore Blog CI



nushell

2nd chunk of `book/coming_from_bash.md`
f092b01aadc324510ff53a802adfc19d0fcc660541855d330000000100001008
| `> <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`                        | `\| ignore`                                                   | Discard command output                                            |
| `> /dev/null 2>&1`                   | `out+err>\| ignore` or `o+e>\| ignore`                        | Discard command output, including stderr                          |
| `command 2>&1 \| less`               | `command out+err>\| less` or `command o+e>\| less`            | Pipe stdout and stderr of an external command into less (NOTE: use [explore](explore.html) for paging output of internal commands) |
| `cmd1 \| tee log.txt \| cmd2`        | `cmd1 \| tee { save log.txt } \| cmd2`                        | Tee command output to a log file                                  |
| `command \| head -5`                 | `command \| first 5`                                          | Limit 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                                    |
| `mv <source> <dest>`                 | `mv <source> <dest>`                                          | Move file to new location                                         |
| `for f in *.md; do echo $f; done`    | `ls *.md \| each { $in.name }`                                | Iterate over a list and return results                            |
| `for i in $(seq 1 10); do echo $i; done` | `for 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](https://docs.rs/chrono/0.4.15/chrono/format/strftime/index.html)) |
| `sed`                                | `str replace`                                                 | Find and replace a pattern in a string                            |
| `grep <pattern>`                     | `where $it =~ <substring>` or `find <substring>`              | Filter strings that contain the substring                         |
| `man <command>`                      | `help <command>`                                              | Get the help for a given command                                  |

Title: Bash to Nushell: Command Equivalents (Continued)
Summary
This section continues the comparison of Bash and Nushell commands, focusing on output redirection, piping, file manipulation, iteration, date parsing, string replacement, filtering, and accessing command help. It provides Nushell equivalents for Bash commands related to discarding output, teeing output to a log file, limiting output rows, displaying file content (raw and structured), moving/copying/removing files and directories, iterating over lists, parsing dates, string replacement via `str replace`, and filtering strings using `where` or `find`. It also shows how to access help documentation.