I have a folder with lots of files and folder. It contains many multimedia files (jpg, jpeg, mp4, mpeg). The directory also contains lots of sub folders.

I want to do two things :

  1. Find the total counts of all files

  2. Find the total size used by the files and folder.

I want to exclude files with some particular extensions, like exclude mp4, jpeg files. I also want to exclude a list of folders also. Suppose I have 1000 files and 200 folders. Out of these files, I want to exclude files with some particular extensions and some folders. Like if I have 26 folders named a-z, I want to exclude the folders named h, f, y and so on.

The final output, of the total number of files present and the size they occupy should not contain these files and folders.

I have made an effort towards it and 90% is completed, the command exludes all the files and directories present but it prints the folder name as well, I just want the file name in the output.

find . -type d \( -path "*/Make-Directory-Script-master" -o -path "*/pycharm-community-2020.3" \) -prune  -o -type f \( -name "*.zip"  -o -name "*.pdf" -o -name "*.js" -o -name "*.json" -o -name "*.css" -o -name "*.srt" \) -prune -o  -print

Any help will be appreciated 🙂🙂

  • Welcome to U&L SE. Could you give us some lines of example output of what you get and of what you expect so that we can understand better what you mean? (Edit your question and add it there)
    – pLumo
    Commented Jan 19, 2021 at 9:09

1 Answer 1


Just add a -type f before final -print

command looks like (folded fo readability)

find . -type d \( -path "*/Make-Directory-Script-master" -o -path "*/pycharm-community-2020.3" \) -prune  
    -o -type f \( -name "*.zip"  -o -name "*.pdf" -o -name "*.js" -o -name "*.json" -o -name "*.css" -o -name "*.srt" \) -prune 
    -o -type f -print

the original command (abridged and line numbered)

#1  find . -type d \( -path ... \) -prune  
#2    -o -type f \( -name ... \) -prune 
#3    -o -print
  • in line 1, you select path from a list and -prune (that is stop finding), to find whole line 1 "\(..\) -prune" evaluate to true, so path matching pattern are skipped from output.
  • in line 2, using a or conjunction ( -o ) you filtered out a list of extension and skipped them from output also.
  • using a final or, in line 3, whithout -type f you print any remaining path, either filename ot directory name.
  • Can you please explain why adding this works, my knowledge regarding this is very low as I just learned about it the day before I posted the question Commented Jan 21, 2021 at 3:28
  • So if I am understanding correctly, the last -type f specifies that only files will be printed. Conversly if I added -type d then only the directories will be printed. Am I correct in my assesment... Commented Jan 21, 2021 at 15:59
  • yes that's correct, you can filter further using -user XXX or -mtime -10 etc ...
    – Archemar
    Commented Jan 21, 2021 at 17:57
  • so after the last -type f -print -user xxx, this will print all the files which belong to user xxx. Am I correct.. Commented Jan 22, 2021 at 2:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .