Linoux

  Accueil

Zoom   

Accueil > Administration > Shell > Grep
Grep
LinuxInfo
Dezoom

Grep

Mise à jour : Debian 9.0

1 - Configurations

Afficher les lignes comprenant le motif fans :

# dmesg |grep fans
[ 2.404916] asus_wmi: Number of fans: 1
# dmesg |grep fans -n
789:[ 2.404916] asus_wmi: Number of fans: 1
# dmesg |grep fans -nB2
787-[ 2.403106] usbhid: USB HID core driver
788-[ 2.404869] input: Logitech USB Receiver as /devices/p....
789:[ 2.404916] asus_wmi: Number of fans: 1
# dmesg |grep fans -nA2
789:[ 2.404916] asus_wmi: Number of fans: 1
790-[ 2.404994] hid-generic 0003:046D:C52F.0001: input.....
791-[ 2.405770] input: Logitech USB Receiver as /devi
# dmesg |grep fans -nC2
787-[ 2.403106] usbhid: USB HID core driver
788-[ 2.404869] input: Logitech USB Receiver as /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.4/4-1.4:1.0/0003:046D:C52F.0001/input/input19
789:[ 2.404916] asus_wmi: Number of fans: 1
790-[ 2.404994] hid-generic 0003:046D:C52F.0001: input,hidraw0: USB HID v1.11 Mouse [Logitech USB Receiver] on usb-0000:00:1d.0-1.4/input0
791-[ 2.405770] input: Logitech USB Receiver as

2 - Conditions

Afficher les lignes

# dmesg |grep -i power
[ 2.311707] input: Power Button as /devices/LNXSYSTM:00/LNXSYBUS:00/PNP0C0C:00/input/input11
[ 2.311759] ACPI: Power Button [PWRB]
# dmesg |grep Power |grep -v input11
[ 2.311759] ACPI: Power Button [PWRB]
# dmesg |grep -E "PWRB|input11"
[ 2.311707] input: Power Button as /devices/LNXSYSTM:00/LNXSYBUS:00/PNP0C0C:00/input/input11
[ 2.311759] ACPI: Power Button [PWRB]
# dmesg |grep  wmi:
[ 2.312016] wmi: Mapper loaded
[ 2.354563] asus_wmi: ASUS WMI generic driver loaded
[ 2.359308] asus_wmi: Initialization: 0x1
[ 2.359344] asus_wmi: BIOS WMI version: 7.6
[ 2.359394] asus_wmi: SFUN value: 0xa0877
[ 2.404916] asus_wmi: Number of fans: 1
# dmesg |grep -w wmi:
[ 2.312016] wmi: Mapper loaded

Attention les caractères : virgule, slash et moins (,/-) ne sont pas considérés comme des délimiteurs : 

# dmesg |grep  -w wmi
[ 2.312016] wmi: Mapper loaded
[ 2.360330] input: Asus WMI hotkeys as /devices/platform/asus-nb-wmi/input/input16

3 - Comptage

# dmesg |grep -c wmi:
6
# dmesg |grep -m2 wmi:
[ 2.312016] wmi: Mapper loaded
[ 2.354563] asus_wmi: ASUS WMI generic driver loaded

4 - Utilisation d'un fichier de motifs

Afficher les lignes contenant les motifs listés dans le fichier test, un motif par ligne : File

$ cat test
pwrb
input11
# dmesg |grep -if test
[ 2.311707] input: Power Button as /devices/LNXSYSTM:00/LNXSYBUS:00/PNP0C0C:00/input/input11
[ 2.311759] ACPI: Power Button [PWRB]