LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
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


Reply
  Search this Thread
Old 12-07-2006, 04:44 PM   #1
kpachopoulos
Member
 
Registered: Feb 2004
Location: Athens, Greece
Distribution: Gentoo,FreeBSD, Debian
Posts: 705

Rep: Reputation: 30
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
 
Old 12-07-2006, 04:52 PM   #2
reddazz
LQ Guru
 
Registered: Nov 2003
Location: N. E. England
Distribution: Fedora, CentOS, Debian
Posts: 16,298

Rep: Reputation: 77
How about "rm -rf *.extension"? You could also do something like
Code:
$find /some/path -name "*.extension" -exec rm -rf {} \;
 
Old 12-07-2006, 04:55 PM   #3
dxqcanada
Member
 
Registered: Sep 2006
Location: Canada
Distribution: Gentoo
Posts: 702

Rep: Reputation: 43
The -r / -R should only remove directorys ... so I think you will need to pipe some commands together (or put it in a script).
 
Old 12-07-2006, 04:57 PM   #4
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 65
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.
 
Old 08-23-2008, 08:12 AM   #5
svzard
LQ Newbie
 
Registered: Nov 2007
Distribution: Gentoo, Slackware64, Ubuntu 14.04
Posts: 10

Rep: Reputation: 0
Hello,

I would be obliged if you could explain the commands you both suggested.

I've the same problem. I stupidly tried
Code:
rm -r /mydir/*.exe
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
 
Old 08-23-2008, 08:33 AM   #6
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 65
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.
 
Old 08-24-2008, 08:53 AM   #7
svzard
LQ Newbie
 
Registered: Nov 2007
Distribution: Gentoo, Slackware64, Ubuntu 14.04
Posts: 10

Rep: Reputation: 0
thanks a lot for the link matthew. will also go through man pages.
 
  


Reply



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
[SOLVED] rm files only - retain directory structure schneidz Programming 15 05-30-2013 04:08 PM
Delete files for a particular changed date recursively? qwertyme Linux - Newbie 5 01-23-2009 10:41 AM
How to recursively rename files using their directory name pattern ceg4048 Linux - General 2 09-28-2005 01:16 PM
Moving certain files recursively preservice folder structure DigiTalk Linux - Newbie 11 09-08-2005 08:04 AM
Program files and directory structure Carel Linux - Newbie 5 04-11-2001 10:57 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 03:02 AM.

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
Open Source Consulting | Domain Registration