Ready to do a little damage? The rm command removes a file (assuming you have permission to do so) without even saying
hasta la vista. Be sure you really want to delete your files before you use rm, because once the files are gone, they're not
coming back. For example,
immediately deletes the file named wallet in the current directory without prompting. If you want to be prompted before the deletion, use the -i flag.
Note: There is one little safety feature in rm--it won't delete a directory (unless you use the -r flag).
One other rm flag is -f, which translates roughly to "Don't ask me any questions--just delete the files." While rm normally asks for confirmation before deleting a write-protected file, the -f (force) flag overrides this prompt.
Be careful with the rm command, since the multiuser nature of Linux does not allow for undelete as in DOS. As soon as you let go of the space occupied by a file, the operating system is likely to use it for something else.
Deleting Directories
If you created a directory named spelunking six months ago, and now you're not so keen on crawling through slimy caves, the rmdir command may be able to help:
$ rmdir spelunking
This command removes the specified directory, but only if it's empty. If the directory contains files or subdirectories, you'll have to delete them using rm first.
One alternative to painstakingly removing all the contents of a directory that you just want to make disappear is to use the rm -r command. The -r flag gives rm license to kill directories, their files, and even their subdirectories. Be very sure you understand what's about to happen before using a command like this:
$ rm -r spelunking
Let's just say that careless use of the -r flag might end your spelunking hobby prematurely.
Previous Lesson: Creating Files and Directories
Next Lesson: Linux Files - Wildcards
Comments (most recent first)
deepu (17 Aug 2010, 01:32)
this explanation is toooo good
very good....... you done a great help....
Jayti (16 Aug 2010, 07:06)
You are brilliant.
I love the way you have designed the course material!
Gub (28 Jul 2010, 04:02)
Dr. Bob thanks for this Site very helpful and you are good educator..i
understand what i am doing right now,
Bob Rankin (10 Jun 2010, 08:28)
@Deb - Sounds like you're low on RAM memory.
Deb (10 Jun 2010, 08:14)
I am getting a "/bin/rm: Cannot allocate memory" message every time I use
the rm -r command :(
Anon (04 Jun 2010, 13:41)
Thank you this was very helpful! I just deleted 50,000 duplicated files
and saved 100 megs of hard drive space. :D
|
|
|
![]() |
|
| <Send This Link to a Friend> <Bookmark This Page> | ||