AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • Início
  • system&network
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • Início
  • system&network
    • Recentes
    • Highest score
    • tags
  • Ubuntu
    • Recentes
    • Highest score
    • tags
  • Unix
    • Recentes
    • tags
  • DBA
    • Recentes
    • tags
  • Computer
    • Recentes
    • tags
  • Coding
    • Recentes
    • tags
Início / ubuntu / Perguntas / 1186170
Accepted
user205301
user205301
Asked: 2019-11-05 07:52:35 +0800 CST2019-11-05 07:52:35 +0800 CST 2019-11-05 07:52:35 +0800 CST

Como obter de forma confiável o nome de uma unidade USB conectada?

  • 772

Eu gostaria de obter (eventualmente em um systemdscript) o nome do dispositivo de uma unidade USB conectada (pendrive ou unidade SSD). Como posso fazer isso de forma confiável ? Podemos supor que haverá apenas uma unidade conectada, mas não sabemos UUIDnada sobre isso neste caso. Quero dizer algo assim:

lsblk | grep disk | awk '{print $1}' | tail -n1

No entanto, não tenho certeza se a unidade USB será sempre a última dessa lista.

boot usb usb-drive device-name
  • 1 1 respostas
  • 234 Views

1 respostas

  • Voted
  1. Best Answer
    schrodingerscatcuriosity
    2019-11-05T08:14:07+08:002019-11-05T08:14:07+08:00

    Se entendi corretamente, use o available columnspara lsblkimprimir as informações completas do usb:

    Por exemplo:

    lsblk -p -o NAME,SERIAL,VENDOR,MODEL,TRAN | grep usb
    

    O que dá a saída:

    /dev/sdc    000FEA0AB9F5BA60641508A8 Kingston DT 101 G2        usb
    

    Available columns (for --output):
    
            NAME  device name
           KNAME  internal kernel device name
         MAJ:MIN  major:minor device number
          FSTYPE  filesystem type
      MOUNTPOINT  where the device is mounted
           LABEL  filesystem LABEL
            UUID  filesystem UUID
        PARTTYPE  partition type UUID
       PARTLABEL  partition LABEL
        PARTUUID  partition UUID
       PARTFLAGS  partition flags
              RA  read-ahead of the device
              RO  read-only device
              RM  removable device
         HOTPLUG  removable or hotplug device (usb, pcmcia, ...)
           MODEL  device identifier
          SERIAL  disk serial number
            SIZE  size of the device
           STATE  state of the device
           OWNER  user name
           GROUP  group name
            MODE  device node permissions
       ALIGNMENT  alignment offset
          MIN-IO  minimum I/O size
          OPT-IO  optimal I/O size
         PHY-SEC  physical sector size
         LOG-SEC  logical sector size
            ROTA  rotational device
           SCHED  I/O scheduler name
         RQ-SIZE  request queue size
            TYPE  device type
        DISC-ALN  discard alignment offset
       DISC-GRAN  discard granularity
        DISC-MAX  discard max bytes
       DISC-ZERO  discard zeroes data
           WSAME  write same max bytes
             WWN  unique storage identifier
            RAND  adds randomness
          PKNAME  internal parent kernel device name
            HCTL  Host:Channel:Target:Lun for SCSI
            TRAN  device transport type
      SUBSYSTEMS  de-duplicated chain of subsystems
             REV  device revision
          VENDOR  device vendor
    
    • 5

relate perguntas

  • Como você redefine um dispositivo USB a partir da linha de comando?

Sidebar

Stats

  • Perguntas 205573
  • respostas 270741
  • best respostas 135370
  • utilizador 68524
  • Highest score
  • respostas
  • Marko Smith

    Existe um comando para listar todos os usuários? Também para adicionar, excluir, modificar usuários, no terminal?

    • 9 respostas
  • Marko Smith

    Como excluir um diretório não vazio no Terminal?

    • 4 respostas
  • Marko Smith

    Como descompactar um arquivo zip do Terminal?

    • 9 respostas
  • Marko Smith

    Como instalo um arquivo .deb por meio da linha de comando?

    • 11 respostas
  • Marko Smith

    Como instalo um arquivo .tar.gz (ou .tar.bz2)?

    • 14 respostas
  • Marko Smith

    Como listar todos os pacotes instalados

    • 24 respostas
  • Martin Hope
    Flimm Como posso usar o docker sem sudo? 2014-06-07 00:17:43 +0800 CST
  • Martin Hope
    led-Zepp Como faço para salvar a saída do terminal em um arquivo? 2014-02-15 11:49:07 +0800 CST
  • Martin Hope
    ubuntu-nerd Como descompactar um arquivo zip do Terminal? 2011-12-11 20:37:54 +0800 CST
  • Martin Hope
    TheXed Como instalo um arquivo .deb por meio da linha de comando? 2011-05-07 09:40:28 +0800 CST
  • Martin Hope
    Ivan Como listar todos os pacotes instalados 2010-12-17 18:08:49 +0800 CST
  • Martin Hope
    David Barry Como determino o tamanho total de um diretório (pasta) na linha de comando? 2010-08-06 10:20:23 +0800 CST
  • Martin Hope
    jfoucher "Os seguintes pacotes foram retidos:" Por que e como resolvo isso? 2010-08-01 13:59:22 +0800 CST
  • Martin Hope
    David Ashford Como os PPAs podem ser removidos? 2010-07-30 01:09:42 +0800 CST

Hot tag

10.10 10.04 gnome networking server command-line package-management software-recommendation sound xorg

Explore

  • Início
  • Perguntas
    • Recentes
    • Highest score
  • tag
  • help

Footer

AskOverflow.Dev

About Us

  • About Us
  • Contact Us

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve