Skip to content

Deleting files#

Uh oh! Jess doesn't actually like the idea of her age being known in that file of ours, so she's asked us to delete that information. Being respectful of another person's privacy is important, we let's delete the file to honour Jess' request: rm jess.txt. The rm command, as you might have guessed, means remove (man rm).

I now get:

1
2
3
michael@develop:~/friends$ rm jess.txt
michael@develop:~/friends$ ls -lh
total 0

Now we have no friends again. We may as well delete the directory, too:

1
2
3
michael@develop:~/friends$ cd ..
michael@develop:~$ rm friends/
rm: cannot remove 'friends/': Is a directory

Huh? It turns out that friends/ is indeed a directory, as we know, and so we can't use rm without providing a few additional flags to "force" it to delete a directory: rm -r friends. Now it's gone.

The -r flag to rm means recursive, and it means: delete this item and everything inside of it by recursing into the directory and deleting everything you find... scary. That's why it must be used with care. Use man rm to see more.