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. |
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.
|
 |
12-07-2006, 04:44 PM
|
#1
|
Member
Registered: Feb 2004
Location: Athens, Greece
Distribution: Gentoo,FreeBSD, Debian
Posts: 705
Rep:
|
how to recursively delete *.xtension files from a directory structure
Hi,
how can i recursively delete *.xtension files from a directory structure? I cannot find an "rm -r" trick for this? Is there one or do i have to write a script?
Thnx
|
|
|
12-07-2006, 04:52 PM
|
#2
|
LQ Guru
Registered: Nov 2003
Location: N. E. England
Distribution: Fedora, CentOS, Debian
Posts: 16,298
Rep:
|
How about "rm -rf *.extension"? You could also do something like
Code:
$find /some/path -name "*.extension" -exec rm -rf {} \;
|
|
|
12-07-2006, 04:55 PM
|
#3
|
Member
Registered: Sep 2006
Location: Canada
Distribution: Gentoo
Posts: 702
Rep:
|
The -r / -R should only remove directorys ... so I think you will need to pipe some commands together (or put it in a script).
|
|
|
12-07-2006, 04:57 PM
|
#4
|
Senior Member
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530
Rep:
|
If you're just interested in files (not directories with the extension), and want to be "safe" with file names with spaces in, do it like this:
Code:
find /your/dir -type f -name "*.extension" -print0 |xargs -0 rm -f
All sub-directories in /your/dir will be searched, although note that symbolic links will not be followed. Also only regular files will be deleted, not symbolic links or special files like fifos.
|
|
|
08-23-2008, 08:12 AM
|
#5
|
LQ Newbie
Registered: Nov 2007
Distribution: Gentoo, Slackware64, Ubuntu 14.04
Posts: 10
Rep:
|
Hello,
I would be obliged if you could explain the commands you both suggested.
I've the same problem. I stupidly tried and the whole data got deleted.
I'll try your commands on a test directory and if it solves my problem will execute it on the pen drive with which I'm having problem. (My pendrive is infected with a virus which creates an 'exe' file by the same name as the directory. The more directory you have the more problem.)
Regards,
SV
|
|
|
08-23-2008, 08:33 AM
|
#6
|
Senior Member
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530
Rep:
|
The xargs version will be faster, if you have a large number of files to remove. If it's only a few files, it won't make a lot of difference between -exec and xargs variants.
See this post for some background which will help you understand the find / xargs combination.
|
|
|
08-24-2008, 08:53 AM
|
#7
|
LQ Newbie
Registered: Nov 2007
Distribution: Gentoo, Slackware64, Ubuntu 14.04
Posts: 10
Rep:
|
thanks a lot for the link matthew. will also go through man pages.
|
|
|
All times are GMT -5. The time now is 05:02 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
|
|