Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Apologies if this a dumb question, but i have not found an answer yet.

How do you find out how much free disk/file space for a given folder or partition.

Basically i need to know how much free space there is before i carry out a tasks on the server and don't wish to hit the limits unexpectedly.

thanks in advance.

share|improve this question
1  
Not a dumb question :) –  bedwyr Jun 6 '09 at 1:21

12 Answers 12

up vote 21 down vote accepted
df -h # shows free disk space on all partitions
du -hs foldername # shows space used by a particular folder
share|improve this answer
1  
du -h was always my favorite thing to say to a coworker. –  Karl Katzke Jun 5 '09 at 19:58

in my case, 'lsof +L1' was the answer. a bunch of apache logs, deleted but not

share|improve this answer

The manual page that's quoted shows it, and rkthkr's answer uses it but it's not highly visible: if you specify a pathname at the end of the df command line, it limits its display to the filesystem containing that path only.

If you want to trim off the header line then pipe it through tail -1, and to grab just the free space column, pipe that through awk '{print $4}' (or a cut selecting the appropriate field or columns).

share|improve this answer

Great answers above.

One thing I would like to add is that df- hP give you output thats more easily parsed. (P is for portability)

share|improve this answer

A little out of the scope of the question, but as 'df' and 'du' are already well covered... if you find the two don't match, it's useful to use the command 'lsof +L1' to list deleted, but still open files.

Your diskspace will not be freed up if a deleted file is still open until it is closed (seen this a lot with improper log rotation setups).

share|improve this answer

I know this is tagged linux, but in the interest of completeness..

The -h option isn't always available. I know Solaris, etc doesn't have it on their tools (du, df, ls, etc).

share|improve this answer
    
I thought Solaris 10 was including the "good" tools with -h. Hmm. –  JR Lawhorne Jun 5 '09 at 20:57

df - report file system disk space usage (man)

df [OPTION]... [FILE]...
Description
This manual page documents the GNU version of df. df displays the amount of disk space available on the file system containing each file name argument. If no file name is given, the space available on all currently mounted file systems is shown. Disk space is shown in 1K blocks by default, unless the environment variable POSIXLY_CORRECT is set, in which case 512-byte blocks are used.

If an argument is the absolute file name of a disk device node containing a mounted file system, df shows the space available on that file system rather than on the file system containing the device node (which is always the root file system). This version of df cannot show the space available on unmounted file systems, because on most kinds of systems doing so requires very nonportable intimate knowledge of file system structures.
Options

Show information about the file system on which each FILE resides, or all file systems by default.

Mandatory arguments to long options are mandatory for short options too.

-a, --all
    include dummy file systems 
-B, --block-size=SIZE use SIZE-byte blocks
-h, --human-readable
    print sizes in human readable format (e.g., 1K 234M 2G) 
-H, --si
    likewise, but use powers of 1000 not 1024 
-i, --inodes
    list inode information instead of block usage 
-k
    like --block-size=1K 
-l, --local
    limit listing to local file systems 
--no-sync
    do not invoke sync before getting usage info (default) 
-P, --portability
    use the POSIX output format 
--sync
    invoke sync before getting usage info 
-t, --type=TYPE
    limit listing to file systems of type TYPE 
-T, --print-type
    print file system type 
-x, --exclude-type=TYPE
    limit listing to file systems not of type TYPE

du - estimate file space usage (man)

du [OPTION]... [FILE]...
du [OPTION]... --files0-from=F
Description

Summarize disk usage of each FILE, recursively for directories.

Mandatory arguments to long options are mandatory for short options too.

-a, --all
    write counts for all files, not just directories 
--apparent-size
    print apparent sizes, rather than disk usage; although the apparent size is usually smaller, it may be larger due to holes in ('sparse') files, internal fragmentation, indirect blocks, and the like 
-B, --block-size=SIZE use SIZE-byte blocks
-b, --bytes
    equivalent to '--apparent-size --block-size=1' 
-c, --total
    produce a grand total 
-D, --dereference-args
    dereference FILEs that are symbolic links 
--files0-from=F
    summarize disk usage of the NUL-terminated file names specified in file F 
-H
    like --si, but also evokes a warning; will soon change to be equivalent to --dereference-args (-D) 
-h, --human-readable
    print sizes in human readable format (e.g., 1K 234M 2G) 
--si
    like -h, but use powers of 1000 not 1024 
-k
    like --block-size=1K 
-l, --count-links
    count sizes many times if hard linked 
-m
    like --block-size=1M 
-L, --dereference
    dereference all symbolic links 
-P, --no-dereference
    don't follow any symbolic links (this is the default) 
-0, --null
    end each output line with 0 byte rather than newline 
-S, --separate-dirs
    do not include size of subdirectories 
-s, --summarize
    display only a total for each argument 
-x, --one-file-system
    skip directories on different file systems 
-X FILE, --exclude-from=FILE
    Exclude files that match any pattern in FILE. 
--exclude=PATTERN Exclude files that match PATTERN.
--max-depth=N
    print the total for a directory (or file, with --all) only if it is N or fewer levels below the command line argument; --max-depth=0 is the same as --summarize 
--time
    show time of the last modification of any file in the directory, or any of its subdirectories 
--time=WORD
    show time as WORD instead of modification time: atime, access, use, ctime or status 
--time-style=STYLE show times using style STYLE:
    full-iso, long-iso, iso, +FORMAT FORMAT is interpreted like 'date'
share|improve this answer

As others suggested, use df for locally mounted disks that you're managing.

For NFS and other remote mounted volumes, you may encounter a quota system. For these systems, use the "quota" command to find out how much free quota remains, which will likely be smaller than the number of bytes remaining. This is not always true, though.

You can find more about quota here: http://www.tldp.org/HOWTO/Quota.html

share|improve this answer

my favorite trick for getting the really big files listed:

du | sort -rn | head

gets the top 10 filepigs listed.

Tim

share|improve this answer
    
This is very useful. Thanks! –  jpartogi Oct 18 '10 at 23:16
   cd /path/to/dir
   df -h .
   Filesystem            Size  Used Avail Use% Mounted on
   /dev/sda1              36G   20G   14G  60% /
share|improve this answer
    
you mean du -h . df -h as chaos said shows free disk on all partitions and it doesn't care about your PWD –  Zypher Jun 6 '09 at 2:25
1  
It does, if you make a simple df -h it will show all filesystems mounted, if you give it a path it will only show the free space for the filesystem mounted there.. –  rkthkr Jun 9 '09 at 9:01

chaos answered first, but I just wanted to add "df -h" is more useful (display it in human-readable terms (MB, GB, KB, etc) instead of blocks), but you can figure that out from df's help page.

share|improve this answer

You want df. (And df -i for inodes free.)

share|improve this answer

Your Answer

 
discard

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.