确定Linux中的可用文件空间

道歉,如果这是一个愚蠢的问题,但我还没有find答案呢。

如何找出给定文件夹或分区有多less空闲磁盘/文件空间?

基本上我需要知道在服务器上执行任务之前有多less可用空间,并且不希望意外达到极限。

提前致谢。

df -h # shows free disk space on all partitions du -hs foldername # shows space used by a particular folder 

混沌回答第一,但我只是想添加“df -h”更有用(显示在人类可读的术语(MB,GB,KB等),而不是块),但你可以从df的帮助页面。

  cd /path/to/dir df -h . Filesystem Size Used Avail Use% Mounted on /dev/sda1 36G 20G 14G 60% / 

我最喜欢的技巧是列出真正的大文件:

 du | sort -rn | head 

获得排名前10的文件夹。

蒂姆

稍微超出问题的范围,但是因为“df”和“du”已经被很好地涵盖了……如果你发现两者不匹配,使用命令“lsof + L1”列出删除,但仍然打开文件。

如果删除的文件仍处于打开状态直到closures,则不会释放您的磁盘空间(如果日志旋转设置不当,可能会看到这一点)。

你想要df 。 (对于inode, df -i是免费的。)

我知道这是标签的Linux,但为了完整的利益..

-h选项并不总是可用的。 我知道Solaris等没有他们的工具(du,df,ls等)。

被引用的手册页显示了它,而rkthkr的答案使用它,但是不是很明显:如果你在df命令行末尾指定了一个path名,它将显示限制在只包含该path的文件系统中。

如果您想修剪标题行,然后通过tail -1pipe道,并抓住自由空间列,通过awk '{print $4}' (或cutselect适当的字段或列)pipe道。

正如其他人所build议的,使用df来pipe理本地安装的磁盘。

对于NFS和其他远程安装的卷,您可能会遇到配额系统。 对于这些系统,请使用“配额”命令查找剩余空闲配额的数量,这可能会比剩余的字节数less。 虽然这并不总是如此。

您可以在这里find更多关于配额的信息: http : //www.tldp.org/HOWTO/Quota.html

df – 报告文件系统磁盘空间使用情况( 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 (eg, 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 – 估计文件空间使用情况( 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 (eg, 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' 

上面的好答案。

我想补充的一件事是, df- hP给你输出更容易parsing。 (P代表便携性)

就我而言,'lsof + L1'就是答案。 一堆apache日志,删除但不是