How to remove non empty Directory in Linux

htt‮.www//:sp‬lautturi.com
How to remove non empty Directory in Linux

To remove a non-empty directory in Linux, you can use the rm command with the -r option, which stands for "recursive." This option tells rm to delete all files and directories within the specified directory, as well as the directory itself.

Here is an example of how to use the rm command to remove a non-empty directory:

rm -r /path/to/directory

Keep in mind that this command will delete all files and subdirectories within the specified directory, as well as the directory itself, and it cannot be undone. Be careful when using this command, and make sure you have a backup of any important data before deleting it.

If you want to be prompted before each file is deleted, you can use the -i option, like this:

rm -ri /path/to/directory

This will ask you to confirm the deletion of each file and subdirectory before it is removed.

Alternatively, you can use the rmdir command to remove an empty directory. To remove a non-empty directory with rmdir, you will need to use the -p option to remove any parent directories that are also empty, like this:

rmdir -p /path/to/directory

This will remove the specified directory, as well as any empty parent directories, recursively.

Created Time:2017-10-28 21:39:06  Author:lautturi