Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How to check if a disk is in use? If in use, How to check free, used space before I can start using it?

I'm trying this in Perl and Any help is appreciated.

share|improve this question
What do you mean by "a disk in use"? Are you looking for open files? Or the disk being mounted somewhere? Having certain partitions? – Bram Jun 18 '12 at 19:21
@Bram - I'm looking for disk partitions whilst created as logical volumes under a volume group. – doubledecker Jun 19 '12 at 8:52
sorry but I can't make heads or tails of that statement. Do you want to know which partitions are used as "physical volumes" in a volume group? Or file systems created on a logical volume? AFAIK you can't create a partition on a logical volume and it certainly wouldn't make much sense if you could. Perhaps it helps if you edit your question explaining how you do this manually. That might make it easier for people to help you script it in any language. – Bram Jun 19 '12 at 14:58

pvdisplay will show you which disks and partitions are "in use" for volume-groups

Use lvs to get a summary of all configured LVs. LVs that are in use have normally the "ao" attribute set. LVs with just "a" are active, but not currently in use. Use blkid to see which filesystems are where. Use df -h to see the currently mounted filesystems and their human-readable sizes.

share|improve this answer

I always do lsof | grep file/filesystem to list open or "in use" files.

Human readable output of "df" might be helpful as well: df -h /mountpoint

share|improve this answer

fuser -m /path/to/mountpoint works in shell to show if a disk is use. You could do a system() call from Perl

df /path/to/mountpoint tells you about disk space

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.