Count the number of files found with find

Bash shell questions
Post Reply
User avatar
MigrationUser
Posts: 336
Joined: 2021-Jul-12, 1:37 pm
Been thanked: 2 times
Contact:

Count the number of files found with find

Post by MigrationUser »

28 Nov 2008 02:34
Temonio

Hello, I am reading and reading tutorials but i cannot find an answer to my problen:

im trying to count the number of files found with FIND, for example if i write the next code line

find . -name 'salida_0*'

and i find 3 files named:
salida_00001_20081120121017
salida_00002_20081120121019
salida_00003_20081120121021

how can I give to a variable the number of files found with the name "salida_0*" in this case, give to a variable the number 3 ?

Thanks a lot community and sorry, my english is quite poor.

----------------------------

#2 28 Nov 2008 13:21
Simon Sheppard

Code: Select all

$ result=$(find . -name 'salida_0*'|xargs -0 | wc -l)

$ echo $result
----------------------------

#3 02 Dec 2008 20:48
Temonio


Wow man, thanks a lot.
Post Reply