Combine fdisk e df na mesma saída

4

sudo fdisk -l dá:

255 heads, 63 sectors/track, 60801 cylinders, total 976773168 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: 0xdb20e840

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048   104859647    52428800    7  HPFS/NTFS/exFAT
/dev/sda2       104859648   310630399   102885376    7  HPFS/NTFS/exFAT
/dev/sda3       310632840   372065399    30716280   83  Linux
/dev/sda4       372072446   838281215   233104385    5  Extended
/dev/sda5       372072448   392552447    10240000   83  Linux
/dev/sda6       392554496   453994495    30720000   83  Linux
/dev/sda7       453996544   515436543    30720000   83  Linux
/dev/sda8       515438592   515456169        8789   82  Linux swap / Solaris
/dev/sda9       515457024   552321023    18432000   83  Linux
/dev/sda10      552323072   585091071    16384000   83  Linux
/dev/sda11      585093120   617861119    16384000   83  Linux
/dev/sda12      617876028   822656519   102390246    7  HPFS/NTFS/exFAT
/dev/sda13      822657024   838281215     7812096   82  Linux swap / Solaris

Enquanto df -h der:

Filesystem      Size  Used Avail Use% Mounted on
/cow            1.9G   30M  1.9G   2% /
udev            1.9G  4.0K  1.9G   1% /dev
tmpfs           385M  1.1M  384M   1% /run
/dev/sr0        913M  913M     0 100% /cdrom
/dev/loop0      874M  874M     0 100% /rofs
none            4.0K     0  4.0K   0% /sys/fs/cgroup
tmpfs           1.9G  8.0K  1.9G   1% /tmp
none            5.0M     0  5.0M   0% /run/lock
none            1.9G   80K  1.9G   1% /run/shm
none            100M   24K  100M   1% /run/user
/dev/sda9        18G  1.2G   16G   8% /media/xubuntu/b90d1c45-7805-421b-9ba7-88ab7ed04fd3
/dev/sda7        29G  4.2G   24G  16% /media/xubuntu/964f9a2f-3641-4754-8319-1decea626931
/dev/sda6        29G   20G  7.8G  72% /media/xubuntu/4f6e6be0-a703-4cb6-a425-9ae73f31eb82
/dev/sda5       9.5G   22M  9.0G   1% /media/xubuntu/3c662996-cf77-41a3-9b5d-d7520f8d534a
/dev/sda3        29G  3.4G   24G  13% /media/xubuntu/57f03636-d50f-43fe-97c0-192b761d7054
/dev/sda12       98G   18G   81G  19% /media/xubuntu/5943EBDD309DF483
/dev/sda11       16G  935M   14G   7% /media/xubuntu/a2176105-4afc-4f19-b182-c027925e249e
/dev/sda10       16G   40M   15G   1% /media/xubuntu/4397bd85-5172-4dc4-a4ce-e9690d3ac7f9
/dev/sda1        50G   32G   19G  64% /media/xubuntu/OSDisk

Como posso combinar esses dois resultados usando awk ou outra coisa para ter no mesmo comando que resulta na saída a seguir.

**Device  -  System_Type  -  Size   -  Use%    -    Mount_Point**
    
por Nadina 28.05.2014 / 19:27

4 respostas

7

por que você não pode tentar df -hT ?

Resultado

-bash-3.2$ df -hT
Filesystem    Type    Size  Used Avail Use% Mounted on
/dev/sda2     ext3     48G   17G   29G  37% /
/dev/sda5     ext3    238G   66G  160G  30% /home
/dev/sda1     ext3     99M   17M   77M  18% /boot
tmpfs        tmpfs    2.0G     0  2.0G   0% /dev/shm

O tipo especifica o tipo de sistema e a única exceção é que isso mostrará apenas os sistemas de arquivos montados, em oposição a fdisk -l , que mostra todas as partições disponíveis, independentemente de estarem montadas ou não.

    
por 28.05.2014 / 19:35
2

De man mount :

For more robust and definable output use findmnt...

findmnt --help
...
-D - imitate the behavior of df
...
Available Columns:
      SOURCE  source device
      TARGET  mountpoint
      FSTYPE  filesystem type
     OPTIONS  all mount options
 VFS-OPTIONS  VFS specific mount options
  FS-OPTIONS  FS specific mount options
       LABEL  filesystem label
        UUID  filesystem UUID
   PARTLABEL  partition label
    PARTUUID  partition UUID
     MAJ:MIN  major:minor device number
      ACTION  action detected by --poll
  OLD-TARGET  old mountpoint saved by --poll
 OLD-OPTIONS  old mount options saved by --poll
        SIZE  filesystem size
       AVAIL  filesystem size available
        USED  filesystem size used
        USE%  filesystem use percentage
      FSROOT  filesystem root
         TID  task ID
          ID  mount ID
  OPT-FIELDS  optional mount fields
 PROPAGATION  VFS propagation flags
        FREQ  dump(8) period in days [fstab only]
      PASSNO  pass number on parallel fsck(8) [fstab only]

...

findmnt -D

SOURCE                  FSTYPE           SIZE   USED AVAIL USE% TARGET
devtmpfs                devtmpfs        11.8G      0 11.8G   0% /dev
tmpfs                   tmpfs           11.8G  95.1M 11.7G   1% /dev/shm
tmpfs                   tmpfs           11.8G   928K 11.8G   0% /run
tmpfs                   tmpfs           11.8G      0 11.8G   0% /sys/fs/cgroup
/dev/sda2[/manjaro]     btrfs             12G   7.8G  3.8G  65% /
tmpfs                   tmpfs           11.8G 758.2M   11G   6% /tmp
/dev/sda1               vfat               3G   588M  2.4G  19% /esp
/dev/sda1[/EFI/manjaro] vfat               3G   588M  2.4G  19% /boot
tmpfs                   tmpfs            2.4G     8K  2.4G   0% /run/user/1000
gvfsd-fuse              fuse.gvfsd-fuse     0      0     0    - /run/user/1000/gvfs
    
por 28.05.2014 / 21:49
2

Aqui está uma versão modificada da resposta de Ramesh que lhe dá as colunas que você precisa apenas dos sistemas de arquivos importantes (não udev , tmpfs ).

disks=$(sudo fdisk -l | grep -Po "/dev/sd.\d+")
for i in $disks; do df -Th $i | tail -n 1; done
    
por 29.05.2014 / 20:57
-1

Isso pode ser simples, mas você pode usar apenas & &:

sudo fdisk -l && df -h

Mas o cfdisk pode fazer o que você deseja:

cfdisk -P s

Partition Table for /dev/sda

           First       Last
# Type       Sector      Sector   Offset    Length   Filesystem Type (ID) Flag
-- ------- ----------- ----------- ------ ----------- -------------------- ----
 Pri/Log           0        2047*     0#       2048*Free Space           None
 1 Primary        2048*    1026047*     0     1024000*Linux (83)           Boot
 2 Primary     1026048*    3074047*     0     2048000*Linux swap / So (82) None
 3 Primary     3074048*   41943039*     0    38868992*Linux LVM (8E)       None
    
por 29.05.2014 / 11:24