1

It's a bit strange with the grep command. When I am in the mail folder, it always produces help text. At first, I thought I had wrong synxtax but it is working on its parent folder. What could be the cause? TIA!

[xx]$ grep "abc" *.out
grep: invalid option -- '-'
Usage: grep [OPTION]... PATTERN [FILE]...
Try 'grep --help' for more information.
[xx]$ cd ..
[xx]$ grep "abc" mail/*.out
mail/0940-cron-mail.out:News 3598...h...N
Dat TT
  • 111
  • 2
  • Could help : https://unix.stackexchange.com/questions/364922/grep-getting-confused-by-filenames-with-dashes – krisFR Nov 03 '17 at 07:05

1 Answers1

3

You have a file in that directory that starts with the character '-'.

When you grep in the directory, the * expands out all the filenames, and grep interprets the one with the leading - as an option, and fails to parse it.

When your grep includes the directory path, the * still expands the filenames out, but now the - is in the middle of the path+filename, so isn't interpreted as a commandline option

Daniel Lawson
  • 5,476
  • 22
  • 27