We start with two sub-directories play and play2 in the home directory each containing one text file. How can we get rid of them?
$ rm play/file2.txt
$ rmdir play
$ rmdir play2
rmdir: failed to remove 'play2': Directory not empty
From the home directory we can delete the file in the sub-directory and then remove the empty directory. The directory play2 is not empty and can't be removed with rmdir.
$ cd play2
bash: cd: play2: No such file or directory
rm: descend into directory 'play'? y
rm: remove regular empty file 'play/file1.txt'? y
rm: remove directory 'play'? y
The -i flag means interactive so each deletion is confirmed. Note we can use rm with no flags or several flags such as i or r after the dash to alter the behaviour of the command.
How to remember all these codes? You get help by using the
man command.
man rm
Scroll up and down with the arrow keys and the letter q exits.
No comments:
Post a Comment