# Cheat Sheet #day31 - lspci

## lspci Cheatsheet

### Basic Usage

* **Display all PCI devices**:
    
    ```sh
    lspci
    ```
    

### Display Options

* **Verbose output** (more detailed information):
    
    ```sh
    lspci -v
    ```
    
* **Very verbose output** (even more details):
    
    ```sh
    lspci -vv
    ```
    
* **Maximum verbosity** (most detailed output):
    
    ```sh
    lspci -vvv
    ```
    
* **Show detailed output for a specific device** (replace `<device>` with the specific device ID):
    
    ```sh
    lspci -v -s <device>
    ```
    
* **Show only the specified device**:
    
    ```sh
    lspci -s <device>
    ```
    

### Information Types

* **Show numerical IDs** (useful for scripting):
    
    ```sh
    lspci -n
    ```
    
* **Show both textual and numerical IDs**:
    
    ```sh
    lspci -nn
    ```
    
* **Display information in a tree-like format**:
    
    ```sh
    lspci -t
    ```
    
* **Show kernel drivers handling each device**:
    
    ```sh
    lspci -k
    ```
    
* **Show hexadecimal dump of the standard config space**:
    
    ```sh
    lspci -x
    ```
    
* **Show detailed hexadecimal dump of the config space**:
    
    ```sh
    lspci -xxx
    ```
    
* **Show capabilities (if available)**:
    
    ```sh
    lspci -vv -s <device>
    ```
    

### Filtering and Sorting

* **Filter output by vendor or device name** (case insensitive):
    
    ```sh
    lspci | grep -i <vendor_or_device_name>
    ```
    
* **Filter and show detailed output for specific devices**:
    
    ```sh
    lspci -v | grep -i -A 20 <vendor_or_device_name>
    ```
    

### PCI Resources

* **Show the resource configuration**:
    
    ```sh
    lspci -v -m
    ```
    
* **Show only resource information**:
    
    ```sh
    lspci -vvv | grep -E '^[0-9a-f]+:|Region|Memory'
    ```
    

### Example Commands

* **List all NVIDIA devices**:
    
    ```sh
    lspci | grep -i nvidia
    ```
    
* **Show detailed information for a specific device (e.g., the first Ethernet controller)**:
    
    ```sh
    lspci -v | grep -i ethernet -A 10
    ```
    
* **List devices along with their kernel drivers**:
    
    ```sh
    lspci -k
    ```
    

### Saving and Parsing Output

* **Save the output to a file**:
    
    ```sh
    lspci -v > lspci_output.txt
    ```
    
* **Read and parse saved output**:
    
    ```sh
    cat lspci_output.txt
    ```
    

---

This cheatsheet provides a quick reference to the most commonly used `lspci` commands and options, helping you to efficiently manage and troubleshoot PCI devices on your system.
