Help answer threads with 0 replies.
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 01-14-2005, 05:05 PM   #1
Registered: Nov 2004
Location: Boston
Posts: 30

Rep: Reputation: 15
Question recurrsive delete of files


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:

if [ -d TESTDIR ]; then
rm -f "$TESTDIR/abc*.txt"

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,
Old 01-14-2005, 05:08 PM   #2
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
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

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

Rep: Reputation: 374Reputation: 374Reputation: 374Reputation: 374
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
LQ Guru
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
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
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:
rm --help
The --help works with alot of commands and is less... verbal... than the man which is often confusing for bash newcomers


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 > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:33 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
Open Source Consulting | Domain Registration