LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 11-28-2005, 12:04 AM   #1
LoafOfBread34
LQ Newbie
 
Registered: Aug 2004
Posts: 13

Rep: Reputation: 0
Delete Files by size


Hi, I would like a command that will remove a file that is below, say 40kb. I think I have to use the find command but im new to that.

Here is what I have so far:
Code:
find . -size -40k -exec rm "{}" \;

This deletes any file that has no decimal places in its size. (E.G. It will delete 1.0kb but not 1.1kb.) How can I fix this?.
 
Old 11-28-2005, 12:56 AM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
I'm not sure I understand what you're saying... if you
"search & destroy" files smaller 40k such of size 1.1k
will survive?


Cheers,
Tink
 
Old 11-28-2005, 01:15 AM   #3
LoafOfBread34
LQ Newbie
 
Registered: Aug 2004
Posts: 13

Original Poster
Rep: Reputation: 0
Sorry, ill try to explain it better.

I have a folder full of around 500 files. I want to keep the files that are over 40kb. So I want a command/script that will delete any file that has a size less than 40kb. So my folder will be left with files that are 40kb or over. so RM >40 KEEP <40
 
Old 11-28-2005, 11:16 AM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Well, that's exactly what the find statement will do ...

find -type f -size -40k -exec rm {} \;

And it doesn't matter whether a file has 1024 or 1126
bytes (aka 1KB or 1.1KB), it will be deleted. Just bear
in mind that Linux still sees 1K as 1024 bytes, not as 1000.


Cheers,
Tink
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Script to delete files with 0k file size in a directory justgiver Linux - Newbie 4 01-28-2008 04:56 AM
How to delete files that won't delete? di11rod Linux - Security 7 10-19-2005 09:14 PM
increase point size size when printing PDF files newlin Red Hat 0 09-27-2003 07:13 AM
How to delete the destination files while the source files deleted in cp -u ? myunicom Linux - General 4 09-26-2003 01:13 PM
delete files by size Serena Linux - Newbie 2 04-25-2002 07:38 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 09:32 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration