View Full Version : [all variants] Is there a command to delete all small files in a specified folder?
afeasfaerw23231233
October 7th, 2009, 02:23 AM
For example, there is a folder call "data" in my home directory. If I want to delete all the files that are smaller than 20KB in that "data" folder (including sub-folders), which parameter of mv command should I run?
terazen
October 7th, 2009, 02:58 AM
rm `find /home/some/folder/ -size -20k -type f`
You may want to run the find command first just to see what you're looking at deleting before you actually do it.
ls -lah `find /home/some/folder/ -size -20k -type f`
The -name option of find is good too if you want to delete certain files like *.jpg or something.
afeasfaerw23231233
October 7th, 2009, 04:52 AM
Thanks for the help. But it doesn't work with file name with spacing.
For example, there's is a file named "text file" in the folder "data" and is smaller than 20K,
ls -lah `find data -size -20k -type f`
ls: cannot access data/text: No such file or directory
ls: cannot access file: No such file or directory
rm `find data -size -20k -type f`
rm: cannot remove `data/text': No such file or directory
rm: cannot remove `file': No such file or directory
lloyd_b
October 7th, 2009, 05:47 AM
find /home/some/folder/ -size -20k -type f | while read FILENAME; do rm "$FILENAME"; done should do the trick. You can replace the "rm" with a "ls" to see what's happening (but be sure to leave the "$FILENAME" in quotation marks!).
Lloyd B.
afeasfaerw23231233
October 7th, 2009, 06:28 AM
Thanks. It works but not on the filename with Simplified Chinese characters.
May I ask what is -type f for? This site (http://linux.about.com/od/commands/l/blcmdl1_find.htm) said it stands for regular file? How can I delete the files with Simplified Chinese characters?
EDIT: Oh, sorry. It seems to be my mistake. The files with Simplified Chinese characters are now gone. Thanks for help!
Powered by vBulletin® Version 4.2.2 Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.