Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 12-17-2008, 11:14 PM   #1
Registered: May 2008
Location: Sri Lanka
Distribution: Ubuntu
Posts: 57
Blog Entries: 1

Rep: Reputation: 16
Angry 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
Old 12-17-2008, 11:41 PM   #2
LQ Newbie
Registered: Dec 2008
Posts: 10

Rep: Reputation: 0
find . -type f -name "*.exe" -size 56k -exec rm -f {} \;
Old 12-18-2008, 12:53 AM   #3
Junior Hacker
Senior Member
Registered: Jan 2005
Location: North America
Distribution: Debian testing Mandriva Ubuntu
Posts: 2,687

Rep: Reputation: 61
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.
Old 12-18-2008, 01:00 AM   #4
Junior Hacker
Senior Member
Registered: Jan 2005
Location: North America
Distribution: Debian testing Mandriva Ubuntu
Posts: 2,687

Rep: Reputation: 61
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.
Old 12-18-2008, 01:18 AM   #5
LQ Guru
Registered: Mar 2006
Location: Sydney, Australia
Distribution: Fedora, CentOS, OpenSuse, Slack, Gentoo, Debian, Arch, PCBSD
Posts: 6,678

Rep: Reputation: 122Reputation: 122
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 {} \;


shell script

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 Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to write a script to delete files? AGazzaz Linux - General 11 12-05-2007 07:43 AM
Delete Files by size LoafOfBread34 Linux - General 3 11-28-2005 12:16 PM
vsftpd: allow users to write and delete files me3 Linux - Software 4 03-04-2005 08:22 PM
clients can write to files but they cannot delete them sparsh Linux - Networking 1 05-10-2003 10:54 PM
delete files by size Serena Linux - Newbie 2 04-25-2002 08:38 PM > Forums > Linux Forums > Linux - Newbie

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

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