-   Linux - Newbie (
-   -   Write a shell scriprt to delete files size of 56KB (

umwai 12-17-2008 10:14 PM

Write a shell scriprt to delete files size of 56KB
I wanna know how to write a shell script that deletes specific kind of a file type with a 56KB
example : exe files with 56KB 12-17-2008 10:41 PM

find . -type f -name "*.exe" -size 56k -exec rm -f {} \;

Junior Hacker 12-17-2008 11:53 PM


find . -name "*.exe" -size 56k -delete


find / -type f -name "*.exe" -size -56k -exec rm -f {} \;


find / -name "*.exe" -size +56k -delete

These are three different scripts, you would save it with a name, something like "56k" in your /home directory or wherever (somewhere in your path). Then you would just type: 56k in a terminal to execute.

The first example deletes all .exe files which are precisely 56KB from the directory you are in (PWD) and all subdirectories.
The second example deletes all .exe files 56KB and under starting from root directory and all subdirectories, meaning it'll delete 56KB and under .exe files throughout the entire file system.
The third deletes all files larger than 56KB from root and all subdirectories.
There are many ways to use the find command, this shows two ways, one may be safer than the other.

Junior Hacker 12-18-2008 12:00 AM

Test any scripts you get from forums/online on expendable files in a testing directory first before executing in valuable areas of the file system.
Just a safety precaution.

billymayday 12-18-2008 12:18 AM

With find, it's usually safest to run it without the -delete or -exec part first. It will just display a list of files that meet the given criteria. So, for example

find . -name "*.exe" -size 56k

and see if the list makes sense before running

find . -name "*.exe" -size 56k -exec rm -f {} \;

All times are GMT -5. The time now is 01:24 AM.