
On Linux systems, devices are represented in the file system by files that are generally listed in the /dev directory. These device files serve as interfaces to devices which may be disks, serial devices and such. Examples include /dev/tty, /dev/console, etc. You can list device files with a command like that shown below. Just be ready to see a couple hundred lines of output!
$ ls -l /dev
total 0
crw-r--r--. 1 root root 10, 235 May 10 10:08 autofs
drwxr-xr-x. 2 root root 140 May 10 10:08 block
drwxr-xr-x. 2 root root 60 May 10 10:08 bsg
crw-rw----. 1 root disk 10, 234 May 10 10:08 btrfs-control
drwxr-xr-x. 3 root root 60 May 10 10:08 bus
drwxr-xr-x. 2 root root 3960 May 10 10:09 char
crw--w----. 1 root tty 5, 1 May 10 10:08 console
lrwxrwxrwx. 1 root root 11 May 10 10:08 core -> /proc/kcore
drwxr-xr-x. 4 root root 80 May 10 10:08 cpu
crw-------. 1 root root 10, 124 May 10 10:08 cpu_dma_latency
crw-------. 1 root root 10, 123 May 10 10:08 cros_ec
crw-------. 1 root root 10, 203 May 10 10:08 cuse
drwxr-xr-x. 9 root root 180 May 10 10:08 disk
…
brw-rw----. 1 root disk 252, 0 May 10 10:08 zram0
Devices can be character devices (like keyboards and serial ports), block devices (such as hard disks and USB devices), network devices (e.g., eth0) and virtual devices (like /dev/null).
When you list device files, the first character in each line can identify the device type. For example, device files starting with “c” are character devices while those starting with “b” are block devices.
The lsblk command is used to list all block devices that are connected to your system. It provided detailed information including such things as the device names, sizes and mount points in a tree-like format. It can help Linux users to manage and understand their storage devices.
$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sda 8:0 0 14.9G 0 disk
├─sda1 8:1 0 600M 0 part /boot/efi
├─sda2 8:2 0 1G 0 part /boot
└─sda3 8:3 0 13.3G 0 part /home
/
zram0 252:0 0 1.7G 0 disk [SWAP]
The output above shows that the system’s disk has three partitions.
The df -h command will display mounted file systems – including tmpfs (temporary file systems) that make the listing quite long.
$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 14G 6.7G 6.2G 52% /
devtmpfs 4.0M 0 4.0M 0% /dev
tmpfs 886M 96K 886M 1% /dev/shm
efivarfs 64K 6.0K 53K 11% /sys/firmware/efi/efivars
tmpfs 355M 1.7M 353M 1% /run
tmpfs 1.0M 0 1.0M 0% /run/credentials/systemd-journald.service
tmpfs 1.0M 0 1.0M 0% /run/credentials/systemd-network-generator.service
tmpfs 1.0M 0 1.0M 0% /run/credentials/systemd-udev-load-credentials.service
tmpfs 1.0M 0 1.0M 0% /run/credentials/systemd-tmpfiles-setup-dev-early.service
tmpfs 1.0M 0 1.0M 0% /run/credentials/systemd-sysctl.service
tmpfs 1.0M 0 1.0M 0% /run/credentials/systemd-tmpfiles-setup-dev.service
tmpfs 886M 16K 886M 1% /tmp
/dev/sda3 14G 6.7G 6.2G 52% /home
/dev/sda2 974M 358M 549M 40% /boot
/dev/sda1 599M 20M 580M 4% /boot/efi
tmpfs 1.0M 0 1.0M 0% /run/credentials/systemd-tmpfiles-setup.service
tmpfs 1.0M 0 1.0M 0% /run/credentials/systemd-resolved.service
tmpfs 1.0M 0 1.0M 0% /run/credentials/systemd-vconsole-setup.service
tmpfs 178M 180K 177M 1% /run/user/1000
tmpfs 178M 76K 177M 1% /run/user/1001
You can reduce the output to a more concise listing like this (removing the tmpfs file systems):
$ df -h | grep -v tmpfs
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 14G 6.7G 6.2G 52% /
efivarfs 64K 6.0K 53K 11% /sys/firmware/efi/efivars
/dev/sda3 14G 6.7G 6.2G 52% /home
/dev/sda2 974M 358M 549M 40% /boot
/dev/sda1 599M 20M 580M 4% /boot/efi
You can have the df command supply information on one partition with a command like this:
$ df -h /home
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 14G 6.7G 6.2G 52% /home
Using the mount command without arguments will display all of the mounted file systems. To list file systems by type, you can use a command like this that lists only ext4 file systems:
$ mount -t ext4
/dev/sda2 on /boot type ext4 (rw,relatime,seclabel)
Passing the output of the mount command to the column command will provide a listing that will likely be easier to read as the output will be displayed with separated columns of data.
$ mount | column -t
The fdisk -l command will display details on file systems, but requires root access.
$ sudo fdisk -l
Disk /dev/sda: 14.91 GiB, 16013942784 bytes, 31277232 sectors
Disk model: KINGSTON SNS4151
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 9645D103-5519-4B2A-82FB-636FED806E1B
Device Start End Sectors Size Type
/dev/sda1 2048 1230847 1228800 600M EFI System
/dev/sda2 1230848 3327999 2097152 1G Linux extended boot
/dev/sda3 3328000 31277055 27949056 13.3G Linux filesystem
Disk /dev/zram0: 1.73 GiB, 1855979520 bytes, 453120 sectors
Units: sectors of 1 * 4096 = 4096 bytes
Sector size (logical/physical): 4096 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
The lspci command will display information on pci (peripheral component interconnect) devices.
$ lspci
00:00.0 Host bridge: Intel Corporation Haswell-ULT DRAM Controller (rev 09)
00:02.0 VGA compatible controller: Intel Corporation Haswell-ULT Integrated Graphics Controller (rev 09)
00:03.0 Audio device: Intel Corporation Haswell-ULT HD Audio Controller (rev 09)
00:04.0 Signal processing controller: Intel Corporation Haswell-ULT Thermal Subsystem (rev 09)
00:14.0 USB controller: Intel Corporation 8 Series USB xHCI HC (rev 04)
00:16.0 Communication controller: Intel Corporation 8 Series HECI #0 (rev 04)
00:1b.0 Audio device: Intel Corporation 8 Series HD Audio Controller (rev 04)
00:1c.0 PCI bridge: Intel Corporation 8 Series PCI Express Root Port 1 (rev e4)
00:1c.1 PCI bridge: Intel Corporation 8 Series PCI Express Root Port 2 (rev e4)
00:1f.0 ISA bridge: Intel Corporation 8 Series LPC Controller (rev 04)
00:1f.2 SATA controller: Intel Corporation 8 Series SATA Controller 1 [AHCI mode] (rev 04)
00:1f.3 SMBus: Intel Corporation 8 Series SMBus Controller (rev 04)
00:1f.6 Signal processing controller: Intel Corporation 8 Series Thermal (rev 04)
01:00.0 Network controller: Qualcomm Atheros AR9462 Wireless Network Adapter (rev 01)
Wrapping up, the list below includes a list of tasks and the commands you would use to complete them.
- List all device files: ls /dev
- Show block devices: lsblk
- Show detailed device info: lshw (may require sudo)
- List PCI devices: lspci
- List USB devices: lsusb
- List loop devices: losetup
- Show mounted filesystems: df -h
- Mount a device: mount /dev/sdX /mnt
- Format a device: mkfs.ext4 /dev/sdX
- Wipe partition table: wipefs /dev/sdX
- Check partitions: fdisk -l
Source:: Network World