How to List All Connected Hard Drives on Terminal in Ubuntu
This is an article about how to list all connected hard drives and storage devices on the terminal using Ubuntu. In this comprehensive guide, we cover various commands and tools you can use to easily detect and manage your system’s connected storage hardware from within the command line interface (CLI). Read this article to find out about the different methods and utilities available in Linux for identifying disk partitions, sizes, types, and more.
Introduction
Linux offers a plethora of powerful commands that make it easy to interact with hardware components directly from the terminal. Knowing how to list all connected hard drives is essential for system administrators, developers, and hobbyists alike who prefer to work with command-line interfaces rather than graphical user interfaces (GUIs). This article will walk you through several methods to discover and manage your storage devices under Ubuntu.
Command Line Tools
Ubuntu relies heavily on the Linux kernel and a suite of tools to facilitate interaction with hardware. For listing hard drives, there are multiple commands available including lsblk, fdisk, parted, hdparm, and more specialized ones like lsusb for USB devices. In this section, we will focus primarily on lsblk, fdisk, and parted due to their versatility and ease of use.
Using lsblk
The lsblk command is a straightforward tool that provides detailed information about all block devices connected to your system including hard drives and solid-state drives (SSD). It supports multiple output formats and can display device hierarchy, UUIDs, labels, and more.
Syntax:
Common Options:
- -o: Customize the column format. Use NAME, MAJ:MIN, RM, SIZE, RO, TYPE, MOUNTPOINT for typical output.
- -d: Shows only devices (no slaves).
- -f: Shows filesystem information.
Example Usage:
Using fdisk
The fdisk command is used to partition hard disks. It can also be used to list all disk partitions which includes connected hard drives among other storage devices.
Syntax:
This will output a detailed listing of your disk partitions including device identifiers, cylinder information, and partition details like start, end, sectors, size, type, and file system type (if applicable).
Using parted
The parted command is another powerful utility similar to fdisk. It can be used for creating, deleting, or resizing partitions on a disk. Additionally, it provides detailed information about all connected hard drives.
Syntax:
This command lists all the disks and their respective partitions in detail. You’ll get information such as:
- Disk Name (e.g., /dev/sda).
- Size.
- Logical Sector size.
- Partition Table type (like msdos or gpt).
- Partition Information including number, start, end, file system type.
Using Udisks2
For a higher level of abstraction and user-friendly output, you can use the udisksctl tool provided by udisks2. This utility is often used for controlling disk-based storage devices in modern Linux distributions like Ubuntu.
Syntax:
This command will display a concise list of all block devices connected to your system, including USB drives and internal hard disks.
Using lsusb
Although lsusb is primarily used for listing USB devices, it can be helpful when identifying external hard drives or other storage devices that are connected via the USB interface.
Syntax:
This command will provide a list of all USB buses and their associated device descriptors. While not specifically about block devices, lsusb provides useful identification information for removable media like USB flash drives.
Interpreting Output
When listing hard drives using the above commands, you might encounter various types of output depending on which tool you’re using:
- With lsblk, each line represents a device. The NAME column indicates the device name (e.g., /dev/sda), SIZE shows its capacity in bytes or a human-readable format if -b is not used, TYPE specifies whether it’s a disk, partition, loopback mount, etc., and MOUNTPOINT tells you where on your filesystem each device is mounted.
- fdisk -l produces a detailed report for every block device. It starts with the name of the disk followed by its size, unit information, and then lists out partitions in detail.
- parted -l provides an overview of disks along with their partition tables including start and end sectors, file system type, flags (e.g., boot), etc.
Understanding this output is crucial for managing your storage devices effectively without a GUI. You can use it to check if new drives are being recognized, inspect disk usage across multiple partitions, or troubleshoot issues related to missing or improperly mounted disks.
Conclusion
In summary, listing connected hard drives on Ubuntu through the terminal involves utilizing specific Linux commands such as lsblk, fdisk, and parted. Each command provides unique insights into your system’s storage configuration, allowing you to manage your hardware efficiently from the command line. Whether you’re checking disk information for maintenance purposes or troubleshooting issues with your file systems, these tools are indispensable.
By mastering these commands and understanding their outputs, you can become more proficient in Linux administration tasks related to managing storage devices without relying on graphical interfaces. Experimenting with different options within these commands will further enhance your ability to diagnose and manage hardware connected to your Ubuntu system effectively.
Last Modified: 22/03/2018 - 03:35:44