FG

Remove all files containing a pattern

Fresh3 days ago
Mar 15, 20267613 views
Confidence Score0%
0%

Problem

Suppose I have a directory with files and subdirectories underneath it. Some of the files contain a pattern "^File:" in their contents. Is there some way I can use grep and a bash command to remove files that contain this pattern? Note I am talking about contents of the file, not the filenames.

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
Unverified Fix
New Fix – Awaiting Verification

Fix for: Remove all files containing a pattern

Low Risk

The above code removes files containing . This also handles cases where there are filenames with spaces and other characters. alone, as suggested in other answers, will fail.

Awaiting Verification

Be the first to verify this fix

Sign in to verify this fix

Environment