|
How do I search from several files (grep), and displays only the file name to match the file?
When you search from more than one file, it displays the default file name:
grep "word" filename
grep root / etc / *
Sample output:
/etc/bash.bashrc:See"man sudo_root "for details.
/ Etc / crontab: 17 **** root cd / && run-parts --report /etc/cron.hourly
/ Etc / crontab: 256 *** root test-x / usr / sbin / anacron || (cd / && run-parts --report /etc/cron.daily)
/ Etc / crontab: 476 ** 7 root test-x / usr / sbin / anacron || (cd / && run-parts --report /etc/cron.weekly)
/ Etc / crontab: 5261 ** root test-x / usr / sbin / anacron || (cd / && run-parts --report /etc/cron.monthly)
/ Etc / group: root: x: 0:
grep: / etc / gshadow: Permission denied
/etc/logrotate.conf: create 0664 root utmp
/etc/logrotate.conf: create 0660 root utmp
Each line starting with the first part of the file name (eg: / etc / crontab, / etc / group). Use the -l option to display only the file name:
grep-l "string" filename
grep-l root / etc / *
Sample output:
/ Etc / aliases
/etc/arpwatch.conf
grep: /etc/at.deny: Permission denied
/etc/bash.bashrc
/ Etc / bash_completion
/etc/ca-certificates.conf
/ Etc / crontab
/ Etc / group
You can also reverse the output; using the -L option to output the name of a file that does not match:
grep-L "word" filename
grep-L root / etc / *
Sample output:
/ Etc / apm
/ Etc / apparmor
/etc/apparmor.d
/ Etc / apport
/ Etc / apt
/ Etc / avahi
/etc/bash_completion.d
/etc/bindresvport.blacklist
/etc/blkid.conf
/ Etc / bluetooth
/etc/bogofilter.cf
/ Etc / bonobo-activation
/etc/brlapi.key |
|
|
|