Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

If I plug in a flash drive (pendrive) then it gets logged in the dmesg and in the /var/log* files. How can I disable this? I don't want to disable the logging, I just want to disable the logs about usb flashdrives:

[83400.640015] usb 2-2: new high speed USB device using ehci_hcd and address 4
[83400.777225] usb 2-2: configuration #1 chosen from 1 choice
[83401.386977] Initializing USB Mass Storage driver...
[83401.387192] scsi4 : SCSI emulation for USB Mass Storage devices
[83401.387282] usbcore: registered new interface driver usb-storage
[83401.387284] USB Mass Storage support registered.
[83401.388725] usb-storage: device found at 4
[83401.388728] usb-storage: waiting for device to settle before scanning
[83406.388491] usb-storage: device scan complete
[83406.389480] scsi 4:0:0:0: Direct-Access     Corsair  UFD              1100 PQ: 0 ANSI: 0 CCS
[83406.389923] sd 4:0:0:0: Attached scsi generic sg2 type 0
[83406.392468] sd 4:0:0:0: [sdb] 7864320 512-byte logical blocks: (4.02 GB/3.75 GiB)
[83406.393211] sd 4:0:0:0: [sdb] Write Protect is off
[83406.393214] sd 4:0:0:0: [sdb] Mode Sense: 43 00 00 00
[83406.393216] sd 4:0:0:0: [sdb] Assuming drive cache: write through
[83406.395834] sd 4:0:0:0: [sdb] Assuming drive cache: write through
[83406.395838]  sdb: sdb1
[83406.458088] sd 4:0:0:0: [sdb] Assuming drive cache: write through
[83406.458093] sd 4:0:0:0: [sdb] Attached SCSI removable disk

or just: how to disable logging a given USB port?

share|improve this question

1 Answer 1

up vote 0 down vote accepted

Run this in every minutes with root user to clear the logs for a given port:



sync; sync; sync
fgrep -iIR "] usb 2-3: " /var/log/* 2>/dev/null | fgrep -i " and address " | awk '{ print $NF }' | sort -u | while read i; do 
    egrep -iIR "] usb-storage: waiting|] usb-storage: device |usb-storage: device found at $i| scsi$i : SCSI emulation for|] scsi $i:|] sd $i:" /var/log/* 2>/dev/null
    grep -iIR "] sd $i:0:0:0: \[*.*\] Write P" /var/log/* 2>/dev/null | sed 's/\[//g; s/\]//g' | awk '{print $9}' | sort -u | while read ONEDEV; do grep -iIR "$ONEDEV: " /var/log/* 2>/dev/null; done
    fgrep -iIR "] usb 2-3: " /var/log/* 2>/dev/null
    done > "$tmpfile"

    while read ONELINE; do 
        FILENAME="`echo "$ONELINE" | cut -d : -f 1`"
        STRING="`echo "$ONELINE" | sed 's/:/\n/' | fgrep -v "/var/log" | sed 's/\[/\\\[/g' | sed 's/\]/\\\\]/g' | sed 's/\//\\\\\\//g'`"
        echo "$FILENAME XXX $STRING"
        sed -i "/$STRING/d" "$FILENAME"
    done < "$tmpfile"
    rm "$tmpfile"

dmesg -c > /dev/null
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.