Original address: http://blog.sina.com.cn/s/blog_56d8ea9001018w60.html Thanks to the author!
ls -l |grep "^-"|wc -l
or
find ./company -type f | wc -l
View the number of files in a folder, including subfolders.
ls -lR|grep "^-"|wc -l
View the number of folders in a folder, including subfolders.
ls -lR|grep "^d"|wc -l
illustrate:
ls -l
The long list outputs the file information in the directory (note that the files here are different from ordinary files, which may be directories, links, device files, etc.)
grep "^-"
Here, part of the output information of the long list is filtered, and only general files are retained. If only the directory is retained, it is ^d
wc -l
Count the number of lines of output information, because only general files have been filtered, so the statistical result is the number of lines of general file information.
One line of information corresponds to one file, so it is the number of files.
Linux check folder size
du -sh View the current folder size
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