The number of files with various suffix names in the statistics folder of the script series

Source: Internet
Author: User

Welcome Reprint! When reproduced, please indicate the source:http://blog.csdn.net/nfer_zhuang/article/details/42582425

Introduction

Usage scenarios:

My QQ group in the recent chat is in full swing, also led to my QQ buffer folder size in the crazy rise, when the QQ client will prompt users to clear the cache folder after 500M. The largest part of the buffer folder is a variety of picture files, including pictures in various formats. Before deleting, I want to follow the picture format and then back up to other folders. This time I need to do a statistic:

    1. Pictures with several formats (suffix names) under the current folder
    2. How many files are in each format of a picture
General Usage:
    1. Open the File Manager and go to the folder to be counted

    2. Sort By type
    3. Select all files that specify the suffix name, and in the File Manager, the status bar has a count of the number of files selected, recorded

    4. Then select all the files for the next suffix and count and record until all the statistics are complete

Sentence script usage:

Find-type f-name "* *" | cut-f3-d '. ' | Sort | Uniq-c  -I (recursively finds all subfolders under the current folder) or <pre name= "code" class= "plain" >find-maxdepth 1-type f-name "* *" | cut-f3-d ' .' | Sort | Uniq-c  -I (Find only the current folder without recursion)
The above script decomposition steps are:
    1. Find all file name types in *. * format
    2. Truncate the name of the suffix in the File name section
    3. After sorting the suffix names and counting

Note: Since my QQ is running in the window system, the above script is executed through Cynwin.

The Find Command section explains

First look at the description in the Man Handbook of Find:

-maxdepth levels
Descend at most levels (a non-negative integers) levels of directories below the command line arguments.
-type C
File is of type C:
D Directory
F Regular File
-name pattern
Base of file name (the path with the leading directories removed) matches shell pattern pattern.

Here's what I'm doing:

    1. Find only under the current folder, so use the-maxdepth 1 parameter (Note that if you have a-maxdepth parameter, you must put it before all other parameters, otherwise waring information will appear)
    2. To find only files, without needing to care about folders, use the-type f parameter (note that there will be file types in other formats, such as linked files, block files, etc.) on Linux, and that the shortcuts on the window System are in the format of general files.
    3. Only files with a suffix are filtered out, so use the-name "* *" parameter (Note that using the-name "*. *" parameter will also filter out the. Name and name.), so filter * * * and "." There are characters before and after the file, you can use-regex "\./.+\. + "parameters, specific function please Baidu" find regular expression ")
Cut Command Section Description

In the same vein, take a look at the description in Cut's Man Handbook:

-F,--fields=list
Select only these fields; Also print any line this contains no delimiter character, unless the-s option is specified
-D,--delimiter=delim
Use DELIM instead of the TAB for field delimiter

The contents of the output after the find command above are in the following format:

./a.png
./b.jpg

...

So, here we just need a second "." After the content, so use the-d '. ' parameter specifies the use of '. ' As a delimiter, and then use-F3 to explicitly output the contents of the third field, that is, all the suffix names.

The sort command and the Uniq command section explain

The sort command is well understood, which is to sort the preceding output in order to operate with the Uniq command.

Let's focus on the use of the Uniq command, which describes the role of the Uniq command in this manual:

Uniq-report or omit repeated lines

The approximate function is to find successive lines of repetition and report them. Note that Uniq is concerned with: 1. Must be consecutive, so sort before use, and the action object of the command is row, so do not use this command if it is a repeating word within a statistical paragraph.

Let's look at the description of the-C and-I parameters for Uniq:

-C,--count
Prefix lines by the number of occurrences
-I.,--ignore-case
Ignore differences in case when comparing

Here, our requirement is to count the number of occurrences of all duplicate rows (suffix names), so the-c parameter is used, and the window system is case insensitive, so the-I parameter is used.

Note: There is a post dedicated to the Uniq command "example of Linux command line Uniq" Using the example demonstrates the use of each parameter, you can go to a view.
Summarize

This one-sentence script uses the following knowledge:

    1. The-maxdepth,-type,-name parameters of the Find command
    2. The-F,-D parameter of the Cut command
    3. Sort command
    4. The-C of the Uniq command,-i parameter


The number of files with various suffix names in the statistics folder of the script series

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.