Lesson 12: Removing files¶
You've seen how to remove a directory with the rmdir
command, but
rmdir
won't remove directories if they contain any files. So how can
we remove the files we have created inside learning_linux/planets
? To
do this, we will have to use the
rm (remove) command.
Warning
Please read the next section VERY carefully. Misuse of the rm
command can lead to destruction and system failure if running as the
superuser (root) - the system administration account.
Potentially, rm
is a very dangerous command; if you delete something
with rm
, it is unrecoverable! It is therefore possible to delete
everything in your home directory (all directories and sub-directories)
with rm
.
As an additional security measure, rm
can be used with the -i
command-line option which will ask for confirmation before deleting
anything (remember to use tab-completion). Run the following commands,
and type "y" (for yes) to indicate you truly intend to delete the files.
[learner learning_linux]$ cd planets/
[learner planets]$ rm -i heaven.txt
rm: remove regular empty file heaven.txt? y
[learner planets]$ ls
earth.txt jupiter.txt mars.txt neptune.txt