Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to use shell script to skillfully count files

Shulou Source: shulou.com Published: 2022-06-01 04:18:50 09月17日 Update

Today, I will talk to you about how to use shell script clever statistical files, many people may not understand, in order to make you better understand, the editor summed up the following content, I hope you can get something according to this article.

In the process of data migration, a large number of dump files will be generated, which requires a simple and clear management of dump files. For example, there are a large number of files in the directory, and some tables are relatively large, corresponding to more dump files, so you want to get a very concise report that can count how many dump files there are in each table.

For example, there are 1000 dump files, all based on the table TEST1,TEST2,TEST3,TEST4. Then you want to get a simple statistical report, similar to the following form

TEST1 100 TEST2 450 TEST3 300 TEST4 150

Briefly simulate this problem.

Use the following script a.sh to generate the DUMP file.

For i in {1... 2} do touch $1_EXT_$i.dmp done

Generate these 1000 dump files.

[ora11g@rac1 DUMP] $ksh a.sh TEST1 100 [ora11g@rac1 DUMP] $ksh a.sh TEST2 450 [ora11g@rac1 DUMP] $ksh a.sh TEST3 300 [ora11g@rac1 DUMP] $ksh a.sh TEST4 150 [ora11g@rac1 DUMP] $ll * .dmp | wc-l 1000

Take a brief look at the generated dump.

[ora11g@rac1 DUMP] $ll * .dmp | tail-10-rw-r--r-- 1 ora11g dba 0 Aug 7 08:13 TEST4_EXT_91.dmp-rw-r--r-- 1 ora11g dba 0 Aug 7 08:13 TEST4_EXT_92.dmp-rw-r--r-- 1 ora11g dba 0 Aug 7 08:13 TEST4_EXT_93.dmp-rw-r--r-- 1 ora11g dba 0 Aug 7 08:13 TEST4_EXT_94.dmp-rw -Rafael ora11g dba-1 ora11g dba 0 Aug 7 08:13 TEST4_EXT_95.dmp-rw-r--r-- 1 ora11g dba 0 Aug 7 08:13 TEST4_EXT_96.dmp-rw-r--r-- 1 ora11g dba 0 Aug 7 08:13 TEST4_EXT_97.dmp-rw-r--r-- 1 ora11g dba 0 Aug 7 08:13 TEST4_EXT_98.dmp-rw-r--r-- 1 ora11g dba 0 Aug 7 08:13 TEST4_EXT_99.dmp-rw-r--r-- 1 ora11g dba 0 Aug 7 08:13 TEST4_EXT_9.dmp [ora11g@rac1 DUMP] $

The first thing you need to get is that there are several related tables in this directory.

For example, in the current situation, you need to get the

TEST1 TEST2 TEST3 TEST4

You can use the following command to get the statistics.

[ora11g@rac1 DUMP] $ls-lrt * .dmp | awk'{print $9}'| awk-F_EXT'{print $1}'| uniq TEST1 TEST2 TEST3 TEST4

Then go a step further, how to get how many dump files each table corresponds to.

You can use the following script b.sh to quickly get

Ls-lrt * .dmp | awk'{print $9}'| awk-F_EXT'{print $1}'| uniq | xargs-I echo "echo {}\ `ls-lrt {} _ EXT_ [0-9] * .dmp | wc-l\ `> tablst" > test.sh ksh test.sh rm test.sh [ora11g@rac1 DUMP] $ksh b.sh [ora11g@rac1 DUMP] $cat tablst TEST1 100TEST2 450 TEST3 300 TEST4 150

In this way, the statistical work of the documents will be very clear.

After reading the above, do you have any further understanding of how to use clever statistical files in shell scripts? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

Tags: Files statistics scripts content situations directories generation ingenuity lower want reports brevity commands forms data clear in more knowledge articles Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info Microsoft Docker NVidia Redmi