
Getty Images/iStockphoto
26 essential Linux storage commands for management
Monitor, manage and secure storage capacity across your Linux servers, devices and dev workstations. These commands aid management of file sizes, partitions and file systems.
Managing storage space on Linux devices can be challenging. Linux storage commands, though, help monitor and manage this space and make the sys admin job easier.
Use the following commands on Linux servers and workstations to make sure you provide users with efficient and available drive space. Note that many commands display several types of information that can span categories.
Managing file sizes
Managing Linux storage capacity includes understanding file and directory sizes. Use the following commands to display this information.
1. ls -sh
Displays directory contents with size information in a human-readable format.
2. ls -lh
Displays directory contents in long format, including size, in a readable format.
3. find . -size +1G
Finds files larger than 1 GB in the current directory. Adjust this using M for megabytes. Replace the +1G with -1G for files smaller than 1 GB. Note that the find command has many useful variations for finding files based on size.
Managing utilization
Display overall capacity consumption and available space on a given file system by using the following Linux storage commands.
4. du -h /home
Displays disk utilization information for the specified directory -- the /home directory, in this case. The -h option displays the output in helpful size increments, such as megabytes. Use the -s option to summarize the directory's total size.
5. df -h
Displays disk file system utilization on your Linux device. As with other commands, the -h option displays the output in a user-friendly format.
The difference between du and df boils down to this: Use du for file and directory information, and df for broader file system data.
Managing devices
Understand storage device capabilities by using these commands.
6. blkid
Displays detailed data about available block devices, including Universally Unique Identifier, file system type and label.
7. lsblk
Displays information about available block devices, such as SSDs, HDDs and USB storage. The output includes details like device name, size, type and mount points.
8. hdparm
Displays and configures hardware parameters for HDDs and SSDs. Results include read speed information. You can set power management, drive cache and other tunable parameters, assuming the disk supports them.
9. smartctl
Manages and monitors self-monitoring, analysis and reporting technology, or SMART, storage devices. Displays health, attributes and errors for supported devices.
10. lshw -class disk
Displays detailed storage device attributes, including model, vendor, size and capabilities. Summarize data with the -short flag. Note that you can use the -class flag to display information on other devices, such as network and processor.
11. lsusb
Displays USB bus and device information, including numeric identifiers useful for troubleshooting. The command also displays vendor and model data. Add the -v, or verbose, option for more detail.
12. lsscsi
Shows SCSI device details, including addresses, types and nodes.
Managing partitions
The Linux /proc directory provides real-time information about the kernel, hardware and processes. Several files within this virtual file system contain information about storage devices.
13. cat /proc/partitions
Displays disk partitions.
14. cat /proc/devices
Displays storage devices.
15. cat /proc/diskstats
Displays I/O statistics for devices.
16. partprobe
Causes the system to reread disk partition tables to discover changes, such as new or removed partitions. Run this command after modifying partitions to make sure the system has current information.
17. fdisk -l
Uses fdisk to retrieve and display partition information, including names, sizes and types. Use this command if you have installed fdisk on your system and have Master Boot Record (MBR) partitions.
18. parted -l
Uses parted to retrieve and display partition information, including GUID Partition Table (GPT) and MBR configurations. Use this command if you have installed parted on your system and have GPT volumes.
Managing file systems
Display and manipulate file systems on storage devices using these Linux storage commands.
19. mkfs.xfs /dev/sda1
Adds the XFS file system to storage partition /dev/sda1. You can also use the syntax mkfs -t xfs /dev/sda1 for the same configuration. The other common variation would be specifying the ext4 file system instead of xfs.
20. mount /dev/sda1 /projects
Attaches a file system at /dev/sda1 to a mount point, or directory, at /projects, making the storage capacity available.
21. umount /dev/sda1
Detaches the file system, making the capacity unavailable.
22. cat /proc/mounts
Displays mounted file systems.
23. dd if=/dev/sda1 of=/dev/sdb1
Copies and converts data between the /dev/sda1 and /dev/sdb1 partitions. The if parameter indicates the source, while the of parameter is the destination. Add the status=progress option to display progress information.
Be aware that another dd capability is deleting the file system, which can be useful for disk sanitization.
24. shred -vfz -n 5 /dev/sda1
Overwrites the /dev/sda1 partition with five passes, with the final pass being zeros. The -v option provides a progress meter.
Think carefully before using this command, or you might lose data.
25. shred -uvz -n 5 fileA.txt
Overwrites fileA.txt with five passes, with the final pass being zeros. The -u option deletes the file once the overwrites are complete.
26. fsck -y -C /dev/sda1
Checks the file system at /dev/sda1 for errors during troubleshooting or monitoring.
Good practices for Linux storage commands
Many other useful storage-oriented Linux commands exist, especially around file management. Various tools enable compression, archiving, efficient file centralization on remote servers and integrity checking.
Don't forget to compare the XFS and ext4 file systems and how they handle large files, as one might have more efficient storage utilization over the other.
Begin using these Linux storage commands to determine how your organization is using its capacity and where you can make it more efficient.
Damon Garn owns Cogspinner Coaction and provides freelance IT writing and editing services. He has written multiple CompTIA study guides, including the Linux+, Cloud Essentials+ and Server+ guides, and contributes extensively to Informa TechTarget, The New Stack and CompTIA Blogs.