Sono un principiante di Linux. Devo cercare una stringa "teststring" in tutti i file * .java che rientrano in / home / user1 / (comprese le sottocartelle). Come posso farlo in Linux tramite il comando shell.
Sono un principiante di Linux. Devo cercare una stringa "teststring" in tutti i file * .java che rientrano in / home / user1 / (comprese le sottocartelle). Come posso farlo in Linux tramite il comando shell.
Risposte:
Il modo più semplice è usare le funzionalità di GNU grep:
grep -r --include '*.java' teststring /home/user1
Se sei mai su un'altra variante unix che non ha GNU grep, ecco un modo portatile:
find /home/user1 -name '*.java' -exec grep teststring {} +
grep -r teststring .
usando ack basta digitare:cd /home/user01 && ack --java teststring
ack --java teststring /home/user01
Trovato. Pubblicarlo perché potrebbe aiutare qualcuno.
find /home/user01 -name *.java | xargs grep "teststring"
Correggi se esiste un modo migliore.
-print0e -0quando tubazioni findin xargsfunzioni correttamente con i file che possono avere spazi o nuove righe nei loro nomi:find /home/user01 -name *.java -print0 | xargs -0 grep "teststring"