Skip to main content
added 10 characters in body
Source Link
mrjayviper
  • 2.3k
  • 6
  • 30
  • 45

I think it's best described with an example

parent1 (located inside /home/myuser
  - folder1
    - test11.png
    - test11.txt
    - folder11
      - test111.png
    - folder12
      - test121.png
      - test122.png
  - folder2
    - test21.png

if I can my script

get-number-of-files-per-folder "parent" png

the output should be:

folder1: 4
folder2: 1

at the moment, I'm using this command but it seems it counts all the files and not just the file extension I listed.

find /home/myuser/parent -maxdepth 1 -mindepth 1 -type d -exec sh -c 'echo "{} : $(find "{}" -iname "*png" -type f | wc -l)" file\(s\)' \;

How do I know it's wrong? because when I ran this

find /home/myuser/parent -iname '*$png''*jpg' -type f | wc -l

it says I have zero JPG files but the script above says I have xx files inside a folder.

I think it's best described with an example

parent1 (located inside /home/myuser
  - folder1
    - test11.png
    - test11.txt
    - folder11
      - test111.png
    - folder12
      - test121.png
      - test122.png
  - folder2
    - test21.png

if I can my script

get-number-of-files-per-folder "parent" png

the output should be:

folder1: 4
folder2: 1

at the moment, I'm using this command but it seems it counts all the files and not just the file extension.

find /home/myuser/parent -maxdepth 1 -mindepth 1 -type d -exec sh -c 'echo "{} : $(find "{}" -iname "*png" -type f | wc -l)" file\(s\)' \;

How do I know it's wrong? because when I ran this

find /home/myuser/parent -iname '*$png' -type f | wc -l

it says I have zero files.

I think it's best described with an example

parent1 (located inside /home/myuser
  - folder1
    - test11.png
    - test11.txt
    - folder11
      - test111.png
    - folder12
      - test121.png
      - test122.png
  - folder2
    - test21.png

if I can my script

get-number-of-files-per-folder "parent" png

the output should be:

folder1: 4
folder2: 1

at the moment, I'm using this command but it seems it counts all the files and not just the file extension I listed.

find /home/myuser/parent -maxdepth 1 -mindepth 1 -type d -exec sh -c 'echo "{} : $(find "{}" -iname "*png" -type f | wc -l)" file\(s\)' \;

How do I know it's wrong? because when I ran this

find /home/myuser/parent -iname '*jpg' -type f | wc -l

it says I have zero JPG files but the script above says I have xx files inside a folder.

added 10 characters in body
Source Link
mrjayviper
  • 2.3k
  • 6
  • 30
  • 45

I think it's best described with an example

parent1 (located inside /home/myuser
  - folder1
    - test11.png
    - test11.txt
    - folder11
      - test111.png
    - folder12
      - test121.png
      - test122.png
  - folder2
    - test21.png

if I can my script

get-number-of-files-per-folder "parent" png

the output willshould be:

folder1: 4 folder2: 1

folder1: 4
folder2: 1

at the moment, I'm using this command but it seems it counts all the files and not just the file extension.

find /home/myuser/parent -maxdepth 1 -mindepth 1 -type d -exec sh -c 'echo "{} : $(find "{}" -iname "*png" -type f | wc -l)" file\(s\)' \;

How do I know it's wrong? because when I ran this

find /home/myuser/parent -iname '*$png' -type f | wc -l

it says I have zero files.

I think it's best described with an example

parent1 (located inside /home/myuser
  - folder1
    - test11.png
    - test11.txt
    - folder11
      - test111.png
    - folder12
      - test121.png
      - test122.png
  - folder2
    - test21.png

if I can my script

get-number-of-files-per-folder "parent" png

the output will be:

folder1: 4 folder2: 1

at the moment, I'm using this command but it seems it counts all the files and not just the file extension.

find /home/myuser/parent -maxdepth 1 -mindepth 1 -type d -exec sh -c 'echo "{} : $(find "{}" -iname "*png" -type f | wc -l)" file\(s\)' \;

How do I know it's wrong? because when I ran this

find /home/myuser/parent -iname '*$png' -type f | wc -l

it says I have zero files.

I think it's best described with an example

parent1 (located inside /home/myuser
  - folder1
    - test11.png
    - test11.txt
    - folder11
      - test111.png
    - folder12
      - test121.png
      - test122.png
  - folder2
    - test21.png

if I can my script

get-number-of-files-per-folder "parent" png

the output should be:

folder1: 4
folder2: 1

at the moment, I'm using this command but it seems it counts all the files and not just the file extension.

find /home/myuser/parent -maxdepth 1 -mindepth 1 -type d -exec sh -c 'echo "{} : $(find "{}" -iname "*png" -type f | wc -l)" file\(s\)' \;

How do I know it's wrong? because when I ran this

find /home/myuser/parent -iname '*$png' -type f | wc -l

it says I have zero files.

Source Link
mrjayviper
  • 2.3k
  • 6
  • 30
  • 45

count number of files (based on file extension) in multiple folders

I think it's best described with an example

parent1 (located inside /home/myuser
  - folder1
    - test11.png
    - test11.txt
    - folder11
      - test111.png
    - folder12
      - test121.png
      - test122.png
  - folder2
    - test21.png

if I can my script

get-number-of-files-per-folder "parent" png

the output will be:

folder1: 4 folder2: 1

at the moment, I'm using this command but it seems it counts all the files and not just the file extension.

find /home/myuser/parent -maxdepth 1 -mindepth 1 -type d -exec sh -c 'echo "{} : $(find "{}" -iname "*png" -type f | wc -l)" file\(s\)' \;

How do I know it's wrong? because when I ran this

find /home/myuser/parent -iname '*$png' -type f | wc -l

it says I have zero files.