Поиск во многих файлах

Программа powertop должен помочь Вам определить проблему.

   $ sudo yum -y install powertop
   $ sudo powertop

Посмотрите на различный вывод и затем клавишу со стрелкой к самой правой "вкладке", Tunables. Посмотрите на вещи, которые "плохи", и нажимают Enter для фиксации их.

Кроме того, на первом Overview экранируйте, ищите любые в высшей степени плохие процессы, которые могли бы вызывать пробуждения.

6
05.12.2011, 13:30
6 ответов

Можно сделать любой из

grep pattern_search . # делает нормальный grep на текущем каталоге

grep pattern_search * # используйте нормальный grep на всех globbed файлах из текущего каталога

grep -R pattern_search . # используйте рекурсивный поиск на текущем каталоге

grep -H pattern_search * # имя файла печати, когда файлы - больше чем один. ‘-H’

Другие опции такой как (из руководства гну):

--directories=action
    If an input file is a directory, use action to process it. By default, 
    action is ‘read’, which means that directories are read just as if they 
    were ordinary files (some operating systems and file systems disallow 
    this, and will cause grep to print error messages for every directory 
    or silently skip them). If action is ‘skip’, directories are silently 
    skipped. If action is ‘recurse’, grep reads all files under each 
    directory, recursively; this is equivalent to the ‘-r’ option. 
--exclude=glob
    Skip files whose base name matches glob (using wildcard matching). A 
    file-name glob can use ‘*’, ‘?’, and ‘[’...‘]’ as wildcards, and \ to 
    quote a wildcard or backslash character literally. 
--exclude-from=file
    Skip files whose base name matches any of the file-name globs read from 
    file (using wildcard matching as described under ‘--exclude’). 
--exclude-dir=dir
    Exclude directories matching the pattern dir from recursive directory 
    searches. 
-I
    Process a binary file as if it did not contain matching data; this is 
    equivalent to the ‘--binary-files=without-match’ option. 
--include=glob
    Search only files whose base name matches glob (using wildcard matching 
    as described under ‘--exclude’). 
-r
-R
--recursive
    For each directory mentioned on the command line, read and process all 
    files in that directory, recursively. This is the same as the 
    --directories=recurse option.
--with-filename
    Print the file name for each match. This is the default when there is 
    more than one file to search. 
10
27.01.2020, 20:20
  • 1
    Первая форма, grep pattern . не ищите файл без рекурсивной опции. –  enzotib 05.12.2011, 15:07
  • 2
    grep намного быстрее, чем находят. –  Nils 05.12.2011, 22:46

Я использую:

find . -name 'whatever*' -exec grep -H searched_string {} \;
6
27.01.2020, 20:20

Выезд ack-grep. Это идеально подходит для быстрых поисков и получает бонусные очки для игнорирования .svn- каталоги по умолчанию. Это производит имя файла и номер строки на том, где строка была найдена.

ack-grep -a Fnord
2
27.01.2020, 20:20

Основываясь на ответе Chris Card, я сам использую: find . -print0 | xargs -r0 grep -H searched_string -print0 объединенный с -0 в xargs гарантирует, что пробел в именах файлов обрабатывается правильно. -r говорит xargs давать по крайней мере одно имя файла на командной строке. Я также обычно использую fgrep если я хочу починенные строки (никакое регулярное выражение), который немного быстрее.

Используя find . -print0 | xargs -0 cmd быстрее, чем find . -exec cmd {} \;. Это немного медленнее, чем find . -exec cmd {} +, но более широко доступный затем - должностное лицо + использование.

2
27.01.2020, 20:20

Шаблон, не упомянутый все же:

find . -name "<filename>" | xargs grep "<>"

Как в

find . -name Makefile | xargs grep -v "target"

найти во всех Ваших Make-файлах, который пропускает конкретную цель.

1
27.01.2020, 20:20

Если Вы добавите/dev/null в своей команде, то Вы также получите имя файла, где строка подобрана:

for i in `find .`; do grep searched_string "$i" /dev/null ; done;
1
27.01.2020, 20:20
  • 1
    Или-H grep's использования иначе - опция с именем файла. –  James McLeod 05.12.2011, 14:05
  • 2
    for i in $(find .) должен окончательно избежаться (я использовал эквивалентный синтаксис $() вместо обратных галочек, потому что они конфликтуют с форматированием разделителей). Это повреждается на именах файлов с пробелами. –  enzotib 05.12.2011, 15:26

Теги

Похожие вопросы