disk commands in linux shell

Here is the list of hard disk and file system commands in Linux.

mount and unmount command

mount command is used to mount the file system in Linux. For example if you want to access the files from USB drive, you will have to first mount the file system from USB drive in the Linux System. Below example shows how to mount a file system on specific directory.
$ mount <file-system> <mount-directory>

You can also modify “/etc/fstab” file to mount the file system. “fstab” stands for file system table. This file contains entries for all mounted file systems.

df command

“df” command stands for disk free. As the name indicates, it displays how much space is used by specific file system. It also shows how much space is available on specific file system. To display the size in human readable format (MG,GB,TB etc), you can use below command.
df -h

du command

“du” stands for disk usage. This command is used to display the space occupied by specific file or a directory. For example – below command will display the space occupied by /etc directory and all files and sub-directories in it. “-h” will display the usage in human readable format (MB, GB,TB etc) and “-c” will display the total usage in the end.
du -hc /etc

Finding the size of each directory as well as file
$ du -ah

Finding the size of entire directory
$ du -sh

Finding the size of all files and directories in only current directory
$ du -ah -maxd 1

free command

free command is used to show the details of RAM in Linux. By default RAM is displayed in KB. But you can use below commands to show the RAM in MB, GB, TB etc.
free -m
free -g
free -t

quota command in Linux

quota command is used to manage the disk quota of an user or group. Assume that you set up 15 GB as hard limit quota and 14 GB as soft limit quota with grace period as 10.
  • Hard limit – With 15 GB as hard limit quota, user will not be allowed to store any more files after 15 GB space is used.
  • Soft limit – With 14 GB as soft limit quota, user will be given warning messages after disk usage exceeds 14 GB
  • Grace period – Grace period allows you to store files even though you have crossed hard limit.

Getting disk information of the system

You can use lshw command to get disk information. As you can see there are 2 types of disks attached to the system – /dev/cdrom (DVD reader) and /dev/sda (ATA Disk)You can use lsblk command to display the block devices and mount points. You can use fdisk command to manage the partitions of specific disk.

Web development and Automation testing

solutions delivered!!