Linux Learning Notes: view the file size, number of files

Files, folders, the number of statistics

Linux, or can find -type f ls -l file to count the number of folders, as follows.

  • View a folder under the file number:
ls -l | grep "^-" | wc -l
# ls -l 列出文件及文件夹
# "^-" 以-开头的行 文件以-开头 文件夹以d开头
# wc -l 统计行数

Or you can:

find ./ -type f | wc -l
# ./ 在当前目录查找
# -type f 文件类型
# wc -l 统计行数
  • View a folder under the file number, including sub-folders:
ls -lR | grep "^-" | wc -l
# -R 递归列出子目录的文件
  • View a folder number folder, including sub-folders:
ls -lR | grep "^d" | wc -l
# "^d" 以d开头的行

File, folder size statistics

Use du, df, free statistics, detailed below.

du 详解

Linux du command displays the size of the directory or file.

du will display the specified directories or files take up more disk space.

grammar:

du [-abcDhHklmsSx] [目录或文件]

Parameter Description:

  • -a or -all: display size of files in a directory, in KB
  • -b: display the file directory size, in bytes byte units
  • -c: display size of the files in a directory, and displays the sum, in KB
  • -k: display size of files in a directory, in KB
  • -m: display size of the files in a directory, in MB
  • -s: show only the total value of the directory, in KB
  • -h: - human-readable to K, M, G as a unit, to improve the readability of information.
  • -x: the file system at the beginning of treatment, whichever, if met other different file system directory is skipped.
  • -H: - si -h and the same parameters, but K, M, G is the conversion unit 1000 to
  • --max-depth = 1: Depth traversal

Example:

du -h * # 显示当前目录下文件的大小
du -sh # 查看当前文件夹大小
du -sh * | sort -nr # 统计当前文件夹(目录)大小,并按文件大小排序 -- 加了-h之后排序有问题
du -sk filename # 查看指定文件大小

Use the sort of argument -nr said to be a digital sort Reverse sort, because we want to do sort of directory size, so can not use human-readable output size, or the size of the directory will be K, M and so forth, will resulting in incorrect ordering.

If there is a process to open a large file, the large file directly rm or mv off, the updated statistic du, df will not update the statistics values, or that space is not released. Until this process of opening a large file is Kill off.

Detailed df

Linux df command displays the disk space that can be used on disk partitions.

  • df can see a folder size, the proportion of use, file system and its hanging point, but the file can not do anything.
  • du can view the file and folder size.

Combination of the two to use, very effective.

For example, to view a directory with df which is too large, then du viewing a folder or file size, so you can quickly identify the crux.

grammar:

df [选项] [file]

Parameter Description:

  • -a: --all include all file systems with 0 Blocks the default unit KB
  • -h: -h option to be displayed in KB, MB, GB units, high readability ~~~ (most common)
  • -i: see the current situation using the file system inode

Sometimes though there are file system space, but if there is not enough information to hold the inode file, they would not add new files.

The so-called inode is used to store basic information about files and directories (metadata), including the time, file name, such as users and groups. When splitting the sector, the system will first make a pile for later use inode, inode number of files and the relationship between the total number of directory system that can be established. If you want to save the file most are small, the same size hard drive will have more files, that is to say more needs to hang inode files and directories.

Example:

df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda1             3.9G  300M  3.4G   8% /
/dev/sda7             100G  188M   95G   1% /data0
/dev/sdb1             133G   80G   47G  64% /data1
/dev/sda6             7.8G  218M  7.2G   3% /var
/dev/sda5             7.8G  166M  7.2G   3% /tmp
/dev/sda3             9.7G  2.5G  6.8G  27% /usr
tmpfs                 2.0G     0  2.0G   0% /dev/shm
  • Filesystem - File System
  • Mounted on - hanging point
  • size - partition size
  • Used - size has been used
  • Avail - the remaining size
  • Use% - The percentage of use

Under FreeBSD, when the hard disk is full, you may see the percentage that has been used more than 100% because FreeBSD will leave some space for root, so that when the root file system is full, or you can write something to the file system to management.

free Detailed

Free Linux command to display the free Linux system, physical memory and memory interaction zone has been used (the swap), and is used by the kernel buffer (kernel buffer memory). Shared memory is ignored.

grammar:

free [参数]
             total       used       free     shared    buffers     cached
Mem:      32948032   32767416     180616          0     139960   29878896
-/+ buffers/cache:    2748560   30199472
Swap:      8193140     664956    7528184

Parameter Description:

  • -b: Byte units to display memory usage
  • -k: in KB display memory usage
  • -m: in MB display memory usage
  • -g: in GB display memory usage
  • -t: display integrated ranked memory

: Reference link method linux view the folder size, the number of files

Reference Links 2: Linux's ls -l | grep "^ -" | wc -l command

Reference links 3: Linux in du (Detailed), df (Detailed) and free (Detailed) as well as their differences

Guess you like

Origin www.cnblogs.com/hider/p/12098157.html