0

Today when I was using the "find" command. It is a little bit confusing on the usage.

The problem: I want to count how many gz files under the main directory. However, the main dir also have sub directories. e.g. /mainDir/Dir1/1/ /mainDir/Dir2/1/2012. Under each sub folder, there are several gz files.

I use command 1, it works fine.

First I go the the main directory:

ls -R . | find -name "*.gz" | wc -l

However, if I use command 2, it return 0:

ls -R /home/user1/data1/2012/mainDir | find -name "*.gz" | wc -l

What is the reason, Any one got some idea?

thanks,

4

2 回答 2

4

你不需要ls。简单地find . -name '*.gz' | wc -lfind /home/user1/data1/2012/mainDir -name '*.gz' | wc -lfind命令中连字符选项之前的单词like-name是要搜索的目录的名称。

于 2013-03-14T00:12:02.350 回答
0

这个怎么样:

 find /home/user1/data1/2012/mainDir -name "*.gz" | wc -l

这符合标准 find 语法并做你想做的事。

于 2013-03-14T00:13:09.917 回答