2.4 Delete files and directories: rm

Finally, another useful command is “rm”, which delete files or directories (when providing the flag -r). We just need to type “rm” and the list of file or directories names we want to delete.

ls
#fileA.txt fileB.txt newdir subdir
rm fileB.txt; ls
#fileA.txt newdir subdir

Note: Keep in mind there is no way back! The command rm does not move files to the trash! files are completely deleted.

Removing a directory: rm -r

rm newdir
#rm: cannot remov ‘newdir’: Is a directory
rm -r newdir; ls
#fileA.txt subdir
rm -r *; ls

When providing a file name or directory, we need to be sure they are present in our current location, otherwise we have to write a path that take us to that file or directory. For example, suppose we are in our home directory that contains subdir, so if we want to copy or delete a file that is in subdir, we then have to type the path to subdir + the file name: “rm subdir/A” this will delete A within subdir.^