在所有系统文件中查找特定文本短语

在所有系统文件中查找特定文本短语

尝试在所有系统文件中查找特定文本短语。这是一种糟糕的调试方法,但我不知道错误在哪里,而且此时我不在乎调试是否需要一天时间。

我跑了

grep -rnw /* -e _renderd 

我得到的错误是

root@geocode:~# grep -rnw /* -e _renderd 
/etc/passwd:38:_renderd:x:115:124:renderd daemon,,,:/nonexistent:/usr/sbin/nologin
/etc/shadow:38:_renderd:*:18784:0:99999:7:::
/etc/passwd-:38:_renderd:x:115:124::/nonexistent:/usr/sbin/nologin
/etc/shadow-:38:_renderd:*:18784:0:99999:7:::
/etc/group:66:_renderd:x:124:
/etc/gshadow:66:_renderd:!::
/lib/systemd/system/renderd.service:8:User=_renderd
grep: /proc/sys/abi/vsyscall32: Cannot allocate memory
grep: /proc/sys/debug/exception-trace: Cannot allocate memory
grep: /proc/sys/debug/kprobes-optimization: Cannot allocate memory
grep: /proc/sys/dev/cdrom/autoclose: Cannot allocate memory
grep: /proc/sys/dev/cdrom/autoeject: Cannot allocate memory
grep: /proc/sys/dev/cdrom/check_media: Cannot allocate memory
grep: /proc/sys/dev/cdrom/debug: Cannot allocate memory
grep: /proc/sys/dev/cdrom/info: Cannot allocate memory
grep: /proc/sys/dev/cdrom/lock: Cannot allocate memory
grep: /proc/sys/dev/hpet/max-user-freq: Cannot allocate memory
grep: /proc/sys/dev/raid/speed_limit_max: Cannot allocate memory
grep: /proc/sys/dev/raid/speed_limit_min: Cannot allocate memory
grep: /proc/sys/dev/scsi/logging_level: Cannot allocate memory
grep: /proc/sys/dev/tty/ldisc_autoload: Cannot allocate memory
grep: /proc/sys/fs/aio-max-nr: Cannot allocate memory
grep: /proc/sys/fs/aio-nr: Cannot allocate memory
grep: /proc/sys/fs/binfmt_misc/register: Invalid argument
grep: /proc/sys/fs/dentry-state: Cannot allocate memory
grep: /proc/sys/fs/dir-notify-enable: Cannot allocate memory
grep: /proc/sys/fs/epoll/max_user_watches: Cannot allocate memory
grep: /proc/sys/fs/file-max: Cannot allocate memory
grep: /proc/sys/fs/file-nr: Cannot allocate memory
grep: /proc/sys/fs/inode-nr: Cannot allocate memory
grep: /proc/sys/fs/inode-state: Cannot allocate memory
grep: /proc/sys/fs/inotify/max_queued_events: Cannot allocate memory
grep: /proc/sys/fs/inotify/max_user_instances: Cannot allocate memory
grep: /proc/sys/fs/inotify/max_user_watches: Cannot allocate memory
grep: /proc/sys/fs/lease-break-time: Cannot allocate memory
grep: /proc/sys/fs/leases-enable: Cannot allocate memory
grep: /proc/sys/fs/mount-max: Cannot allocate memory
grep: /proc/sys/fs/mqueue/msg_default: Cannot allocate memory
grep: /proc/sys/fs/mqueue/msg_max: Cannot allocate memory
grep: /proc/sys/fs/mqueue/msgsize_default: Cannot allocate memory
grep: /proc/sys/fs/mqueue/msgsize_max: Cannot allocate memory
grep: /proc/sys/fs/mqueue/queues_max: Cannot allocate memory
grep: /proc/sys/fs/nr_open: Cannot allocate memory
grep: /proc/sys/fs/overflowgid: Cannot allocate memory
grep: /proc/sys/fs/overflowuid: Cannot allocate memory
grep: /proc/sys/fs/pipe-max-size: Cannot allocate memory
grep: /proc/sys/fs/pipe-user-pages-hard: Cannot allocate memory
grep: /proc/sys/fs/pipe-user-pages-soft: Cannot allocate memory
grep: /proc/sys/fs/protected_fifos: Cannot allocate memory
grep: /proc/sys/fs/protected_hardlinks: Cannot allocate memory
grep: /proc/sys/fs/protected_regular: Cannot allocate memory
grep: /proc/sys/fs/protected_symlinks: Cannot allocate memory
grep: /proc/sys/fs/quota/allocated_dquots: Cannot allocate memory

我该如何限制内存。是不是因为我运行的文件大于我拥有的 16 GB RAM,还是其他原因?

答案1

除非您特别想搜索临时文件系统/proc,否则/sys我建议使用find递归 + 非递归 grep,以便您可以/dev从搜索中修剪它们(和块设备树)。您可能希望添加-I到 grep 选项以跳过二进制文件:

find / \( -path /dev -o -path /proc -o -path /sys \) -prune -o -type f \
    -exec grep -Inw -e _renderd {} +

您可能想要将其添加-path /run到修剪路径列表中。

相关内容