diff --git a/crates/nu-command/src/filesystem/ls.rs b/crates/nu-command/src/filesystem/ls.rs index d60df4ca01..961de3d96e 100644 --- a/crates/nu-command/src/filesystem/ls.rs +++ b/crates/nu-command/src/filesystem/ls.rs @@ -224,6 +224,22 @@ impl Command for Ls { example: "ls *.rs", result: None, }, + Example { + description: "List all files and directories whose name do not contain 'bar'", + example: "ls -s | where name !~ bar", + result: None, + }, + Example { + description: "List all dirs with full path name in your home directory", + example: "ls -f ~ | where type == dir", + result: None, + }, + Example { + description: + "List all dirs in your home directory which have not been modified in 7 days", + example: "ls -s ~ | where type == dir && modified < ((date now) - 7day)", + result: None, + }, ] } } diff --git a/crates/nu-command/src/filters/reduce.rs b/crates/nu-command/src/filters/reduce.rs index 174ca2749b..c81955d602 100644 --- a/crates/nu-command/src/filters/reduce.rs +++ b/crates/nu-command/src/filters/reduce.rs @@ -46,6 +46,14 @@ impl Command for Reduce { span: Span::test_data(), }), }, + Example { + example: "[ 1 2 3 ] | reduce -n {|it, acc| $acc + $it.item }", + description: "Sum values of a list (same as 'math sum')", + result: Some(Value::Int { + val: 6, + span: Span::test_data(), + }), + }, Example { example: "[ 1 2 3 4 ] | reduce -f 10 {|it, acc| $acc + $it }", description: "Sum values with a starting value (fold)", diff --git a/crates/nu-command/src/filters/where_.rs b/crates/nu-command/src/filters/where_.rs index 9eb10fb51e..7e92b338b5 100644 --- a/crates/nu-command/src/filters/where_.rs +++ b/crates/nu-command/src/filters/where_.rs @@ -96,7 +96,7 @@ impl Command for Where { }, Example { description: "List all files that were modified in the last two weeks", - example: "ls | where modified <= 2wk", + example: "ls | where modified >= (date now) - 2wk", result: None, }, ] diff --git a/docs/commands/ls.md b/docs/commands/ls.md index 0e479ab1e8..54e8d7dc42 100644 --- a/docs/commands/ls.md +++ b/docs/commands/ls.md @@ -35,3 +35,18 @@ List all rust files ```shell > ls *.rs ``` + +List all files and directories whose name do not contain 'bar' +```shell +> ls -s | where name !~ bar +``` + +List all dirs with full path name in your home directory +```shell +> ls -f ~ | where type == dir +``` + +List all dirs in your home directory which have not been modified in 7 days +```shell +> ls -s ~ | where type == dir && modified < ((date now) - 7day) +``` diff --git a/docs/commands/reduce.md b/docs/commands/reduce.md index eda6593314..7fefd2af03 100644 --- a/docs/commands/reduce.md +++ b/docs/commands/reduce.md @@ -23,6 +23,11 @@ Sum values of a list (same as 'math sum') > [ 1 2 3 4 ] | reduce {|it, acc| $it + $acc } ``` +Sum values of a list (same as 'math sum') +```shell +> [ 1 2 3 ] | reduce -n {|it, acc| $acc + $it.item } +``` + Sum values with a starting value (fold) ```shell > [ 1 2 3 4 ] | reduce -f 10 {|it, acc| $acc + $it } diff --git a/docs/commands/where.md b/docs/commands/where.md index 793d16fbc3..4531a7e8bb 100644 --- a/docs/commands/where.md +++ b/docs/commands/where.md @@ -33,5 +33,5 @@ List all files with names that contain "Car" List all files that were modified in the last two weeks ```shell -> ls | where modified <= 2wk +> ls | where modified >= (date now) - 2wk ```