How Do You Delete Files from a Directory That Are Smaller Than 10 KB with a Bash Command?

Problem scenario
You want to delete all the files (but not subdirectories) that are less than 10 KB in Linux's /tmp/ directory. How do you do this?

Solution
Run this command: find /tmp/ -maxdepth 1 -type f -size -10k -ls | awk '{print $NF}' | rm -rf

Leave a comment

Your email address will not be published. Required fields are marked *