Usage of ls
ls -l |grep "^-"|wc -l or find ./company -type f | wc -l View the number of files in a folder, including those in subfolders.
ls -lR|grep "^-"|wc -l View the number of folders in a folder, including those in subfolders.
ls -lR|grep "^d"|wc -l
Description: ls -l long list output file information in this directory (note that the files here are different from ordinary files, they may be directories, links, device files, etc.)
grep "^-" here will filter a part of the long list output information, only keep general files, if only keep the directory, it is ^d
wc -l counts the number of lines of output information, because it has been filtered so that only general files are left, the statistical result is the number of lines of general file information, and since one line of information corresponds to one file, it is the number of files.
du
The du command is used to view the amount of disk space occupied by a directory or file. The commonly used option combination is: du -sh
Common options for du:
-h: display in a human-readable way
-a: Display the disk space occupied by the directory, and also display the disk space occupied by the directories and files under it
-s: Display the disk space occupied by the directory, do not display the disk space occupied by the subdirectories and files under it
-c: Display the disk space occupied by several directories or files, and count the sum of them
--apparent-size: display the size of the directory or file itself
-l: Count the size of disk space occupied by hard links
-L: Count the amount of disk space occupied by the file pointed to by the symbolic link
du -sh: View the total capacity of the current directory. Instead of separately listing the capacity occupied by each sub-item
du -lh --max-depth=1: View the disk capacity occupied by sub-files and sub-directories under the current directory.
du -sh * | sort -n Count the size of the current folder (directory) and sort by file size
du -sk filename View the specified file size