LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 01-14-2005, 05:05 PM   #1
jimwelc
Member
 
Registered: Nov 2004
Location: Boston
Posts: 30

Rep: Reputation: 15
Question recurrsive delete of files


Hello,

I am very new to bash scripting and I am trying to recursivly deletes files within a directory:

Basically I have a directory and I would like to delete all the abc*.txt files
In my script I attempt to do the following:


#=========================
TESTDIR="/home/test"
if [ -d TESTDIR ]; then
rm -f "$TESTDIR/abc*.txt"
fi
#=========================

Althouth this exact "rm" command works fine within a terminal window, it will not work within my script.

Any suggestions or help will be greatly appreciate.


Best Regards,
-Jim
 
Old 01-14-2005, 05:08 PM   #2
wolfe2554
Member
 
Registered: Apr 2003
Location: denver co
Distribution: redhat9
Posts: 156

Rep: Reputation: 30
-r is recurssive so rm -rf /home would remove home and everything else on that branch of the tree. But you must be super user to delete dirs with rm otherwise rmdir.
 
Old 01-14-2005, 05:11 PM   #3
jimwelc
Member
 
Registered: Nov 2004
Location: Boston
Posts: 30

Original Poster
Rep: Reputation: 15
Hello wolfe2554,

Thats for the reply, but do you know a way of deleting wildcard files:

Such as all /home/abc*.txt

-Jim
 
Old 01-14-2005, 05:14 PM   #4
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 370Reputation: 370Reputation: 370Reputation: 370
My suggestion:
find /home/test -maxdepth 1 -type f -name "abc*.txt" -exec rm {} \;

Check out man find for details on what the switches/arguments do.
 
Old 01-15-2005, 05:13 AM   #5
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 671Reputation: 671Reputation: 671Reputation: 671Reputation: 671Reputation: 671
Sorry, I originally misunderstood the question. So please ignore this edited post.

Last edited by jschiwal; 01-15-2005 at 05:17 AM.
 
Old 01-15-2005, 05:54 AM   #6
jeickal
Member
 
Registered: Oct 2004
Distribution: Mandrake, DSL, SuSE, RedHat
Posts: 71

Rep: Reputation: 15
jimwelc, further to the "man" command, if you want a quicker simpler help with a specific command try this one:
Code:
rm --help
The --help works with alot of commands and is less... verbal... than the man which is often confusing for bash newcomers
 
  


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 Off
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 10:14 PM
delete files suguname Linux - Newbie 3 07-05-2005 09:49 AM
how do you delete files? otoomet Linux - General 6 11-12-2004 05:06 AM
How to delete the destination files while the source files deleted in cp -u ? myunicom Linux - General 4 09-26-2003 02:13 PM
Delete Files bsengland Linux - Newbie 1 11-04-2002 06:29 PM


All times are GMT -5. The time now is 08:36 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration