Remove Files and Directories Using Linux Terminal

Remove Files and Directories Using Linux Terminal


Default syntax for rm deletes files, but not directories. Deleting a directory, and potentially many sub-directories and files below it, requires the –r recursive option. There is no command-line undelete feature, nor a trash bin from which to restore.

Linux RM 1

After rm failed to delete the chapter1 directory, the –r recursive option succeeded. The last rm command parsed into each sub-directory first, individually deleting contained files before removing each non-empty directory. Using -i will interactively prompt for each deletion. This is essentially the opposite of –f which will force the deletion without prompting the user.

The rmdir command deletes directories only if empty. Removed directories cannot be undeleted.

rmdir

The rmdir command failed to deleted non-empty ProjectX, but rm –r succeeded.

Read the man pages, man(rm) - man(rmdir)




Tech info

Comments