diff --git a/src/uu/tail/src/tail.rs b/src/uu/tail/src/tail.rs index 3a16f670b63..4e570d0676e 100644 --- a/src/uu/tail/src/tail.rs +++ b/src/uu/tail/src/tail.rs @@ -403,6 +403,10 @@ fn forwards_thru_file( /// `num_delimiters` instance of `delimiter`. The `file` is left seek'd to the /// position just after that delimiter. fn backwards_thru_file(file: &mut File, num_delimiters: u64, delimiter: u8) { + if num_delimiters == 0 { + file.seek(SeekFrom::End(0)).unwrap(); + return; + } // This variable counts the number of delimiters found in the file // so far (reading from the end of the file toward the beginning). let mut counter = 0; diff --git a/tests/by-util/test_tail.rs b/tests/by-util/test_tail.rs index 3dd0ee0d2d4..3def2eb08a4 100644 --- a/tests/by-util/test_tail.rs +++ b/tests/by-util/test_tail.rs @@ -1125,6 +1125,16 @@ fn test_obsolete_syntax_small_file() { .stdout_is("a\nb\nc\nd\ne\n"); } +/// Test for obsolete syntax `tail -0 FILE`: print nothing and exit cleanly. +#[test] +fn test_obsolete_syntax_zero_lines_file() { + new_ucmd!() + .args(&["-0", "foobar.txt"]) + .succeeds() + .no_stderr() + .no_stdout(); +} + /// Test for reading all lines, specified by `tail -n +0`. #[test] fn test_positive_zero_lines() {