Number of files in the Linux statistics directory __linux

Source: Internet
Author: User
How to query the number of files under Linux.

I'm going to ftp all the files from a directory in Linux to a Windows machine, and I want to know if the download is complete, I have to compare the size of the folder and the total number of files under the folder, what commands to use under Linux.

File size can be
Du-sh/var
Like this, the number of files

View the number of files under a folder (number of files in the current directory)
Ls-l |grep "^-" | Wc-l

Ls-l
Long list output file information in this directory (note the file here, different from the general file, may be directories, links, device files, etc.)
grep ^-
Here the long list output information filter part, only the general file, if only keep the directory is
^d


Wc-l
Statistics output The number of rows, because has been filtered only general file, so the statistical result is the number of general file information, and because a line of information corresponding to a file, so that is the number of files.

View the number of files under a folder (the number of files and subfolders in the current directory)
Find./-type F | Wc-l
Or
Ls-lr|grep "^-" |wc-l


View the number of files in the current directory under Linux


Ls-l | grep "^-" | Wc-l
View the number of files in the current directory, including subdirectories.

ls-lr| grep "^-" | Wc-l
View the number of folders (directories) in a directory, including those in subdirectories.

ls-lr| grep "^d" | Wc-l
Brief description:


Ls-l
Long list output file information in this directory (note the file here, different from the general file, may be directories, links, device files, etc.)
grep "^-"
Here the long list output information filter part, only the general file, if only keep the directory is
^d


Wc-l
Statistics output The number of rows, because has been filtered only general file, so the statistical result is the number of general file information line, and because a line of information corresponding to a file, so that is the number of files

How to view the number of files open in Linux systems


Article reprinted from the Home network:
Http://www.bitscn.com/os/linux/200804/137662.html

Ulimit-n 4096
That is, limit the maximum number of file open to 4,096 users


There are two general statements about how to view the number of open files on the Internet.
/proc/sys/fs/file-nr
This file is associated with File-max, which has three values:
Number of allocated file handles
Number of used file handles
Maximum number of file handles
The file is read-only and is used only for display information.
To view the number of file open for all processes
Lsof |wc-l
To view the number of files opened by a process
Lsof-p PID |wc-l

UNIX file size, number of file rows

#文件行数

File_count= ' Wc-l/odsstatfs/groupfile/${file_name} | awk ' {print '} '
echo "Number of file rows: ${file_count}"
#文件大小
File_size= ' Ls-l/odsstatfs/groupfile/${file_name} | awk ' {print $} '
echo "File size: ${file_size}"


There are five ways to sum up:

Now there's a file, a total of 55 lines
First type:
# awk ' {print NR} ' a|tail-n1
55


The second type:
This is BEGINCWCW brother:
# awk ' End{print NR} ' a
55

The third type:
# grep-n "" A|awk-f: ' {print '}|tail-n1
55

The fourth kind:
Brother Honbj is also good:
# sed-n ' $= ' a
55

Fifth Kind
# wc-l A|awk ' {print} '
55


Sixth kind
#cat a |wc-l
55


File Content Statistics Command: WC

Http://www.fanqiang.com (2001-05-08-14:24:15)

Wc
The function of the command is to count the number of bytes, words, and rows in the specified file and display the results to the output.
Syntax: WC [options] file?
Description: This command counts the number of bytes, words, and lines in a given file. If no file name is given, read from standard input.
Wc
Also gives the president count of all specified documents. A word is the largest string that is separated by a space character area.
The options for this command have the following meanings:
-C
Statistics the number of bytes.
-L
Statistics the number of rows.
+ 1
Count the number of words.


These options can be used in combination.
The order and number of output columns are not affected by the order and number of options. Always appear in the following order and each item is at most one column.



Number of lines, words, bytes, file names if there is no file name in the command line, the file name does not appear in the output.

For example:
$ WC-LCW file1 file2
4 file1
7 File2
Total


Omit option-LCW,WC command has the same execution result as above.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.