“bash trouver tous les fichiers contenant de la chaîne” Réponses codées

bash trouver tous les fichiers contenant de la chaîne

grep -r '/path/to/somewhere/' -e 'pattern'
Sleepy Scarab

ligne de commande comment trouver tous les fichiers qui ont une chaîne

grep -rnw '/path/to/somewhere/' -e 'pattern'
Disgusted Dolphin

bash trouver des fichiers contenant de la chaîne

# Basic syntax using find..exec:
find /top/dir -mindepth int -maxdepth int -type f -exec grep -H 'string' {} \;
# Note, this might look a bit scary, but it's worth learning
# Where:
#	- find searches recursively through all directories in the /top/directory
#	- -mindepth and maxdepth set the depth of subdirectories to search
#	- -type f indicates that only files should be considered
#	- all files found using the above criteria are iteratively passed to exec 
#		via the curly braces. exec then runs grep which searches for the word
#		'string' in the file
#	- -H tells grep to return the filename along with the matching line

# Basic syntax using find and xargs:
find /top/dir -mindepth int -maxdepth int -type f | xargs grep -H 'string'
# Note, more recently I've been using xargs which is faster and uses syntax
# 	that is, IMO easier to remember than exec
Charles-Alexandre Roy

Réponses similaires à “bash trouver tous les fichiers contenant de la chaîne”

Questions similaires à “bash trouver tous les fichiers contenant de la chaîne”

Plus de réponses similaires à “bash trouver tous les fichiers contenant de la chaîne” dans Shell/Bash

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code