0

I need to search a file in unix which starts with "catalina"

 find ... what to be used effectively -name, -exec ? Whats the expression

Also I need to show few files at a time, then show some more. There are huge set of log files in there. I know there is some expression, but forgot...

Some Java Guy
  • 4,992
  • 19
  • 71
  • 108
  • Do you want to search for a file - or search within those files matching *catalina? – Joel Feb 08 '11 at 09:57

2 Answers2

1

find /path/to/search/in -name 'catalina*'

Use iname to match case-insensitively.

To not be overwhelmed with a long list of files, filter through less (append |less). You can also use more instead of less.

sleske
  • 81,358
  • 34
  • 189
  • 227
  • Still standard way is to use `more`, not `less`. –  Feb 08 '11 at 09:58
  • @pooh: Well, "standard way" is always open to debate. Only Linux, `less` is pretty much the standard, but to each his own :-). – sleske Feb 08 '11 at 10:13
  • there's **unix** in the topic, that's why first i think of POSIX `more`. –  Feb 08 '11 at 11:10
  • @pooh: OK, you have a point. But then, most Unices have a port of `less`. Might not be the standard, though. I edited my answer. – sleske Feb 08 '11 at 11:38
0

If catalina is the file name, then use

find -name 'catalina*'

If catalina is the first word contained in the file, then use

find -type f | xargs head -v -n 1 | grep -B 1 -A 1 -e '^catalina'
Didier Trosset
  • 36,376
  • 13
  • 83
  • 122
  • Note that you can do this without `find`, at least in simple cases, as grep can recurse itself (`grep -r`). Also, you *really* should always use `find -print0... xargs -0` when combining with `xargs`, otherwise funny filenames may (read: *will*) bite you. – sleske Feb 08 '11 at 10:14