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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
01-14-2005, 05:05 PM
|
#1
|
Member
Registered: Nov 2004
Location: Boston
Posts: 30
Rep:
|
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
|
|
|
01-14-2005, 05:08 PM
|
#2
|
Member
Registered: Apr 2003
Location: denver co
Distribution: redhat9
Posts: 156
Rep:
|
-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.
|
|
|
01-14-2005, 05:11 PM
|
#3
|
Member
Registered: Nov 2004
Location: Boston
Posts: 30
Original Poster
Rep:
|
Hello wolfe2554,
Thats for the reply, but do you know a way of deleting wildcard files:
Such as all /home/abc*.txt
-Jim
|
|
|
01-14-2005, 05:14 PM
|
#4
|
Senior Member
Registered: Jan 2003
Posts: 2,786
|
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.
|
|
|
01-15-2005, 05:13 AM
|
#5
|
LQ Guru
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733
|
Sorry, I originally misunderstood the question. So please ignore this edited post.
Last edited by jschiwal; 01-15-2005 at 05:17 AM.
|
|
|
01-15-2005, 05:54 AM
|
#6
|
Member
Registered: Oct 2004
Distribution: Mandrake, DSL, SuSE, RedHat
Posts: 71
Rep:
|
jimwelc, further to the "man" command, if you want a quicker simpler help with a specific command try this one:
The --help works with alot of commands and is less... verbal... than the man which is often confusing for bash newcomers
|
|
|
All times are GMT -5. The time now is 01:18 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|