1#!/bin/SH2 #find The Count of same name files under current directory3 4RM-RF Search.txt5 forFileinch' Find. -name"*.txt"`6 Do 7echo ' basename ${file} ' >>search.txt8 Done9 TenCat Search.txt | Sort | Uniq-c >Times_of_file.txt One A -RM-RF Result.txt - whileRead Line the Do -File_cnt= ' echo ${line} | Awk-f' ' '{print $}'` -File_name= ' echo ${line} | Awk-f' ' '{print $}'` -#echo ${line} >>Result.txt +Echo"file Name:${file_name}, Count is:${file_cnt}">>Result.txt -Echo"file paths is:">>Result.txt +Find. -name"${file_name}">>Result.txt ADone <Times_of_file.txt at -RM-RF Times_of_file.txt -RM-RF search.txt
The background of writing this script is:. So files with the same name on the commercial environment, the system is looking for the old. So file by default, which causes the component installation to fail.
So I want to write a script that confirms the number of files with the same name in the environment, the exact path of the file with the same name.
The execution result of the above script:
1 $ cat Result.txt2File name:1. txt, Count is:43 file paths is:4./2/1. txt5./1/1. txt6./3/1. txt7./4/4_1/1. txt8File name:2. txt, Count is:29 file paths is:Ten./2/2. txt One./1/2. txt AFile name:3. txt, Count is:1 - file paths is: -./3/3. txt theFile name:4. txt, Count is:1 - file paths is: -./4/4. txt
The output of the script is redirected to the file by default, so that even when the data is large, it can prevent the query result from swiping, resulting in difficulty in later confirmation.
After the query results sort , using uniq-c to conveniently count the number of occurrences of the same name string, this is my intention to record this script, because this command is really useful in this scenario.
Many people on the internet say that using GREP-C to count the same string, it feels very inconvenient.
As for why sort before using uniq-c, it is because Uniq-c can only count the same strings that are linked together.
| Uniq-C 1 a 1 B 1 A
As above, Uniq-c does not correctly count the number of occurrences of a, so after sort, two a will be linked together, then the count will be counted correctly.
The script above uses a for loop and a while loop in the shell, and when reading a file, a while loop format is commonly used by the individual.
The last line of the file that the while loop reads is preferably a blank line, or the last line cannot be read effectively when the file under Windows is placed under Linux.
Search system different directories under the same name of the number of files and specific path