Linux Challenge Lab 4 - grep syntax

Hi,

In the Linux Challenge Lab 4 there is a task to find all files that have a word in them ending with the letter “t”. After getting stuck on this for a while I looked up the solution and found this repository, and the answer impressed me quite a bit, as I’ve never seen this syntax:

rm -f $(find /opt/appdata/ -type f -exec grep -l 't\>' "{}"  \; )

Could someone kindly explain what the grep -l 't\> part is doing? Thank you,

  • The -l (lowercase L) option tells grep to print only the names of files where a match is found, instead of the usual output of the matching lines.
  • The pattern 't\>' is what grep is searching for in each file:
    • t is the character we’re looking to find.
    • \> is a special pattern in grep, which stands for a “word boundary”. It ensures that the character t is at the end of a word. This word boundary matches positions where a word character (like letters and digits) is followed by a non-word character or the end of a line.
1 Like

That is very revealing, I’m learning so much already. Thanks again for all the help.