Deleting files based on their size


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Deleting files based on their size
# 1  
Old 06-24-2010
Deleting files based on their size

I have several files in a folder and I would like to delete the ones that do not contain all the required information (size) let say 1kb.
Any ideas?
# 2  
Old 06-24-2010
If you want to delete files that are less than 1kB, then this should work:
Code:
find . -size -2k -exec rm '{}' \;

This User Gave Thanks to bartus11 For This Post:
# 3  
Old 06-24-2010
Excelent!

Thanks!
# 4  
Old 06-24-2010
find . -type f -size -1k -exec rm '{}' \;
# 5  
Old 06-25-2010
Quote:
Originally Posted by rdcwayx
find . -type f -size -1k -exec rm '{}' \;
Did you try your code? :P On my test machine "-1k" finds only empty files.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Deleting lines based on a condition for a group of files

hi i have a set of similar files. i want to delete lines until certain pattern appears in those files. for a single file the following command can be used but i want to do it for all the files at a time since the number is in thousands. awk '/PATTERN/{i++}i' file (6 Replies)
Discussion started by: anurupa777
6 Replies

2. UNIX for Dummies Questions & Answers

Deleting files based on Substring match

In folder there are files (eg ABS_18APR2012_XYZ.csv DSE_17APR2012_ABE.csv) . My requirement is to delete all the files except today's timestamp I tried doing this to list all the files not having today's date timestamp #!/bin/ksh DATE=`date +"%d%h%Y"` DIR=/data/rfs/... (9 Replies)
Discussion started by: manushi88
9 Replies

3. UNIX for Dummies Questions & Answers

deleting files based on the suffix

how do we delete files based on the suffix??? (1 Reply)
Discussion started by: saggiboy10
1 Replies

4. Shell Programming and Scripting

deleting all files with 0 size

I tried with find . -maxdepth 1 -type f -size 0 | xargs rm -f but, getting the error find: bad option -maxdepth seems maxdepth is not there in my system. m using HP-UX Please help. (7 Replies)
Discussion started by: gotam
7 Replies

5. Shell Programming and Scripting

Deleting the files based on the date's

I have to write one script which will delete the files in the below passion. If today is 17-Feb-2010 then the script delete only 17-JAN-2010 files from the directory. Could you please help me, How will I delete the files when the year is leap year, if today is 30th Mar 2010 then how will... (1 Reply)
Discussion started by: kandi.reddy
1 Replies

6. UNIX for Dummies Questions & Answers

deleting lines from a delimited files based on a 2nd file

I need a little help... I have a file with 3 fields, Time/Date, IP address, UniqueID I have a 2nd file of UniqueIDs. I want to either (which ever is easier): 1. delete entries in file 1 that have a UniqueID in file 2 2. create a new file with the fields from File 1, excluding the... (4 Replies)
Discussion started by: goldie363
4 Replies

7. Shell Programming and Scripting

Checking files size and deleting if bigger than x

Hello , I have to write a crontab line make a check on a file and, if bigger than 2Gb, to stop apache daemon, delete the file and restart apache . Someone have suggestions ? Thanks (2 Replies)
Discussion started by: gogol_bordello
2 Replies

8. UNIX for Dummies Questions & Answers

deleting files based on file name and modified time

Hi, I have some log files created in the following fashion Ex: file name modified date 1) s.log1 01-jan-08 2) s.log2 02-jan-08 3) s.log3 03-jan-08 4) s.log4 04-jan-08 Now I want to have the latest 2 logs and delete the others. Can you tell me the one liner /... (1 Reply)
Discussion started by: ammu
1 Replies

9. Shell Programming and Scripting

command for deleting log files based on some condition

Hello, Can anyone pls. provide me with the command for deleting files older then 15 days with a restriction to keep at least 5 files in a directory even if they are older then 15 days. Any help will be highly appreciated. Thanks, Pulkit (4 Replies)
Discussion started by: pulkit
4 Replies

10. Shell Programming and Scripting

Traversing thru dirs and deleting files based on date

Hi Folks I am pretty new to unix and shellscripting. I need help on writing logic on traversing recursively through a set of directories under a top-level folder and delete files(mostly text) which are 1 month old. Can you people help me on this? Thanks a lot Ravi (5 Replies)
Discussion started by: ravi2082
5 Replies
Login or Register to Ask a Question