tutaphil.blogg.se

Grep all files in a directory
Grep all files in a directory




As you’ll see below, you can also add -i for case-insensitive searches.The -l option (lowercase letter L) says “list only filenames”.The -r option says “do a recursive search”.However, I was just reminded that a much easier way to perform the same recursive search is with the -r flag of the grep command:Īs you can see, this is a much shorter command, and it performs the same recursive search as the longer command, specifically: This command can be read as, “Search all files in all subdirectories of the current directory for the string ‘alvin’, and print the filenames that contain this pattern.” It’s an extremely powerful approach for recursively searching files in all subdirectories that match the pattern I specify.

grep all files in a directory grep all files in a directory grep all files in a directory

Solution 1: Combine 'find' and 'grep'įor years I always used variations of the following Linux find and grep commands to recursively search subdirectories for files that match a grep pattern:įind. Two solutions are shown next, followed by some additional details which may be useful. Unix/Linux grep FAQ: How can I perform a recursive search with the grep command in Linux?






Grep all files in a directory