The following commands are useful for the daily work in the Linux Machine. These commands are executed on Ubuntu Linux 14.04 32-bit Machine.
Command #1 : How to get the distribution of Linux Machine?
lsb_release - print distribution-specific information
root@m:~# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 14.04.4 LTS
Release: 14.04
Codename: trusty
Command #2 : How to get the list of USB devices ?
lsusb - list USB devices
root@m:~# lsusb
Bus 002 Device 002: ID 0b95:1780 ASIX Electronics Corp. AX88178
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 008 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 007 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 006 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 003 Device 002: ID 03f9:0100 KeyTronic Corp. KT-2001 Keyboard
Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
dmidecode - DMI table decoder
This table contains a description of the system's hardware components, as well as other useful pieces of information such as serial numbers and BIOS revision
Keyword Types
──────────────────
bios 0, 13
system 1, 12, 15, 23, 32
baseboard 2, 10, 41
chassis 3
processor 4
memory 5, 6, 16, 17
cache 7
connector 8
slot 9
Examples:
root@m:~# dmidecode -t 1 -> t indicates type
# dmidecode 2.12
SMBIOS 2.5 present.
Handle 0x0100, DMI type 1, 27 bytes
System Information
Manufacturer: Dell Inc.
Product Name: SUPER JET
Version: Not Specified
Serial Number: 8GCRXY
UUID: 4MUNI-5200-1043-84422
Wake-up Type: APM Timer
SKU Number: Not Specified
Family: Not Specified
root@m:~# dmidecode -t 4
# dmidecode 2.12
SMBIOS 2.5 present.
Handle 0x0400, DMI type 4, 40 bytes
Processor Information
Socket Designation: CPU
Type: Central Processor
Family: Core 2 Duo
Manufacturer: Intel
Udev - Manages the devices dynamically.
Commands :
Examples:
Example:
------------
# We can also write the udev rules in /etc/udev/rules.d/* directory and reload the rules dynamically with out any reboot of the system.
Step 1: root@m:/etc/udev/rules.d# vi 99-yourOwn.rules
Step 2: Rule can be any thing, Add a device, run a script etc.
e.g: SUBSYSTEMS=="usb",ATTRS{idVendor}=="0ebc",RUN+="/etc/udev/myscript.sh"
Step 3: udevadm control --reload-rules
Reload the rules with out any reboot.
Step 4: udevadm trigger
And then check the result in the log files or any verify your expected functionality.
Sometimes, you can skip the step 3: udevadm control --reload-rules
udevadm test
-------------
The above command used to the test the devices and check the functionality is working or not.
Example:
------------
Step 1:
root@m:~# lsusb
Bus 002 Device 004: ID 0b95:1780 ASIX Electronics Corp. AX88178
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 008 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 007 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 006 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 003 Device 002: ID 03f9:0100 KeyTronic Corp. KT-2001 Keyboard
Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Command #1 : How to get the distribution of Linux Machine?
lsb_release - print distribution-specific information
root@m:~# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 14.04.4 LTS
Release: 14.04
Codename: trusty
Command #2 : How to get the list of USB devices ?
lsusb - list USB devices
root@m:~# lsusb
Bus 002 Device 002: ID 0b95:1780 ASIX Electronics Corp. AX88178
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 008 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 007 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 006 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 003 Device 002: ID 03f9:0100 KeyTronic Corp. KT-2001 Keyboard
Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Command #3 : How to get the BIOS, Hardware details, Manufacturer, BIOS release date etc. ?
dmidecode - DMI table decoder
Keyword Types
──────────────────
bios 0, 13
system 1, 12, 15, 23, 32
baseboard 2, 10, 41
chassis 3
processor 4
memory 5, 6, 16, 17
cache 7
connector 8
slot 9
Examples:
root@m:~# dmidecode -t 1 -> t indicates type
# dmidecode 2.12
SMBIOS 2.5 present.
Handle 0x0100, DMI type 1, 27 bytes
System Information
Manufacturer: Dell Inc.
Product Name: SUPER JET
Version: Not Specified
Serial Number: 8GCRXY
UUID: 4MUNI-5200-1043-84422
Wake-up Type: APM Timer
SKU Number: Not Specified
Family: Not Specified
# dmidecode 2.12
SMBIOS 2.5 present.
Handle 0x0400, DMI type 4, 40 bytes
Processor Information
Socket Designation: CPU
Type: Central Processor
Family: Core 2 Duo
Manufacturer: Intel
Get HW information about BIOS : dmidecode -t
bios
Get HW information about System : dmidecode -t
system
Get HW information about baseboard : dmidecode -t
baseboard
Get HW information about chassis : dmidecode -t chassis
Get HW information about System : dmidecode -t system
Get HW information about baseboard : dmidecode -t baseboard
Get HW information about chassis : dmidecode -t chassis
Command #4 : How to configure (set/get), list, test input devices of the Linux Machine ?
xinput - is a utility to list available input devices, query information about a device and change input device settings
root@m:~# xinput or xinput --list
⎡ Virtual core pointer id=2 [master pointer (3)]
⎜ ↳ Virtual core XTEST pointer id=4 [slave pointer (2)]
⎜ ↳ eGalax Inc. USB TouchController id=9 [slave pointer (2)]
⎜ ↳ eGalax Inc. USB TouchController Pen id=8 [slave pointer (2)]
⎣ Virtual core keyboard id=3 [master keyboard (2)]
↳ Virtual core XTEST keyboard id=5 [slave keyboard (3)]
↳ Dell Dell USB Keyboard id=11 [slave keyboard (3)]
↳ Wincor Nixdorf BEETLE /Express Composite Device id=10 [slave keyboard (3)]
↳ Power Button id=7 [slave keyboard (3)]
↳ Power Button id=6 [slave keyboard (3)]
How to Get the Properties of particular Device Using the Device ID?
root@m:~# xinput --list-props 11
Device 'Dell Dell USB Keyboard':
Device Enabled (114): 0
Coordinate Transformation Matrix (116): 1.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 1.000000
Device Product ID (232): 16700, 8453
Device Node (233): "/dev/input/event3"
Command #5 : How to list hardware in the Linux Machine ?
lshw - list hardware
lshw is a small tool to extract detailed information on the hardware configuration of the machine. It can report exact memory configuration, firmware version, mainboard configuration, CPU version and speed, cache configuration, bus speed, etc.
EXAMPLES
lshw -short
Lists hardware in a compact format.
lshw -class disk -class storage
Lists all disks and storage controllers in the system.
lshw -html -class network
Lists all network interfaces in HTML.
lshw -disable dmi
Don't use DMI to detect hardware.
root@m:~# lshw -c disk
*-disk
description: ATA Disk
product: SanDisk SSD U100
physical id: 0.0.0
bus info: scsi@2:0.0.0
logical name: /dev/sda
version: 10.5
serial: 132535401384
size: 59GiB (64GB)
capabilities: partitioned partitioned:dos
root@m:~# lshw -short
H/W path Device Class Description
=================================================
system DELL 15 D525,2GB,HDD (To Be Filled By O.E.M.)
/0 bus PD359
/0/0 memory 64KiB BIOS
/0/4 processor Intel(R) Atom(TM) CPU D525 @ 1.80GHz
/0/4/5 memory 48KiB L1 cache
/0/4/6 memory 1MiB L2 cache
/0/4/0.1 processor Logical CPU
/0/4/0.2 processor Logical CPU
/0/4/0.3 processor Logical CPU
/0/4/0.4 processor Logical CPU
/0/d memory 4GiB System Memory
/0/d/0 memory 4GiB SODIMM DDR3 Synchronous 800 MHz (1.2 ns)
/0/1 processor
/0/1/0.1 processor Logical CPU
/0/1/0.2 processor Logical CPU
/0/1/0.3 processor Logical CPU
/0/1/0.4 processor Logical CPU
/0/100 bridge Atom Processor D4xx/D5xx/N4xx/N5xx DMI Bridge
/0/100/2 display Atom Processor D4xx/D5xx/N4xx/N5xx Integrated Graphics Controller
/0/100/2.1 display Atom Processor D4xx/D5xx/N4xx/N5xx Integrated Graphics Controller
/0/100/1a bus 82801H (ICH8 Family) USB UHCI Controller #4
/0/100/1a.1 bus 82801H (ICH8 Family) USB UHCI Controller #5
/0/100/1a.7 bus 82801H (ICH8 Family) USB2 EHCI Controller #2
/0/100/1c bridge 82801H (ICH8 Family) PCI Express Port 1
/0/100/1c.4 bridge 82801H (ICH8 Family) PCI Express Port 5
/0/100/1c.4/0 eth0 network RTL8101/2/6E PCI Express Fast/Gigabit Ethernet controller
/0/100/1d bus 82801H (ICH8 Family) USB UHCI Controller #1
/0/100/1d.1 bus 82801H (ICH8 Family) USB UHCI Controller #2
/0/100/1d.2 bus 82801H (ICH8 Family) USB UHCI Controller #3
/0/100/1d.7 bus 82801H (ICH8 Family) USB2 EHCI Controller #1
/0/100/1e bridge 82801 Mobile PCI Bridge
/0/100/1f bridge 82801HM (ICH8M) LPC Interface Controller
/0/100/1f.1 storage 82801HM/HEM (ICH8M/ICH8M-E) IDE Controller
/0/100/1f.2 storage 82801HM/HEM (ICH8M/ICH8M-E) SATA Controller [IDE mode]
/0/100/1f.3 bus 82801H (ICH8 Family) SMBus Controller
/0/2 scsi2 storage
/0/2/0.0.0 /dev/sda disk 64GB SanDisk SSD U100
/0/2/0.0.0/1 /dev/sda1 volume 243MiB Linux filesystem partition
/0/2/0.0.0/2 /dev/sda2 volume 59GiB Extended partition
/0/2/0.0.0/2/5 /dev/sda5 volume 59GiB Linux LVM Physical Volume partition
/1 power ----------------------------------------
/2 power 9NA0651264
Command #6 : How to get the monitor model information in Linux ?
get-edid | parse-edid
get-edid, parse-edid - read-edid tools to retrieve and interpret monitor specifications using the VESA VBE DDC protocol
(or)
grep -i "monitor name" /var/log/Xorg.*.log
Command #7 : How to check disk space in Linux ?
df - report file system disk space usage
df displays the amount of disk space available on the file system containing each file name argument
root@m:~# df -h
df displays the amount of disk space available on the file system containing each file name argument
root@m:~# df -h
Filesystem Size Used Avail Use% Mounted on
udev 980M 4.0K 980M 1% /dev
tmpfs 198M 3.6M 195M 2% /run
/dev/dm-1 20G 9.7G 9.3G 51% /
none 4.0K 0 4.0K 0% /sys/fs/cgroup
none 5.0M 12K 5.0M 1% /run/lock
none 990M 0 990M 0% /run/shm
none 100M 4.0K 100M 1% /run/user
udev 980M 4.0K 980M 1% /dev
tmpfs 198M 3.6M 195M 2% /run
/dev/dm-1 20G 9.7G 9.3G 51% /
none 4.0K 0 4.0K 0% /sys/fs/cgroup
none 5.0M 12K 5.0M 1% /run/lock
none 990M 0 990M 0% /run/shm
none 100M 4.0K 100M 1% /run/user
root@m:~# df /dev/sda
Filesystem 1K-blocks Used Available Use% Mounted on
udev 1003444 4 1003440 1% /dev
root@m:~# df /dev/sda
Filesystem 1K-blocks Used Available Use% Mounted on
udev 1003444 4 1003440 1% /dev
root@m:~# df -h /dev/sda
Filesystem Size Used Avail Use% Mounted on
udev 980M 4.0K 980M 1% /dev
root@m:~# df -a
Filesystem 1K-blocks Used Available Use% Mounted on
sysfs 0 0 0 - /sys
proc 0 0 0 - /proc
udev 1003444 4 1003440 1% /dev
devpts 0 0 0 - /dev/pts
tmpfs 202744 3640 199104 2% /run
/dev/dm-1 20039548 10076208 9742036 51% /
none 4 0 4 0% /sys/fs/cgroup
none 0 0 0 - /sys/fs/fuse/connections
none 0 0 0 - /sys/kernel/debug
none 0 0 0 - /sys/kernel/security
none 5120 12 5108 1% /run/lock
none 1013704 0 1013704 0% /run/shm
none 102400 4 102396 1% /run/user
none 0 0 0 - /sys/fs/pstore
/dev/dm-1 20039548 10076208 9742036 51% /appl/lib
rpc_pipefs 0 0 0 - /run/rpc_pipefs
systemd 0 0 0 - /sys/fs/cgroup/systemd
nfsd 0 0 0 - /proc/fs/nfsd
proc 0 0 0 - /appl/proc
root@m:~# df -a -h
Filesystem Size Used Avail Use% Mounted on
sysfs 0 0 0 - /sys
proc 0 0 0 - /proc
udev 980M 4.0K 980M 1% /dev
devpts 0 0 0 - /dev/pts
tmpfs 198M 3.6M 195M 2% /run
/dev/dm-1 20G 9.7G 9.3G 51% /
none 4.0K 0 4.0K 0% /sys/fs/cgroup
none 0 0 0 - /sys/fs/fuse/connections
none 0 0 0 - /sys/kernel/debug
none 0 0 0 - /sys/kernel/security
none 5.0M 12K 5.0M 1% /run/lock
none 990M 0 990M 0% /run/shm
none 100M 4.0K 100M 1% /run/user
none 0 0 0 - /sys/fs/pstore
/dev/dm-1 20G 9.7G 9.3G 51% /appl/lib
rpc_pipefs 0 0 0 - /run/rpc_pipefs
systemd 0 0 0 - /sys/fs/cgroup/systemd
nfsd 0 0 0 - /proc/fs/nfsd
proc 0 0 0 - /appl/proc
root@m:~# df --total
Filesystem 1K-blocks Used Available Use% Mounted on
udev 1003444 4 1003440 1% /dev
tmpfs 202744 3640 199104 2% /run
/dev/dm-1 20039548 10076264 9741980 51% /
none 4 0 4 0% /sys/fs/cgroup
none 5120 12 5108 1% /run/lock
none 1013704 0 1013704 0% /run/shm
none 102400 4 102396 1% /run/user
total 22366964 10079924 12065736 46% -
Command #8 : How to list the open files in Linux?
lsof - list of open files.
In Unix, every thing is file. Using lsof command, we can list the open files.
FD – Represents the file descriptor. Some of the values of FDs are,
cwd – Current Working Directory
txt – Text file
mem – Memory mapped file
mmap – Memory mapped device
NUMBER – Represent the actual file descriptor. The character after the number i.e ‘1u’, represents the mode in which the file is opened. r for read, w for write, u for read and write.
TYPE – Specifies the type of the file. Some of the values of TYPEs are,
REG – Regular File
DIR – Directory
FIFO – First In First Out
CHR – Character special file
root@m:~# lsof /var/log/kern.log
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
rsyslogd 11086 syslog 5w REG 252,0 25850 314 /var/log/kern.log
root@m:~# lsof +D /var/log
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
cupsd 464 root 4u REG 252,0 0 136301 /var/log/cups/access_log
cupsd 464 root 5u REG 252,0 0 156937 /var/log/cups/error_log
cupsd 464 root 6u REG 252,0 0 156938 /var/log/cups/page_log
smbd 577 root 2w REG 252,0 0 144792 /var/log/samba/log.smbd
smbd 577 root 34w REG 252,0 0 144792 /var/log/samba/log.smbd
smbd 621 root 2w REG 252,0 0 144792 /var/log/samba/log.smbd
smbd 621 root 28w REG 252,0 0 144792 /var/log/samba/log.smbd
elousbd 2181 root 2w REG 252,0 1950 2380 /var/log/rc.local.log
elousbd 2181 root 3u REG 252,0 114 156946 /var/log/elo-usb/EloUsbErrorLog.txt
nmbd 2604 root 2w REG 252,0 2162 144797 /var/log/samba/log.nmbd
nmbd 2604 root 18w REG 252,0 2162 144797 /var/log/samba/log.nmbd
rsyslogd 11086 syslog 1w REG 252,0 700207 330 /var/log/auth.log
rsyslogd 11086 syslog 2w REG 252,0 34882 310 /var/log/syslog
rsyslogd 11086 syslog 5w REG 252,0 25850 314 /var/log/kern.log
Xorg 31401 root 0w REG 252,0 140409 861 /var/log/Xorg.1.log
In Unix, every thing is file. Using lsof command, we can list the open files.
FD – Represents the file descriptor. Some of the values of FDs are,
cwd – Current Working Directory
txt – Text file
mem – Memory mapped file
mmap – Memory mapped device
NUMBER – Represent the actual file descriptor. The character after the number i.e ‘1u’, represents the mode in which the file is opened. r for read, w for write, u for read and write.
TYPE – Specifies the type of the file. Some of the values of TYPEs are,
REG – Regular File
DIR – Directory
FIFO – First In First Out
CHR – Character special file
How to list process which opened the file?
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
rsyslogd 11086 syslog 5w REG 252,0 25850 314 /var/log/kern.log
How to list opened files under directory? (+D)
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
cupsd 464 root 4u REG 252,0 0 136301 /var/log/cups/access_log
cupsd 464 root 5u REG 252,0 0 156937 /var/log/cups/error_log
cupsd 464 root 6u REG 252,0 0 156938 /var/log/cups/page_log
smbd 577 root 2w REG 252,0 0 144792 /var/log/samba/log.smbd
smbd 577 root 34w REG 252,0 0 144792 /var/log/samba/log.smbd
smbd 621 root 2w REG 252,0 0 144792 /var/log/samba/log.smbd
smbd 621 root 28w REG 252,0 0 144792 /var/log/samba/log.smbd
elousbd 2181 root 2w REG 252,0 1950 2380 /var/log/rc.local.log
elousbd 2181 root 3u REG 252,0 114 156946 /var/log/elo-usb/EloUsbErrorLog.txt
nmbd 2604 root 2w REG 252,0 2162 144797 /var/log/samba/log.nmbd
nmbd 2604 root 18w REG 252,0 2162 144797 /var/log/samba/log.nmbd
rsyslogd 11086 syslog 1w REG 252,0 700207 330 /var/log/auth.log
rsyslogd 11086 syslog 2w REG 252,0 34882 310 /var/log/syslog
rsyslogd 11086 syslog 5w REG 252,0 25850 314 /var/log/kern.log
Xorg 31401 root 0w REG 252,0 140409 861 /var/log/Xorg.1.log
How to list opened files based on process name?
root@m:~# lsof -c sshd
sshd 2517 root cwd DIR 252,0 4096 2 /
sshd 2517 root rtd DIR 252,0 4096 2 /
sshd 2517 root txt REG 252,0 834680 21216 /usr/sbin/sshd
sshd 2517 root mem REG 252,0 46812 134784 /lib/i386-linux-gnu/libnss_files-2.19.so
sshd 2517 root mem REG 252,0 42668 134778 /lib/i386-linux-
sshd 22635 root 4u unix 0xf5da0b00 0t0 138945568 socket
sshd 22635 root 5r FIFO 0,8 0t0 138944997 pipe
sshd 22635 root 6w FIFO 0,8 0t0 138944997 pipe
sshd 22635 root 8u CHR 5,2 0t0 9473 /dev/ptmx
sshd 22635 root 10u CHR 5,2 0t0 9473 /dev/ptmx
sshd 22635 root 11u CHR 5,2 0t0 9473 /dev/ptmx
How to list all Network connections?
root@m:~# lsof -i
How to list all TCP/UDP connections?
root@m:~# lsof -i tcp
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
cupsd 464 root 10u IPv6 11515 0t0 TCP localhost:ipp (LISTEN)
cupsd 464 root 11u IPv4 11516 0t0 TCP localhost:ipp (LISTEN)
smbd 577 root 30u IPv6 11540 0t0 TCP *:microsoft-ds (LISTEN)
smbd 577 root 31u IPv6 11541 0t0 TCP *:netbios-ssn (LISTEN)
smbd 577 root 32u IPv4 11542 0t0 TCP *:microsoft-ds (LISTEN)
smbd 577 root 33u IPv4 11543 0t0 TCP *:netbios-ssn (LISTEN)
rpcbind 613 root 8u IPv4 8908 0t0 TCP *:sunrpc (LISTEN)
rpcbind 613 root 11u IPv6 8911 0t0 TCP *:sunrpc (LISTEN)
rpc.statd 719 statd 9u IPv4 11603 0t0 TCP *:34794 (LISTEN)
rpc.statd 719 statd 11u IPv6 11609 0t0 TCP *:55775 (LISTEN)
xinetd 1019 root 6u IPv4 9176 0t0 TCP *:ftp (LISTEN)
portcommu 1124 root 10u IPv4 11887 0t0 TCP *:2291 (LISTEN)
sshd 2517 root 3u IPv4 14006 0t0 TCP *:ssh (LISTEN)
sshd 2517 root 4u IPv6 14008 0t0 TCP *:ssh (LISTEN)
root@m:~# lsof -i udp
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
rpcbind 613 root 6u IPv4 8904 0t0 UDP *:sunrpc
rpcbind 613 root 7u IPv4 8907 0t0 UDP *:783
rpcbind 613 root 9u IPv6 8909 0t0 UDP *:sunrpc
rpcbind 613 root 10u IPv6 8910 0t0 UDP *:783
rpc.statd 719 statd 5u IPv4 12547 0t0 UDP localhost:895
rpc.statd 719 statd 8u IPv4 11600 0t0 UDP *:52247
rpc.statd 719 statd 10u IPv6 11606 0t0 UDP *:60550
cups-brow 863 root 8u IPv4 10767 0t0 UDP *:ipp
xinetd 1019 root 5u IPv4 9175 0t0 UDP *:tftp
How to list all files associated with process ID?
root@m:~# lsof -p 613
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
rpcbind 613 root cwd DIR 252,0 4096 2 /
rpcbind 613 root rtd DIR 252,0 4096 2 /
rpcbind 613 root txt REG 252,0 42920 12332 /sbin/rpcbind
rpcbind 613 root mem REG 252,0 42668 134778 /lib/i386-linux-gnu/libnss_nis-2.19.so
rpcbind 613 root mem REG 252,0 30560 134770 /lib/i386-linux-gnu/libnss_compat-2.19.so
rpcbind 613 root mem REG 252,0 13856 134779 /lib/i386-linux-gnu/libdl-2.19.so
rpcbind 613 root mem REG 252,0 92036 134788 /lib/i386-linux-gnu/libnsl-2.19.so
How to list all files associated with port number?
root@m:~# lsof -i :19578
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
dhclient 2362 root 20u IPv4 11193 0t0 UDP *:19578
How to list all files under username?
root@m:~# lsof -u muni
How to kill all files under username?
root@m:~# kill -9 `lsof -t -u muni`
‘-t’ option to list output only the process id of the process
What is Udev and How to use the Udev rules in Linux?
This is the device management tool runs in the user space to manages (creates/remove) the devices dynamically. Present from 2.6 kernel on wards and it runs in user space.
udevd is the process, it manages the device nodes (permissions, symlinks, name) in /dev directory.
For example: If we attach an USB device, user can set permissions that it can accessible to specific user etc or run specific script.
udevd is the process, it manages the device nodes (permissions, symlinks, name) in /dev directory.
For example: If we attach an USB device, user can set permissions that it can accessible to specific user etc or run specific script.
How it works?
Step 1: Attach a USB disk.
Step 2: Kernel detects it and sysfs is populated with device details like serial number, vendor,
port etc.. in /sys/ directory.
Step 3: Kernel will send an uevent and this event shall be received by Udev
(udevd process listening for uevents) .
Step 4: Then udev checks in the sysfs (file system) whether it have an rule corresponding for
this uevent. The rules are present in the /etc/udev/rules.d/*.rules.
Step 5: udevd will check all rules present under /etc/udev/rules.d/*.rules and identify this device matches with any rules present in this directory.
If it matches the rule, then it performs the actions (Setting the permissions,
run custom script, symlink etc.)
How to find the information using udevadm tool?
udevadm: is the udev management tool.
Step 1: Attach a USB disk.
Step 2: Kernel detects it and sysfs is populated with device details like serial number, vendor,
port etc.. in /sys/ directory.
Step 3: Kernel will send an uevent and this event shall be received by Udev
(udevd process listening for uevents) .
Step 4: Then udev checks in the sysfs (file system) whether it have an rule corresponding for
this uevent. The rules are present in the /etc/udev/rules.d/*.rules.
Step 5: udevd will check all rules present under /etc/udev/rules.d/*.rules and identify this device matches with any rules present in this directory.
If it matches the rule, then it performs the actions (Setting the permissions,
run custom script, symlink etc.)
How to find the information using udevadm tool?
udevadm: is the udev management tool.
Commands :
udevadm info options
udevadm trigger [options]
udevadm settle [options]
udevadm control command
udevadm monitor [options]
udevadm test [options] devpath
Examples:
root@m:~# udevadm info
Usage: udevadm info OPTIONS
--query=<type> query device information:
name name of device node
symlink pointing to node
path sys device path
property the device properties
all all values
--path=<syspath> sys device path used for query or attribute walk
--name=<name> node or symlink name used for query or attribute walk
--root prepend dev directory to path names
--attribute-walk print all key matches while walking along the chain
of parent devices
--device-id-of-file=<file> print major:minor of device containing this file
--export export key/value pairs
--export-prefix export the key name with a prefix
--export-db export the content of the udev database
--cleanup-db cleanup the udev database
--help
Usage: udevadm info OPTIONS
--query=<type> query device information:
name name of device node
symlink pointing to node
path sys device path
property the device properties
all all values
--path=<syspath> sys device path used for query or attribute walk
--name=<name> node or symlink name used for query or attribute walk
--root prepend dev directory to path names
--attribute-walk print all key matches while walking along the chain
of parent devices
--device-id-of-file=<file> print major:minor of device containing this file
--export export key/value pairs
--export-prefix export the key name with a prefix
--export-db export the content of the udev database
--cleanup-db cleanup the udev database
--help
root@m:~# fdisk -l /dev/sda
Disk /dev/sda: 250.1 GB, 250059350016 bytes
255 heads, 63 sectors/track, 30401 cylinders, total 488397168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000bb738
Device Boot Start End Blocks Id System
/dev/sda1 2048 34613373 17305663 da Non-FS data
/dev/sda4 * 34613374 156248189 60817408 fd
Disk /dev/sda: 250.1 GB, 250059350016 bytes
255 heads, 63 sectors/track, 30401 cylinders, total 488397168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000bb738
Device Boot Start End Blocks Id System
/dev/sda1 2048 34613373 17305663 da Non-FS data
/dev/sda4 * 34613374 156248189 60817408 fd
root@m:~# udevadm info -a /dev/sda
Udevadm info starts with the device specified by the devpath and then
walks up the chain of parent devices. It prints for every device
found, all possible attributes in the udev rules key format.
A rule to match, can be composed by the attributes of the device
and the attributes from one single parent device.
looking at device '/devices/pci0000:00/0000:00:1f.2/ata1/host0/target0:0:0/0:0:0:0/block/sda':
KERNEL=="sda"
SUBSYSTEM=="block"
DRIVER==""
ATTR{ro}=="0"
ATTR{size}=="488397168"
ATTR{stat}==" 136370 841647 122415922 2097420 50871 33096 613279 317380 0 764248 2414756"
ATTR{range}=="16"
ATTR{discard_alignment}=="0"
ATTR{events}==""
ATTR{ext_range}=="256"
ATTR{events_poll_msecs}=="-1"
ATTR{alignment_offset}=="0"
ATTR{inflight}==" 0 0"
ATTR{removable}=="0"
ATTR{capability}=="50"
ATTR{events_async}==""
looking at parent device '/devices/pci0000:00/0000:00:1f.2/ata1/host0/target0:0:0/0:0:0:0':
KERNELS=="0:0:0:0"
SUBSYSTEMS=="scsi"
DRIVERS=="sd"
ATTRS{rev}=="19.0"
ATTRS{type}=="0"
ATTRS{scsi_level}=="6"
ATTRS{model}=="WDC WD2500AAKX-7"
ATTRS{state}=="running"
ATTRS{queue_type}=="simple"
ATTRS{iodone_cnt}=="0x35107"
ATTRS{iorequest_cnt}=="0x35b96"
ATTRS{queue_ramp_up_period}=="120000"
ATTRS{device_busy}=="0"
ATTRS{evt_capacity_change_reported}=="0"
ATTRS{timeout}=="30"
ATTRS{evt_media_change}=="0"
ATTRS{ioerr_cnt}=="0x67"
ATTRS{queue_depth}=="31"
ATTRS{vendor}=="ATA "
ATTRS{evt_soft_threshold_reached}=="0"
ATTRS{device_blocked}=="0"
ATTRS{evt_mode_parameter_change_reported}=="0"
ATTRS{evt_lun_change_reported}=="0"
ATTRS{evt_inquiry_change_reported}=="0"
ATTRS{iocounterbits}=="32"
ATTRS{eh_timeout}=="10"
looking at parent device '/devices/pci0000:00/0000:00:1f.2/ata1/host0/target0:0:0':
KERNELS=="target0:0:0"
SUBSYSTEMS=="scsi"
DRIVERS==""
looking at parent device '/devices/pci0000:00/0000:00:1f.2/ata1/host0':
KERNELS=="host0"
SUBSYSTEMS=="scsi"
DRIVERS==""
looking at parent device '/devices/pci0000:00/0000:00:1f.2/ata1':
KERNELS=="ata1"
SUBSYSTEMS==""
DRIVERS==""
looking at parent device '/devices/pci0000:00/0000:00:1f.2':
KERNELS=="0000:00:1f.2"
SUBSYSTEMS=="pci"
DRIVERS=="ahci"
ATTRS{irq}=="51"
ATTRS{subsystem_vendor}=="0x1028"
ATTRS{broken_parity_status}=="0"
ATTRS{class}=="0x010400"
ATTRS{consistent_dma_mask_bits}=="64"
ATTRS{dma_mask_bits}=="64"
ATTRS{local_cpus}=="ff"
ATTRS{device}=="0x2822"
ATTRS{enable}=="1"
ATTRS{msi_bus}==""
ATTRS{local_cpulist}=="0-7"
ATTRS{vendor}=="0x8086"
ATTRS{subsystem_device}=="0x02fb"
ATTRS{d3cold_allowed}=="1"
looking at parent device '/devices/pci0000:00':
KERNELS=="pci0000:00"
SUBSYSTEMS==""
Udevadm info starts with the device specified by the devpath and then
walks up the chain of parent devices. It prints for every device
found, all possible attributes in the udev rules key format.
A rule to match, can be composed by the attributes of the device
and the attributes from one single parent device.
looking at device '/devices/pci0000:00/0000:00:1f.2/ata1/host0/target0:0:0/0:0:0:0/block/sda':
KERNEL=="sda"
SUBSYSTEM=="block"
DRIVER==""
ATTR{ro}=="0"
ATTR{size}=="488397168"
ATTR{stat}==" 136370 841647 122415922 2097420 50871 33096 613279 317380 0 764248 2414756"
ATTR{range}=="16"
ATTR{discard_alignment}=="0"
ATTR{events}==""
ATTR{ext_range}=="256"
ATTR{events_poll_msecs}=="-1"
ATTR{alignment_offset}=="0"
ATTR{inflight}==" 0 0"
ATTR{removable}=="0"
ATTR{capability}=="50"
ATTR{events_async}==""
looking at parent device '/devices/pci0000:00/0000:00:1f.2/ata1/host0/target0:0:0/0:0:0:0':
KERNELS=="0:0:0:0"
SUBSYSTEMS=="scsi"
DRIVERS=="sd"
ATTRS{rev}=="19.0"
ATTRS{type}=="0"
ATTRS{scsi_level}=="6"
ATTRS{model}=="WDC WD2500AAKX-7"
ATTRS{state}=="running"
ATTRS{queue_type}=="simple"
ATTRS{iodone_cnt}=="0x35107"
ATTRS{iorequest_cnt}=="0x35b96"
ATTRS{queue_ramp_up_period}=="120000"
ATTRS{device_busy}=="0"
ATTRS{evt_capacity_change_reported}=="0"
ATTRS{timeout}=="30"
ATTRS{evt_media_change}=="0"
ATTRS{ioerr_cnt}=="0x67"
ATTRS{queue_depth}=="31"
ATTRS{vendor}=="ATA "
ATTRS{evt_soft_threshold_reached}=="0"
ATTRS{device_blocked}=="0"
ATTRS{evt_mode_parameter_change_reported}=="0"
ATTRS{evt_lun_change_reported}=="0"
ATTRS{evt_inquiry_change_reported}=="0"
ATTRS{iocounterbits}=="32"
ATTRS{eh_timeout}=="10"
looking at parent device '/devices/pci0000:00/0000:00:1f.2/ata1/host0/target0:0:0':
KERNELS=="target0:0:0"
SUBSYSTEMS=="scsi"
DRIVERS==""
looking at parent device '/devices/pci0000:00/0000:00:1f.2/ata1/host0':
KERNELS=="host0"
SUBSYSTEMS=="scsi"
DRIVERS==""
looking at parent device '/devices/pci0000:00/0000:00:1f.2/ata1':
KERNELS=="ata1"
SUBSYSTEMS==""
DRIVERS==""
looking at parent device '/devices/pci0000:00/0000:00:1f.2':
KERNELS=="0000:00:1f.2"
SUBSYSTEMS=="pci"
DRIVERS=="ahci"
ATTRS{irq}=="51"
ATTRS{subsystem_vendor}=="0x1028"
ATTRS{broken_parity_status}=="0"
ATTRS{class}=="0x010400"
ATTRS{consistent_dma_mask_bits}=="64"
ATTRS{dma_mask_bits}=="64"
ATTRS{local_cpus}=="ff"
ATTRS{device}=="0x2822"
ATTRS{enable}=="1"
ATTRS{msi_bus}==""
ATTRS{local_cpulist}=="0-7"
ATTRS{vendor}=="0x8086"
ATTRS{subsystem_device}=="0x02fb"
ATTRS{d3cold_allowed}=="1"
looking at parent device '/devices/pci0000:00':
KERNELS=="pci0000:00"
SUBSYSTEMS==""
root@m:~# udevadm info --export-db > entire_udev_database
root@m:~# vim entire_udev_database
P: /devices/pci0000:00/0000:00:1f.2/ata1/host0/target0:0:0/0:0:0:0/block/sda
N: sda
S: disk/by-id/ata-WDC_WD2500AAKX-75U6AA0_WD-WCC2F1095181
S: disk/by-id/wwn-0x50014ee207ecee4d
S: rootdisk
E: DEVLINKS=/dev/disk/by-id/ata-WDC_WD2500AAKX-75U6AA0_WD-WCC2F1095181 /dev/disk/by-id/wwn-0x50014ee207ecee4d /dev/rootdisk
E: DEVNAME=/dev/sda
E: DEVPATH=/devices/pci0000:00/0000:00:1f.2/ata1/host0/target0:0:0/0:0:0:0/block/sda
E: DEVTYPE=disk
E: ID_ATA=1
E: ID_ATA_DOWNLOAD_MICROCODE=1
E: ID_ATA_FEATURE_SET_HPA=1
E: ID_ATA_FEATURE_SET_HPA_ENABLED=1
E: ID_ATA_FEATURE_SET_PM=1
E: ID_ATA_FEATURE_SET_PM_ENABLED=1
E: ID_ATA_FEATURE_SET_PUIS=1
E: ID_ATA_FEATURE_SET_PUIS_ENABLED=0
E: ID_ATA_FEATURE_SET_SECURITY=1
E: ID_ATA_FEATURE_SET_SECURITY_ENABLED=0
E: ID_ATA_FEATURE_SET_SECURITY_ENHANCED_ERASE_UNIT_MIN=44
E: ID_ATA_FEATURE_SET_SECURITY_ERASE_UNIT_MIN=44
E: ID_ATA_FEATURE_SET_SECURITY_FROZEN=1
E: ID_ATA_FEATURE_SET_SMART=1
E: ID_ATA_FEATURE_SET_SMART_ENABLED=1
E: ID_ATA_SATA=1
E: ID_ATA_SATA_SIGNAL_RATE_GEN1=1
E: ID_ATA_SATA_SIGNAL_RATE_GEN2=1
E: ID_ATA_WRITE_CACHE=1
E: ID_ATA_WRITE_CACHE_ENABLED=1
E: ID_BUS=ata
E: ID_MODEL=WDC_WD2500AAKX-75U6AA0
E: ID_MODEL_ENC=WDC\x20WD2500AAKX-75U6AA0\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20
E: ID_PART_TABLE_TYPE=dos
E: ID_REVISION=19.01H19
E: ID_SERIAL=WDC_WD2500AAKX-75U6AA0_WD-WCC2F1095181
E: ID_SERIAL_SHORT=WD-WCC2F1095181
E: ID_TYPE=disk
E: ID_WWN=0x50014ee207ecee4d
E: ID_WWN_WITH_EXTENSION=0x50014ee207ecee4d
E: MAJOR=8
E: MINOR=0
E: SUBSYSTEM=block
E: UDISKS_IGNORE=1
E: USEC_INITIALIZED=4665
E: nomdmonddf=1
E: nomdmonisw=1
root@m:~# udevadm info -a /dev/ttyS4
looking at device '/devices/platform/serial8250/tty/ttyS4':
KERNEL=="ttyS4"
SUBSYSTEM=="tty"
DRIVER==""
ATTR{irq}=="0"
ATTR{line}=="4"
ATTR{port}=="0x0"
ATTR{type}=="0"
ATTR{flags}=="0x0"
ATTR{iomem_base}=="0x0"
ATTR{custom_divisor}=="0"
ATTR{iomem_reg_shift}=="0"
ATTR{uartclk}=="0"
ATTR{xmit_fifo_size}=="0"
ATTR{close_delay}=="50"
ATTR{closing_wait}=="3000"
ATTR{io_type}=="0"
looking at parent device '/devices/platform/serial8250':
KERNELS=="serial8250"
SUBSYSTEMS=="platform"
DRIVERS=="serial8250"
looking at parent device '/devices/platform':
KERNELS=="platform"
SUBSYSTEMS==""
DRIVERS==""
root@m:~# udevadm info --attribute-walk /dev/ttyS4
looking at device '/devices/platform/serial8250/tty/ttyS4':
KERNEL=="ttyS4"
SUBSYSTEM=="tty"
DRIVER==""
ATTR{irq}=="0"
ATTR{line}=="4"
ATTR{port}=="0x0"
ATTR{type}=="0"
ATTR{flags}=="0x0"
ATTR{iomem_base}=="0x0"
ATTR{custom_divisor}=="0"
ATTR{iomem_reg_shift}=="0"
ATTR{uartclk}=="0"
ATTR{xmit_fifo_size}=="0"
ATTR{close_delay}=="50"
ATTR{closing_wait}=="3000"
ATTR{io_type}=="0"
looking at parent device '/devices/platform/serial8250':
KERNELS=="serial8250"
SUBSYSTEMS=="platform"
DRIVERS=="serial8250"
looking at parent device '/devices/platform':
KERNELS=="platform"
SUBSYSTEMS==""
DRIVERS==""
# Connect USB to the system and Monitor the Uevent
# remove the USB from the System
root@m:~# udevadm monitor
monitor will print the received events for:
UDEV - the event which udev sends out after rule processing
KERNEL - the kernel uevent
Example:
-------
# Connect the USB device.
root@m:~# udevadm monitor
monitor will print the received events for:
UDEV - the event which udev sends out after rule processing
KERNEL - the kernel uevent
KERNEL[80864.173700] add /devices/pci0000:00/0000:00:1d.7/usb2/2-2 (usb)
KERNEL[80864.176371] add /devices/pci0000:00/0000:00:1d.7/usb2/2-2/2-2:1.0 (usb)
KERNEL[80864.176637] add /devices/pci0000:00/0000:00:1d.7/usb2/2-2/2-2:1.0/host8 (scsi)
KERNEL[80864.176954] add /devices/pci0000:00/0000:00:1d.7/usb2/2-2/2-2:1.0/host8/scsi_host/host8 (scsi_host)
UDEV [80864.179558] add /devices/pci0000:00/0000:00:1d.7/usb2/2-2 (usb)
UDEV [80864.185429] add /devices/pci0000:00/0000:00:1d.7/usb2/2-2/2-2:1.0 (usb)
UDEV [80864.186228] add /devices/pci0000:00/0000:00:1d.7/usb2/2-2/2-2:1.0/host8 (scsi)
UDEV [80864.187256] add /devices/pci0000:00/0000:00:1d.7/usb2/2-2/2-2:1.0/host8/scsi_host/host8 (scsi_host)
KERNEL[80865.183894] add /devices/pci0000:00/0000:00:1d.7/usb2/2-2/2-2:1.0/host8/target8:0:0 (scsi)
KERNEL[80865.183920] add /devices/pci0000:00/0000:00:1d.7/usb2/2-2/2-2:1.0/host8/target8:0:0/8:0:0:0 (scsi)
UDEV [80865.185043] add /devices/pci0000:00/0000:00:1d.7/usb2/2-2/2-2:1.0/host8/target8:0:0 (scsi)
UDEV [80865.186744] add /devices/pci0000:00/0000:00:1d.7/usb2/2-2/2-2:1.0/host8/target8:0:0/8:0:0:0 (scsi)
KERNEL[80865.209430] add /devices/virtual/bdi/11:1 (bdi)
KERNEL[80865.209663] add /devices/pci0000:00/0000:00:1d.7/usb2/2-2/2-2:1.0/host8/target8:0:0/8:0:0:0/block/sr1 (block)
KERNEL[80865.209982] add /devices/pci0000:00/0000:00:1d.7/usb2/2-2/2-2:1.0/host8/target8:0:0/8:0:0:0/scsi_device/8:0:0:0 (scsi_device)
UDEV [80865.210161] add /devices/virtual/bdi/11:1 (bdi)
UDEV [80865.211365] add /devices/pci0000:00/0000:00:1d.7/usb2/2-2/2-2:1.0/host8/target8:0:0/8:0:0:0/scsi_device/8:0:0:0 (scsi_device)
KERNEL[80865.211855] add /devices/pci0000:00/0000:00:1d.7/usb2/2-2/2-2:1.0/host8/target8:0:0/8:0:0:0/scsi_generic/sg3 (scsi_generic)
KERNEL[80865.212244] add /devices/pci0000:00/0000:00:1d.7/usb2/2-2/2-2:1.0/host8/target8:0:0/8:0:0:0/bsg/8:0:0:0 (bsg)
UDEV [80865.213882] add /devices/pci0000:00/0000:00:1d.7/usb2/2-2/2-2:1.0/host8/target8:0:0/8:0:0:0/scsi_generic/sg3 (scsi_generic)
UDEV [80865.215214] add /devices/pci0000:00/0000:00:1d.7/usb2/2-2/2-2:1.0/host8/target8:0:0/8:0:0:0/bsg/8:0:0:0 (bsg)
KERNEL[80865.216289] change /devices/pci0000:00/0000:00:1d.7/usb2/2-2/2-2:1.0/host8/target8:0:0/8:0:0:0/block/sr1 (block)
UDEV [80865.300548] add /devices/pci0000:00/0000:00:1d.7/usb2/2-2/2-2:1.0/host8/target8:0:0/8:0:0:0/block/sr1 (block)
UDEV [80865.366209] change /devices/pci0000:00/0000:00:1d.7/usb2/2-2/2-2:1.0/host8/target8:0:0/8:0:0:0/block/sr1 (block)
--------------------------------
# Remove the USB Device
KERNEL[80880.634465] remove /devices/pci0000:00/0000:00:1d.7/usb2/2-2/2-2:1.0/host8/target8:0:0/8:0:0:0/bsg/8:0:0:0 (bsg)
KERNEL[80880.634629] remove /devices/pci0000:00/0000:00:1d.7/usb2/2-2/2-2:1.0/host8/target8:0:0/8:0:0:0/scsi_generic/sg3 (scsi_generic)
KERNEL[80880.634655] remove /devices/pci0000:00/0000:00:1d.7/usb2/2-2/2-2:1.0/host8/target8:0:0/8:0:0:0/scsi_device/8:0:0:0 (scsi_device)
KERNEL[80880.634790] remove /devices/virtual/bdi/11:1 (bdi)
KERNEL[80880.634881] remove /devices/pci0000:00/0000:00:1d.7/usb2/2-2/2-2:1.0/host8/target8:0:0/8:0:0:0/block/sr1 (block)
KERNEL[80880.635073] remove /devices/pci0000:00/0000:00:1d.7/usb2/2-2/2-2:1.0/host8/target8:0:0/8:0:0:0 (scsi)
KERNEL[80880.635098] remove /devices/pci0000:00/0000:00:1d.7/usb2/2-2/2-2:1.0/host8/target8:0:0 (scsi)
KERNEL[80880.635116] remove /devices/pci0000:00/0000:00:1d.7/usb2/2-2/2-2:1.0/host8/scsi_host/host8 (scsi_host)
2:1.0/host8/target8:0:0/8:0:0:0/block/sr1 (block)
UDEV [80880.651967] remove /devices/pci0000:00/0000:00:1d.7/usb2/2-2/2-2:1.0/host8/target8:0:0/8:0:0:0 (scsi)
UDEV [80880.653369] remove /devices/pci0000:00/0000:00:1d.7/usb2/2-2/2-2:1.0/host8/target8:0:0 (scsi)
UDEV [80880.654570] remove /devices/pci0000:00/0000:00:1d.7/usb2/2-2/2-2:1.0/host8 (scsi)
UDEV [80880.655604] remove /devices/pci0000:00/0000:00:1d.7/usb2/2-2/2-2:1.0 (usb)
/sys/devices/pci0000:00/0000:00:1f.2/ata2/host1/scsi_host/host1
/sys/devices/pci0000:00/0000:00:1f.2/ata3/host2/scsi_host/host2
/sys/devices/pci0000:00/0000:00:1f.2/ata4/host3/scsi_host/host3
/sys/devices/pci0000:00/0000:00:1f.2/ata5/host4/scsi_host/host4
/sys/devices/pci0000:00/0000:00:1f.2/ata6/host5/scsi_host/host5
root@m:~# vim entire_udev_database
P: /devices/pci0000:00/0000:00:1f.2/ata1/host0/target0:0:0/0:0:0:0/block/sda
N: sda
S: disk/by-id/ata-WDC_WD2500AAKX-75U6AA0_WD-WCC2F1095181
S: disk/by-id/wwn-0x50014ee207ecee4d
S: rootdisk
E: DEVLINKS=/dev/disk/by-id/ata-WDC_WD2500AAKX-75U6AA0_WD-WCC2F1095181 /dev/disk/by-id/wwn-0x50014ee207ecee4d /dev/rootdisk
E: DEVNAME=/dev/sda
E: DEVPATH=/devices/pci0000:00/0000:00:1f.2/ata1/host0/target0:0:0/0:0:0:0/block/sda
E: DEVTYPE=disk
E: ID_ATA=1
E: ID_ATA_DOWNLOAD_MICROCODE=1
E: ID_ATA_FEATURE_SET_HPA=1
E: ID_ATA_FEATURE_SET_HPA_ENABLED=1
E: ID_ATA_FEATURE_SET_PM=1
E: ID_ATA_FEATURE_SET_PM_ENABLED=1
E: ID_ATA_FEATURE_SET_PUIS=1
E: ID_ATA_FEATURE_SET_PUIS_ENABLED=0
E: ID_ATA_FEATURE_SET_SECURITY=1
E: ID_ATA_FEATURE_SET_SECURITY_ENABLED=0
E: ID_ATA_FEATURE_SET_SECURITY_ENHANCED_ERASE_UNIT_MIN=44
E: ID_ATA_FEATURE_SET_SECURITY_ERASE_UNIT_MIN=44
E: ID_ATA_FEATURE_SET_SECURITY_FROZEN=1
E: ID_ATA_FEATURE_SET_SMART=1
E: ID_ATA_FEATURE_SET_SMART_ENABLED=1
E: ID_ATA_SATA=1
E: ID_ATA_SATA_SIGNAL_RATE_GEN1=1
E: ID_ATA_SATA_SIGNAL_RATE_GEN2=1
E: ID_ATA_WRITE_CACHE=1
E: ID_ATA_WRITE_CACHE_ENABLED=1
E: ID_BUS=ata
E: ID_MODEL=WDC_WD2500AAKX-75U6AA0
E: ID_MODEL_ENC=WDC\x20WD2500AAKX-75U6AA0\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20
E: ID_PART_TABLE_TYPE=dos
E: ID_REVISION=19.01H19
E: ID_SERIAL=WDC_WD2500AAKX-75U6AA0_WD-WCC2F1095181
E: ID_SERIAL_SHORT=WD-WCC2F1095181
E: ID_TYPE=disk
E: ID_WWN=0x50014ee207ecee4d
E: ID_WWN_WITH_EXTENSION=0x50014ee207ecee4d
E: MAJOR=8
E: MINOR=0
E: SUBSYSTEM=block
E: UDISKS_IGNORE=1
E: USEC_INITIALIZED=4665
E: nomdmonddf=1
E: nomdmonisw=1
root@m:~# udevadm info -a /dev/ttyS4
looking at device '/devices/platform/serial8250/tty/ttyS4':
KERNEL=="ttyS4"
SUBSYSTEM=="tty"
DRIVER==""
ATTR{irq}=="0"
ATTR{line}=="4"
ATTR{port}=="0x0"
ATTR{type}=="0"
ATTR{flags}=="0x0"
ATTR{iomem_base}=="0x0"
ATTR{custom_divisor}=="0"
ATTR{iomem_reg_shift}=="0"
ATTR{uartclk}=="0"
ATTR{xmit_fifo_size}=="0"
ATTR{close_delay}=="50"
ATTR{closing_wait}=="3000"
ATTR{io_type}=="0"
looking at parent device '/devices/platform/serial8250':
KERNELS=="serial8250"
SUBSYSTEMS=="platform"
DRIVERS=="serial8250"
looking at parent device '/devices/platform':
KERNELS=="platform"
SUBSYSTEMS==""
DRIVERS==""
looking at device '/devices/platform/serial8250/tty/ttyS4':
KERNEL=="ttyS4"
SUBSYSTEM=="tty"
DRIVER==""
ATTR{irq}=="0"
ATTR{line}=="4"
ATTR{port}=="0x0"
ATTR{type}=="0"
ATTR{flags}=="0x0"
ATTR{iomem_base}=="0x0"
ATTR{custom_divisor}=="0"
ATTR{iomem_reg_shift}=="0"
ATTR{uartclk}=="0"
ATTR{xmit_fifo_size}=="0"
ATTR{close_delay}=="50"
ATTR{closing_wait}=="3000"
ATTR{io_type}=="0"
looking at parent device '/devices/platform/serial8250':
KERNELS=="serial8250"
SUBSYSTEMS=="platform"
DRIVERS=="serial8250"
looking at parent device '/devices/platform':
KERNELS=="platform"
SUBSYSTEMS==""
DRIVERS==""
# Connect USB to the system and Monitor the Uevent
# remove the USB from the System
root@m:~# udevadm monitor
monitor will print the received events for:
UDEV - the event which udev sends out after rule processing
KERNEL - the kernel uevent
Example:
-------
# Connect the USB device.
root@m:~# udevadm monitor
monitor will print the received events for:
UDEV - the event which udev sends out after rule processing
KERNEL - the kernel uevent
KERNEL[80864.173700] add /devices/pci0000:00/0000:00:1d.7/usb2/2-2 (usb)
KERNEL[80864.176371] add /devices/pci0000:00/0000:00:1d.7/usb2/2-2/2-2:1.0 (usb)
KERNEL[80864.176637] add /devices/pci0000:00/0000:00:1d.7/usb2/2-2/2-2:1.0/host8 (scsi)
KERNEL[80864.176954] add /devices/pci0000:00/0000:00:1d.7/usb2/2-2/2-2:1.0/host8/scsi_host/host8 (scsi_host)
UDEV [80864.179558] add /devices/pci0000:00/0000:00:1d.7/usb2/2-2 (usb)
UDEV [80864.185429] add /devices/pci0000:00/0000:00:1d.7/usb2/2-2/2-2:1.0 (usb)
UDEV [80864.186228] add /devices/pci0000:00/0000:00:1d.7/usb2/2-2/2-2:1.0/host8 (scsi)
UDEV [80864.187256] add /devices/pci0000:00/0000:00:1d.7/usb2/2-2/2-2:1.0/host8/scsi_host/host8 (scsi_host)
KERNEL[80865.183894] add /devices/pci0000:00/0000:00:1d.7/usb2/2-2/2-2:1.0/host8/target8:0:0 (scsi)
KERNEL[80865.183920] add /devices/pci0000:00/0000:00:1d.7/usb2/2-2/2-2:1.0/host8/target8:0:0/8:0:0:0 (scsi)
UDEV [80865.185043] add /devices/pci0000:00/0000:00:1d.7/usb2/2-2/2-2:1.0/host8/target8:0:0 (scsi)
UDEV [80865.186744] add /devices/pci0000:00/0000:00:1d.7/usb2/2-2/2-2:1.0/host8/target8:0:0/8:0:0:0 (scsi)
KERNEL[80865.209430] add /devices/virtual/bdi/11:1 (bdi)
KERNEL[80865.209663] add /devices/pci0000:00/0000:00:1d.7/usb2/2-2/2-2:1.0/host8/target8:0:0/8:0:0:0/block/sr1 (block)
KERNEL[80865.209982] add /devices/pci0000:00/0000:00:1d.7/usb2/2-2/2-2:1.0/host8/target8:0:0/8:0:0:0/scsi_device/8:0:0:0 (scsi_device)
UDEV [80865.210161] add /devices/virtual/bdi/11:1 (bdi)
UDEV [80865.211365] add /devices/pci0000:00/0000:00:1d.7/usb2/2-2/2-2:1.0/host8/target8:0:0/8:0:0:0/scsi_device/8:0:0:0 (scsi_device)
KERNEL[80865.211855] add /devices/pci0000:00/0000:00:1d.7/usb2/2-2/2-2:1.0/host8/target8:0:0/8:0:0:0/scsi_generic/sg3 (scsi_generic)
KERNEL[80865.212244] add /devices/pci0000:00/0000:00:1d.7/usb2/2-2/2-2:1.0/host8/target8:0:0/8:0:0:0/bsg/8:0:0:0 (bsg)
UDEV [80865.213882] add /devices/pci0000:00/0000:00:1d.7/usb2/2-2/2-2:1.0/host8/target8:0:0/8:0:0:0/scsi_generic/sg3 (scsi_generic)
UDEV [80865.215214] add /devices/pci0000:00/0000:00:1d.7/usb2/2-2/2-2:1.0/host8/target8:0:0/8:0:0:0/bsg/8:0:0:0 (bsg)
KERNEL[80865.216289] change /devices/pci0000:00/0000:00:1d.7/usb2/2-2/2-2:1.0/host8/target8:0:0/8:0:0:0/block/sr1 (block)
UDEV [80865.300548] add /devices/pci0000:00/0000:00:1d.7/usb2/2-2/2-2:1.0/host8/target8:0:0/8:0:0:0/block/sr1 (block)
UDEV [80865.366209] change /devices/pci0000:00/0000:00:1d.7/usb2/2-2/2-2:1.0/host8/target8:0:0/8:0:0:0/block/sr1 (block)
--------------------------------
# Remove the USB Device
KERNEL[80880.634465] remove /devices/pci0000:00/0000:00:1d.7/usb2/2-2/2-2:1.0/host8/target8:0:0/8:0:0:0/bsg/8:0:0:0 (bsg)
KERNEL[80880.634629] remove /devices/pci0000:00/0000:00:1d.7/usb2/2-2/2-2:1.0/host8/target8:0:0/8:0:0:0/scsi_generic/sg3 (scsi_generic)
KERNEL[80880.634655] remove /devices/pci0000:00/0000:00:1d.7/usb2/2-2/2-2:1.0/host8/target8:0:0/8:0:0:0/scsi_device/8:0:0:0 (scsi_device)
KERNEL[80880.634790] remove /devices/virtual/bdi/11:1 (bdi)
KERNEL[80880.634881] remove /devices/pci0000:00/0000:00:1d.7/usb2/2-2/2-2:1.0/host8/target8:0:0/8:0:0:0/block/sr1 (block)
KERNEL[80880.635073] remove /devices/pci0000:00/0000:00:1d.7/usb2/2-2/2-2:1.0/host8/target8:0:0/8:0:0:0 (scsi)
KERNEL[80880.635098] remove /devices/pci0000:00/0000:00:1d.7/usb2/2-2/2-2:1.0/host8/target8:0:0 (scsi)
KERNEL[80880.635116] remove /devices/pci0000:00/0000:00:1d.7/usb2/2-2/2-2:1.0/host8/scsi_host/host8 (scsi_host)
2:1.0/host8/target8:0:0/8:0:0:0/block/sr1 (block)
UDEV [80880.651967] remove /devices/pci0000:00/0000:00:1d.7/usb2/2-2/2-2:1.0/host8/target8:0:0/8:0:0:0 (scsi)
UDEV [80880.653369] remove /devices/pci0000:00/0000:00:1d.7/usb2/2-2/2-2:1.0/host8/target8:0:0 (scsi)
UDEV [80880.654570] remove /devices/pci0000:00/0000:00:1d.7/usb2/2-2/2-2:1.0/host8 (scsi)
UDEV [80880.655604] remove /devices/pci0000:00/0000:00:1d.7/usb2/2-2/2-2:1.0 (usb)
udevadm trigger
----------------
root@m:~# udevadm trigger --verbose --dry-run --type=devices --subsystem-match=scsi_host
/sys/devices/pci0000:00/0000:00:1f.2/ata1/host0/scsi_host/host0----------------
root@m:~# udevadm trigger --verbose --dry-run --type=devices --subsystem-match=scsi_host
/sys/devices/pci0000:00/0000:00:1f.2/ata2/host1/scsi_host/host1
/sys/devices/pci0000:00/0000:00:1f.2/ata3/host2/scsi_host/host2
/sys/devices/pci0000:00/0000:00:1f.2/ata4/host3/scsi_host/host3
/sys/devices/pci0000:00/0000:00:1f.2/ata5/host4/scsi_host/host4
/sys/devices/pci0000:00/0000:00:1f.2/ata6/host5/scsi_host/host5
Example:
------------
# We can also write the udev rules in /etc/udev/rules.d/* directory and reload the rules dynamically with out any reboot of the system.
Step 1: root@m:/etc/udev/rules.d# vi 99-yourOwn.rules
Step 2: Rule can be any thing, Add a device, run a script etc.
e.g: SUBSYSTEMS=="usb",ATTRS{idVendor}=="0ebc",RUN+="/etc/udev/myscript.sh"
Step 3: udevadm control --reload-rules
Reload the rules with out any reboot.
Step 4: udevadm trigger
And then check the result in the log files or any verify your expected functionality.
Sometimes, you can skip the step 3: udevadm control --reload-rules
udevadm test
-------------
The above command used to the test the devices and check the functionality is working or not.
Example:
------------
Step 1:
root@m:~# lsusb
Bus 002 Device 004: ID 0b95:1780 ASIX Electronics Corp. AX88178
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 008 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 007 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 006 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 003 Device 002: ID 03f9:0100 KeyTronic Corp. KT-2001 Keyboard
Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Step 2: From above lsusb , get the device name as:
Bus 003 Device 002: ID 03f9:0100 KeyTronic Corp.
The above line can be in Linux file system as
/dev/bus/usb/003/002
Step 3: Use the above path and get the device information using udevadm
udevadm info -a -p $(udevadm info -q path -n /dev/bus/usb/003/002)
root@m:~# udevadm info -a -p $(udevadm info -q path -n /dev/bus/usb/003/002)
looking at device '/devices/pci0000:00/0000:00:1a.0/usb3/3-1':
KERNEL=="3-1"
SUBSYSTEM=="usb"
DRIVER=="usb"
ATTR{bDeviceSubClass}=="00"
ATTR{bDeviceProtocol}=="00"
ATTR{devpath}=="1"
ATTR{idVendor}=="03f9"
ATTR{speed}=="1.5"
ATTR{bNumInterfaces}==" 1"
ATTR{bConfigurationValue}=="1"
ATTR{bMaxPacketSize0}=="8"
ATTR{busnum}=="3"
ATTR{devnum}=="2"
ATTR{configuration}==""
ATTR{bMaxPower}=="100mA"
ATTR{manufacturer}=="Key Tronic"
ATTR{removable}=="unknown"
ATTR{idProduct}=="0100"
ATTR{bDeviceClass}=="00"
ATTR{product}=="Keytronic USB Keyboard"
Step 4:
root@m:~# vi /etc/udev/rules.d/10-local.rules
To give permissions for everyone , then add this rule which is matching vendor Id.
SUBSYSTEMS=="usb", ATTR{idVendor}=="03f9", GROUP="users"
Step 5: Test the rule as : udevadm test < path of the device>
root@m:~# udevadm test /devices/pci0000:00/0000:00:1a.0/usb3/3-1
calling: test
version 204
This program is for debugging only, it does not run any program
specified by a RUN key. It may show incorrect results, because
some values may be different, or not available at a simulation run.
=== trie on-disk ===
tool version: 204
file size: 5759486 bytes
header size 80 bytes
strings 1267110 bytes
nodes 4492296 bytes
load module index
read rules file: /etc/udev/rules.d/10-local.rules
read rules file: /lib/udev/rules.d/40-crda.rules
read rules file: /lib/udev/rules.d/60-keyboard.rules
read rules file: /lib/udev/rules.d/69-xorg-vmmouse.rules
read rules file: /lib/udev/rules.d/69-xserver-xorg-input-wacom.rules
read rules file: /lib/udev/rules.d/77-mm-platform-serial-whitelist.rules
read rules file: /lib/udev/rules.d/90-pulseaudio.rules
read rules file: /lib/udev/rules.d/95-cd-devices.rules
read rules file: /lib/udev/rules.d/95-udev-late.rules
read rules file: /etc/udev/rules.d/99-lexscan.rules
rules contain 196608 bytes tokens (16384 * 12 bytes), 30463 bytes strings
13055 strings (122264 bytes), 10544 de-duplicated (94313 bytes), 2512 trie nodes used
GROUP 100 /etc/udev/rules.d/10-local.rules:10
IMPORT builtin 'usb_id' /lib/udev/rules.d/40-libgphoto2-6.rules:3
IMPORT builtin skip 'usb_id' /lib/udev/rules.d/50-udev-default.rules:9
IMPORT builtin 'hwdb' /lib/udev/rules.d/50-udev-default.rules:9
MODE 0664 /lib/udev/rules.d/50-udev-default.rules:36
handling device node '/dev/bus/usb/003/002', devnum=c189:257, mode=0664, uid=0, gid=100
set permissions /dev/bus/usb/003/002, 020664, uid=0, gid=100
preserve already existing symlink '/dev/char/189:257' to '../bus/usb/003/002'
ACTION=add
BUSNUM=003
DEVNAME=/dev/bus/usb/003/002
DEVNUM=002
DEVPATH=/devices/pci0000:00/0000:00:1a.0/usb3/3-1
DEVTYPE=usb_device
DRIVER=usb
ID_BUS=usb
ID_MODEL=Keytronic_USB_Keyboard
ID_MODEL_ENC=Keytronic\x20USB\x20Keyboard
ID_MODEL_FROM_DATABASE=KT-2001 Keyboard
ID_MODEL_ID=0100
ID_REVISION=0102
ID_SERIAL=Key_Tronic_Keytronic_USB_Keyboard
ID_USB_INTERFACES=:030101:
ID_VENDOR=Key_Tronic
ID_VENDOR_ENC=Key\x20Tronic
ID_VENDOR_FROM_DATABASE=KeyTronic Corp.
ID_VENDOR_ID=03f9
MAJOR=189
https://bayanlarsitesi.com/
ReplyDeleteEskişehir
Erzincan
Ardahan
Erzurum
TDİ
Bolu Lojistik
ReplyDeleteMardin Lojistik
Kocaeli Lojistik
Diyarbakır Lojistik
İstanbul Lojistik
MSUP
çankırı evden eve nakliyat
ReplyDeletekırşehir evden eve nakliyat
kütahya evden eve nakliyat
hakkari evden eve nakliyat
antalya evden eve nakliyat
S2F
5A42A
ReplyDeleteKırıkkale Evden Eve Nakliyat
Sinop Parça Eşya Taşıma
Sivas Evden Eve Nakliyat
Adıyaman Lojistik
Burdur Parça Eşya Taşıma
4B17F
ReplyDeleteSiirt Lojistik
Hatay Evden Eve Nakliyat
Malatya Lojistik
Konya Lojistik
Amasya Lojistik
CE2C8
ReplyDeletebinance komisyon indirimi %20
421BD
ReplyDeletebinance %20 referans kodu
093B7
ReplyDeleteArbitrum Coin Hangi Borsada
Anc Coin Hangi Borsada
Kripto Para Üretme
Bitcoin Kazanma
Twitch Takipçi Satın Al
Bitcoin Nedir
Tiktok İzlenme Hilesi
Linkedin Beğeni Hilesi
Chat Gpt Coin Hangi Borsada
051A1
ReplyDeleteBitcoin Nasıl Kazanılır
Yeni Çıkacak Coin Nasıl Alınır
Bitcoin Üretme Siteleri
Bitcoin Nasıl Alınır
Twitter Beğeni Hilesi
Vector Coin Hangi Borsada
Wabi Coin Hangi Borsada
Nexa Coin Hangi Borsada
Binance Neden Tercih Edilir