Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!

Count Files By Type?

Discussion in 'General Discussion' started by ca2236, Jun 22, 2018.

  1. ca2236

    ca2236 Well-Known Member

    Joined:
    Feb 2, 2018
    Messages:
    50
    Likes Received:
    7
    Trophy Points:
    8
    Location:
    Nebraska
    cPanel Access Level:
    DataCenter Provider
    Hello,

    I've been looking for a way to show a break down of files and how many files exit of each one.

    Awstats shows the file types, and it gives great break down information, but not a count of each file type.

    for example, I would want something that would show something like below:

    File Type | File Count
    ------------------------
    .php 73
    .txt 2
    .
    .
    etc

    thanks
     
  2. Jcats

    Jcats Well-Known Member

    Joined:
    May 25, 2011
    Messages:
    714
    Likes Received:
    120
    Trophy Points:
    168
    Location:
    New Jersey
    cPanel Access Level:
    DataCenter Provider
    Are you referring to your web server access logs, or actual files hosted in the server?

    For the latter, run this in the directory where you want to find and count the ext's, this is recursive.

    Code:
    find . -type f -printf '%f\n' | rev | cut -f 1 -d '.' | rev | sort | uniq -c | sort -n
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
    rpvw likes this.
  3. ca2236

    ca2236 Well-Known Member

    Joined:
    Feb 2, 2018
    Messages:
    50
    Likes Received:
    7
    Trophy Points:
    8
    Location:
    Nebraska
    cPanel Access Level:
    DataCenter Provider
    Thanks Jcats,

    I apologize for not specifying, but it would be for our customers, they wouldn't/and don't have shell access. Is there either an addon/feature/etc where it would do the same thing, but a customer can do it from the cpanel interface.
     
  4. cPanelLauren

    cPanelLauren Forums Analyst
    Staff Member

    Joined:
    Nov 14, 2017
    Messages:
    1,783
    Likes Received:
    132
    Trophy Points:
    118
    Location:
    Houston
    cPanel Access Level:
    DataCenter Provider
    Hi @ca2236

    AwStats has the following section (example from my test domain so not a lot of traffic)

    file_type_awstats.png

    And Analog Stats has:
    file_type_analog.png

    Normally the "extension" portion here would include an actual extension but in my case it's not really getting any traffic.

    Do these not suit your purposes, the hits would be equivalent to the count as each hit is a request of that file type.

    I am not aware of a standalone plugin that just does this for cPanel users. If this is something you'd like to see added to the product I would suggest opening a feature request using the link in my signature. You could also look at creating your own plugin that does something of this nature:
    Guide to cPanel Plugins - Developer Documentation - cPanel Documentation
    Tutorial - How to create a Plugin (WHM & cPanel)

    Thanks!
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  5. ca2236

    ca2236 Well-Known Member

    Joined:
    Feb 2, 2018
    Messages:
    50
    Likes Received:
    7
    Trophy Points:
    8
    Location:
    Nebraska
    cPanel Access Level:
    DataCenter Provider
    Hi cPanelLauren,

    thank you for taking the time to write the detailed message, I appreciate it. However, our client doesn't want a count of each type a file by the number of hits it gets. I think the client wants a list of each file type by number of times it occurs on the file system.

    For example. Let's say you have a website comprised of .php, .html, and .jpg

    the report would have to list an output similar to the following


    File Type | Number of files with this extension in public_html
    -----------------------------------------------------
    .php | 25
    .html | 6
    .jpg | 12


    Please let me know if you have any questions.
     
  6. cPanelLauren

    cPanelLauren Forums Analyst
    Staff Member

    Joined:
    Nov 14, 2017
    Messages:
    1,783
    Likes Received:
    132
    Trophy Points:
    118
    Location:
    Houston
    cPanel Access Level:
    DataCenter Provider
    Hi @ca2236

    As I stated previously this isn't something that is available currently. You could use the one-liner that was provided by @Jcats or you could develop your own plugin which does this but there's nothing native to cPanel that would do this and include it in the stats.

    Thanks!
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  7. ca2236

    ca2236 Well-Known Member

    Joined:
    Feb 2, 2018
    Messages:
    50
    Likes Received:
    7
    Trophy Points:
    8
    Location:
    Nebraska
    cPanel Access Level:
    DataCenter Provider
    Thanks,

    We can resolve this question. I was responding to your question of "do these not suit my preferences", I missed the other statement saying that it wasn't available. I apologize.

    I will investigate what it will take to write my own plugin.
     
  8. cPanelLauren

    cPanelLauren Forums Analyst
    Staff Member

    Joined:
    Nov 14, 2017
    Messages:
    1,783
    Likes Received:
    132
    Trophy Points:
    118
    Location:
    Houston
    cPanel Access Level:
    DataCenter Provider
    HI @ca2236

    The guide I linked earlier may be useful as well as the forums here, there are quite a few folks who have done this. If you do need help please let us know in the cPanel Developers section of the forums!

    Thanks!
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
Loading...

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice