I have a folder with many sub-folders containing small tif files (less than 160kb) which have been merged together in bigger pdf files, together with some big multi-page tif files.

I want to delete all small tif files without deleting the bigger files (tif or pdf) and retaining the directory structure. How do I go about it on Linux using the command-line?

find . -name "*.tif" -type 'f' -size -160k -delete

Run the command without -delete first to verify that the correct files are found.

Note the - before 160k. Just 160k means exactly 160 kilobytes. -160k means smaller than 160 kilobytes. +160k means larger than 160 kilobytes.

The -type 'f' forces the command to only act on files and skip directories. this would avoid errors if the path contains folders with names that match the pattern *.tif.

If you want to filter size in bytes (as in 160 bytes instead of 160 kilobytes) then you have to write it like this: 160c. If you just write 160 it will be interpreted as 160*512 bytes. This is a strange requirement by POSIX. Read here for more details: https://unix.stackexchange.com/questions/259208/purpose-of-find-commands-default-size-unit-512-bytes

  • The ubuntu man page seems to mention this. Just below the "TESTS" section: Numeric arguments can be specified as +n for greater than n, -n for less than n, n for exactly n.
    – jdg
    Sep 11 '14 at 23:55
  • 1
    thanks. it did not occur to me that the information might be somewhere else in the manpage.
    – Lesmana
    Sep 12 '14 at 8:55
  • It is nice this command also works recursively. My use case would be to delete .txt files under 12kB.
    – Sun
    Sep 23 '14 at 4:21
  • no need for sudo? Oct 6 '15 at 15:35
  • 19
    For sizes in bytes specify 50c, not 50b or 50!
    – Evengard
    Jan 29 '16 at 13:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.