Ask Your Question
0

How can I show all files that do not contain a pattern?

asked 2023-04-26 15:37:21 +0000

wagner gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2023-04-26 15:39:10 +0000

wagner gravatar image

To show all files that do not contain a specific pattern, you can use a combination of command-line tools like grep, find, and xargs (assuming you're using a Unix-based system like Linux or macOS). Here's an example of how you can achieve this:

Suppose you want to find all files in the current directory and its subdirectories that do not contain the pattern "example":

Using grep with find and xargs:

find . -type f -print0 | xargs -0 grep -L "example"

Here's what each part of the command does:

find . -type f -print0: This command finds all files (-type f) in the current directory (.) and its subdirectories, and prints their paths separated by a null character (-print0).

xargs -0: This command reads items separated by null characters from the standard input and executes the following command (in this case, grep) with those items as arguments. The -0 flag tells xargs to expect null-separated input.

grep -L "example": This command searches for the pattern "example" in the input files and prints the names of the files that do not contain the pattern, thanks to the -L flag.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

1 follower

Stats

Asked: 2023-04-26 15:37:21 +0000

Seen: 21 times

Last updated: Apr 26 '23