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".
#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
-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
--exclude=
--max-depth=
--help Display help.
--version Display version information.
Example
Display the space occupied by a directory or file:
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!