BusyBox 1.4.2で特定の文字列を含むすべてのファイルを再帰的に見つける方法は?

BusyBox 1.4.2で特定の文字列を含むすべてのファイルを再帰的に見つける方法は?

BusyBox v1.4.2のディレクトリとすべてのサブディレクトリで特定の文字列を含むすべてのファイルを見つける方法は? 「AA:CC:DD:00:EE:55」または「AACCDD00EE55」文字列を見つける必要があります。

BusyBox v1.4.2 (2012-06-01 11:17:34 CST) Built-in shell (ash)
Enter 'help' for a list of built-in commands.

Built-in commands:
-------------------
        . : [ [[ bg break cd chdir continue echo eval exec exit export
        false fg getopts hash help jobs kill local pwd read readonly
        return set shift source test times trap true type ulimit umask
        unset wait


# busybox --help
BusyBox v1.4.2 (2012-06-01 11:17:34 CST) multi-call binary

Usage: busybox [function] [arguments]...
   or: [function] [arguments]...

Currently defined functions:
        [, [[, adduser, ash, awk, cat, chmod, chroot, cp, cut,
        date, dd, deluser, dmesg, echo, false, free, getopt, grep,
        halt, hexdump, hostname, htxsnmptelnet, ifconfig, init,
        insmod, kill, killall, ln, login, ls, lsmod, mkdir, mknod,
        mount, mv, netstat, passwd, ping, ping6, poweroff, ps,
        pwd, reboot, renice, rm, rmmod, route, sh, sleep, tar,
        test, tftp, top, umount, wget

ベストアンサー1

grep再帰フラグがあり、-rflagsを使用して複数の検索パターンを指定できます-e。そしてフォーマットで見ると、Macアドレスを探しているようですので、大文字でも小文字でもかまいません。

あなたができることを知っています

grep -ir -e "AA:CC:DD:00:EE:55" -e "AACCDD00EE55" /directory

sudoファイル/フォルダ(フォルダなど)に対する読み取り権限がない場合は、それを指定する必要があります/etc

例えば、

xieerqi:$ grep -iR "string" /etc/cups                                                                              
grep: /etc/cups/subscriptions.conf: Permission denied
grep: /etc/cups/classes.conf: Permission denied
grep: /etc/cups/printers.conf.O: Permission denied
grep: /etc/cups/subscriptions.conf.O: Permission denied
grep: /etc/cups/ssl: Permission denied
grep: /etc/cups/printers.conf: Permission denied

/etc/cupsこれは、ディレクトリ自体だけでなく、ディレクトリ内のすべてのエントリに対する権限がrootユーザーに対してのみ読み取りおよび書き込みであり、グループに対して読み取りであるためにlp発生します。他のユーザーの場合 - 読み取り権限がありません。例えば、

-rw-r----- 1 root lp     92 11月  6 09:15 subscriptions.conf

そのため、sudoアクセスが必要です。

また、アイテムが読めないと文句を言うかもしれないので、リダイレクトをgrep指定する必要があるかもしれません。2> /dev/null

たとえば、/etc/blkid.tab実際のファイルではなくシンボリックリンクなので、次のエラーが発生します。

xieerqi:$ sudo grep -iR "b4:82:fe:d3:85:56" /etc                                                                  
[sudo] password for xieerqi: 
grep: /etc/blkid.tab: No such file or directory

出力からエラーを消去するには、次の手順を実行します。これは、デフォルトですべての出力のブラックホールであるsudo grep -iR "b4:82:fe:d3:85:56" 2> /dev/nullエラーストリームをデバイスにリダイレクトします。/dev/null

おすすめ記事