LinuxQuestions.org
Visit Jeremy's Blog.
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 10-09-2012, 11:05 PM   #1
the_rhino
Member
 
Registered: Sep 2004
Distribution: PCLinuxOS
Posts: 59

Rep: Reputation: 15
rm recursive doesn't work for me


All I want to do is wipe out several files in one directory and several sub directories

In the directory I want to take out the files I do:

Code:
rm -r *txt
Is the above supposed to work? Am I doing it wrong?

this would wipe out the files and the directories but that is not what I want to do.

Code:
rm -r /dir
Thanks
 
Old 10-09-2012, 11:43 PM   #2
Rupadhya
Member
 
Registered: Sep 2012
Location: Hoffman Estates, IL
Distribution: Fedora 20
Posts: 167

Rep: Reputation: Disabled
I remove directories and all their contents including any sub-directories with this command.

Code:
rm -rf /dir
The -r means remove directories and their contents recursively. The -f means force the option, ignore nonexistent files, never prompt.
Be careful as this doesn't prompt you. if you do
Code:
rm -rf /
it will traverse down from your root of the filesystem and delete all the directories and files!

- Raj
 
Old 10-09-2012, 11:49 PM   #3
the_rhino
Member
 
Registered: Sep 2004
Distribution: PCLinuxOS
Posts: 59

Original Poster
Rep: Reputation: 15
I don't want to to remove the directories. I know how to do that. I also know about wiping out the entire system with your second command.

I just want to delete several files in one directory and in several sub directories.

If rm won't do it is there a command that will?
 
Old 10-10-2012, 02:16 AM   #4
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
"rm" will happily remove whatever you tell it to! Depending on the complexity of what you want to do, it might take several command----or it might involve appending rm to a "find" command.

"rm -r *txt" removes all files ending in "txt" in the current directory--and all subdirectories whose name ends in "txt" (and contents). It will remove--e.g.:
file.txt
dirname_txt and all contents
but not:
dirname/file.txt
dirname/dirname_txt

Try this:
Code:
find . -name "*txt" -exec rm {} \;
This searches recursively, beginning in the current directory, for all filenames (including directories) in the current directory--and everything below. It will remove (assuming permissions allow) all files named *txt, but NOT directory names ending in txt. (for the latter, it will give an error message)
 
1 members found this post helpful.
Old 10-10-2012, 02:37 AM   #5
the_rhino
Member
 
Registered: Sep 2004
Distribution: PCLinuxOS
Posts: 59

Original Poster
Rep: Reputation: 15
Sweet! nice command sequence.
 
  


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
Google Hangout doesn't work, and Mplayer doesm't work without -ao alsa flagGoogle H ranban282 Linux - Software 0 02-20-2012 04:23 AM
Keyboard doesn't work right click on mouse doesn't work ramblinrick Linux Mint 2 10-15-2010 01:10 AM
ls with recursive option and file name doesn't work FromFPan2Fire Linux - Newbie 7 01-05-2010 10:21 AM
how does recursive grep work? serutan Linux - Newbie 5 07-11-2008 01:00 PM
logout in x doesn't work and nvidia doesn't boot Meriadoc Linux - Newbie 2 06-18-2004 12:32 PM

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

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