Latest LQ Deal: Linux Power User Bundle
Go Back > Forums > Linux Forums > Linux - General
User Name
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.


  Search this Thread
Old 05-02-2006, 12:39 PM   #1
Registered: Aug 2003
Posts: 232

Rep: Reputation: 30
delete multiple files

Hi all,

if I have a bunch of file in one dir and I want to delete everything excpet any files that were create on april-29. how is the command line to delete multiple files at one time???

Old 05-02-2006, 01:32 PM   #2
LQ Guru
Registered: Dec 2005
Location: Somewhere on the String
Distribution: Debian Wheezy (x86)
Posts: 6,094

Rep: Reputation: 272Reputation: 272Reputation: 272
First I would do this to give you a txt file with a list of all the files that were last MODIFIED (it's difficult to do creation date in linux from what I've read) on April 29, 2006:


for file in *; do
        mtime=$(stat "$file" -c%y | cut -d" " -f1)
	if [ $mtime == 2006-04-29 ]; then
		echo $file >> files20060429.txt
Look at files20060429.txt and make sure it contains all the files you expect it to. Move it to another directory so that it doesn't get deleted.

Then I would mkdir remove and modify the script to move all the files NOT last modified on 2006-04-29 to this new folder

for file in *; do
        mtime=$(stat "$file" -c%y | cut -d" " -f1)
	if [ $mtime != 2006-04-29 ]; then
		echo $file
		mv $file ./remove
Then I'd look in the directory and make sure none of the files in files20060429.txt are there by mistake. Then rm -ir remove. And it should remove all the files in the directory you created.

Sorry, forgot to mention, the code above should be put into a text file called and then chmod +x to make it executable. You invoke the script by being in the same directory and then ./

Anyway, use this at your own risk, as I'm not responsible for lost data (another reason why I recommend trying it out with cp instead of mv until you are comfortable with the script doing what you want it to do)...


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
How to delete files that won't delete? di11rod Linux - Security 7 10-19-2005 09:14 PM
delete files suguname Linux - Newbie 3 07-05-2005 08:49 AM
Delete Files imsajjadali Red Hat 15 07-23-2004 01:12 PM
Help I need help tarring multiple files in multiple directories VisionZ Linux - Newbie 28 03-25-2004 05:25 PM
How to delete the destination files while the source files deleted in cp -u ? myunicom Linux - General 4 09-26-2003 01:13 PM > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 06:39 AM.

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