Can't get "grep -F" to work like real grep
Quentin Rameau
quinq at fifth.space
Mon Dec 9 20:01:04 UTC 2019
> <Appologies: re-sent as the previous version got corrupted by "rich text"
> fields in the email>
Hi Paul,
> I hope I'm doing something mindnumbingly stupid; grep -F output is not as
> expected. Please can anyone spot the problem? Thanks.
>
> (Background: I'm writing a script to manage kernel images in /boot, and want
> to prevent the user deleting the kernel currently being executed.)
>
> This is sys-apps/busybox-1.30.1 on Gentoo,
> compared with sys-apps/busybox-1.30.1
> all running on an amd64 box.
>
> Running in /boot, where:
>
> acer /boot # ls vmlinuz-*
> vmlinuz-5.1.16-gentoorx570 vmlinuz-5.3.12-gentoorx570.new
>
> acer /boot # uname -v
> #6 SMP Sun Sep 29 00:17:32 BST 2019
>
> Linux grep produces:
> acer /boot # grep -Fl "#6 SMP Sun Sep 29 00:17:32 BST 2019" vmlinuz-*
> vmlinuz-5.1.16-gentoorx570
>
> whereas busybox grep produces no matches. Removing the -F fixes it:
> acer /boot # busybox grep -l "#6 SMP Sun Sep 29 00:17:32 BST 2019" vmlinuz-*
> vmlinuz-5.1.16-gentoorx570
>
> In case it was some weird issue with globbing or UTF-8 etc.,
> I tried:
> acer /boot # uname -v > ver
> acer /boot # busybox grep -Flf ver vmlinuz-*
>
> Still no output, but:
> acer /boot # busybox grep -lf ver vmlinuz-*
> vmlinuz-5.1.16-gentoorx570
>
>
> (I know "file vmlinuz" can pull the necessary info, but "file" isn't in busybox.
> I'll listen to alternatives.)
The grep utility is specified to work on text files.
I suppose your vmlinuz-5.1.16-gentoorx570 file is a compressed binary
Linux kernel, so not text.
From that, you can't really expect a text tool to work on binary data.
More information about the busybox
mailing list