In this video, we'll talk about removing files.
RM is the utility to use.
We have already seen rmdir. RMDIR is used to remove empty directories, and
because directories are not often empty, it's not the most useful command.
Rm is used to remove files as well as directories with contents, as long as you use the appropriate options.
If you're not sure about yourself, use RM I. That will prompt for confirmation on all files.
That's a lot of fun. If you delete 1000 files or so, then
you better use RM F. That will force and don't ask anything.
RM RF removes an entire directory tree without asking, and that allows you to clean it up nicely.
If you really want to do something nasty, use RM RF no preserve
root or on slash, where slash is the root directory of everything that
will try to remove really everything, and that's not really recommended.
Hey, let's talk about that and let me use RM RF
no preserve root on slash and. Oh boy, what am I
getting? Well, I'm stopping it. I'm getting permission denied.
An operation not permitted.
Does that make sense? That absolutely makes sense because I'm an ordinary user.
The only risk that you've got if you are trying to do something like this is that you delete your
home directory as well. But fortunately it was first struggling with this proc directory where it didn't have any permissions.
I might like to do some cleaning up RM RF on tmp.
The TMP in this case is a relative file name. It's relative to my
current directory, and it will remove the TMP directory that I previously copied.
Okay, so let's use RM RF no preserve root and how well is
that doing? Well, that's not doing so well because I'm getting permission denied.
Still, it's risky business because I can't be sure that I didn't
wipe my home directory. But fortunately my home directory still exists.
So why did this command not work? Well, because of privileges. And if I really
wanted it to work, then I needed to put sudo in front of it.
But really, I can hardly imagine any reason why it makes sense to remove the entire root file system.
Maybe it's more fun if you make that RM rif and oh, that should do it in an interactive way.
But for some funny reason the interactivity doesn't work too well.
Okay, let's try the interactivity MKDIR new and
CD new and I'm using touch file.
Then arrange with the curly braces. One up to 1 million.
Does that really work?
And Ah, too bad. The argument list is too long. So apparently there's only a limited
number of files that you can use that you can address this way. But this.
This is working better. I just created 1000 files, so RM minus I on Star is going to
prompt for every single one of them. And of course I don't want to do that, so RM
F on Star will clean it up and that is how you can use the RM command.