Home>Article>Operation and Maintenance> How to check if a folder is empty in linux

How to check if a folder is empty in linux

WBOY
WBOY Original
2022-01-04 10:59:14 7467browse

In Linux, you can use the du command to check whether the folder is empty. This command is used to display the disk space occupied by the specified directory or file. When the parameter is set to "-s", the file can be displayed. The total size of the folder, the syntax is "du -s folder".

How to check if a folder is empty in linux

#The operating environment of this tutorial: linux7.3 system, Dell G3 computer.

How to check whether a folder is empty in Linux

Linux du (full English spelling: disk usage) command is used to display the directory or file size.

du will display the disk space occupied by the specified directory or file.

Syntax

du [-abcDhHklmsSx][-L <符号连接>][-X <文件>][--block-size][--exclude=<目录或文件>][--max-depth=<目录层数>][--help][--version][目录或文件]

Parameter description:

  • -a or -all displays the size of individual files in the directory.

  • -b or -bytes When displaying the size of a directory or file, the unit is byte.

  • -c or --total In addition to displaying the size of individual directories or files, it also displays the sum of all directories or files.

  • -D or --dereference-args displays the source file size of the specified symbolic link.

  • -h or --human-readable in K, M, G units to improve the readability of information.

  • -H or --si is the same as the -h parameter, but K, M, and G are converted in units of 1000.

  • -k or --kilobytes in 1024 bytes.

  • -l or --count-links Repeat counting of files for hardware links.

  • -L or --dereference Displays the source file size of the symbolic link specified in the option.

  • -m or --megabytes in 1MB units.

  • -s or --summarize displays only the total.

  • -S or --separate-dirs When displaying the size of an individual directory, the size of its subdirectories is not included.

  • -x or --one-file-xystem The file system used at the beginning of processing shall prevail. If other different file system directories are encountered, they will be ignored.

  • -X or --exclude-from= Specifies a directory or file in .

  • --exclude= Ignore the specified directory or file.

  • --max-depth= Directories exceeding the specified level will be ignored.

  • --help Display help.

  • --version Display version information.

Example

Display the space occupied by a directory or file:

How to check if a folder is empty in linux

Related recommendations:《Linux Video tutorial

The above is the detailed content of How to check if a folder is empty in linux. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn