Поиск по слову на всей машине Ubuntu с помощью SSH

Используйте несколько шаблонов исключения:

rsync -av --exclude='*.odb' --exclude='*.a3db' source/ target/

Пример:

$ ls source
file-1.a3db  file-2.odb   file-4.a3db  file-5.odb   file-7.a3db  file-8.odb
file-1.c     file-2.txt   file-4.c     file-5.txt   file-7.c     file-8.txt
file-1.odb   file-3.a3db  file-4.odb   file-6.a3db  file-7.odb   file-9.a3db
file-1.txt   file-3.c     file-4.txt   file-6.c     file-7.txt   file-9.c
file-2.a3db  file-3.odb   file-5.a3db  file-6.odb   file-8.a3db  file-9.odb
file-2.c     file-3.txt   file-5.c     file-6.txt   file-8.c     file-9.txt

Используя -vдважды, мы получаем указание на то, что включено и что исключено:

$ rsync -avv --exclude='*.odb' --exclude='*.a3db' source/ target/
sending incremental file list
[sender] hiding file file-1.odb because of pattern *.odb
[sender] hiding file file-1.a3db because of pattern *.a3db
[sender] hiding file file-2.odb because of pattern *.odb
[sender] hiding file file-2.a3db because of pattern *.a3db
[sender] hiding file file-3.odb because of pattern *.odb
[sender] hiding file file-3.a3db because of pattern *.a3db
[sender] hiding file file-4.odb because of pattern *.odb
[sender] hiding file file-4.a3db because of pattern *.a3db
[sender] hiding file file-5.odb because of pattern *.odb
[sender] hiding file file-5.a3db because of pattern *.a3db
[sender] hiding file file-6.odb because of pattern *.odb
[sender] hiding file file-6.a3db because of pattern *.a3db
[sender] hiding file file-7.odb because of pattern *.odb
[sender] hiding file file-7.a3db because of pattern *.a3db
[sender] hiding file file-8.odb because of pattern *.odb
[sender] hiding file file-8.a3db because of pattern *.a3db
[sender] hiding file file-9.odb because of pattern *.odb
[sender] hiding file file-9.a3db because of pattern *.a3db
delta-transmission disabled for local transfer or --whole-file

(остальная часть выходного отрезка)

$ ls target
file-1.c   file-2.txt file-4.c   file-5.txt file-7.c   file-8.txt
file-1.txt file-3.c   file-4.txt file-6.c   file-7.txt file-9.c
file-2.c   file-3.txt file-5.c   file-6.txt file-8.c   file-9.txt

Это также работает, даже если файлы расположены в подкаталогах в source.

0
26.05.2020, 22:52
1 ответ

Добавить 2> /dev/nullк команде, чтобы скрыть ошибки. Это называется перенаправлением stderr. Так что для вашей конкретной команды это будет:

find / -xdev -type f -print0 | xargs -0 grep -H "search for this text" 2> /dev/null

Но это очень многословно. Вы также можете:

grep -rw "flag"

изgrep(1):

       -r, --recursive
              Read all files under each directory, recursively, 
              following symbolic links only if they are on the 
              command line. Note that if no file operand is given, 
              grep searches the working directory.  This is 
              equivalent to the -d recurse option.

       -w, --word-regexp
              Select only those lines containing matches that form 
              whole words. The test is that the matching substring 
              must either be at the beginning of the line or preceded 
              by a non-word constituent character.  Similarly, it 
              must be either at the end of the line or followed by a 
              non-word constituent character.  Word-constituent 
              characters are letters, digits, and the underscore. 
              This option has no effect if -x is also specified.

Обратите внимание, что слово «флаг» будет найдено в любом файле из текущего каталога. Поэтому, если вы хотите выполнить поиск по всей машине, запустите это из /. Если вы хотите, чтобы -не учитывал регистр, добавьте -i. Еще одним преимуществом этого является то, что слова типа flaggedне будут найдены.

Используйте grep -rw "flag" 2> /dev/nullдля фильтрации всех этих Permission deniedсообщений

0
18.03.2021, 23:32

Теги

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