![]() You can also use regular expansions to match and delete multiple directories. To remove the directory type y and hit Enter. If the directory contains a lot of files, this can be a little annoying, so you may consider using the -I option what will prompt you only once before proceeding with the deletion. The -i option tells rm to prompt you to confirm the deletion of each subdirectory and file. The command below will remove each listed directory and their contents: rm -r dir1 dir2 dir3 To remove multiple directories at once, invoke the rm command, followed by the names of the directories separated by space. To remove a directory without being prompted, use the -f option: rm -rf dir1 If a directory or a file within the directory is write-protected, you will be prompted to confirm the deletion. To delete an empty directory, use the -d ( -dir) option and to delete a non-empty directory, and all of its contents use the -r ( -recursive or -R) option.įor example to delete a directory named dir1 along with all of its contents you would type: rm -r dir1 Unlike rmdir the rm command can delete both empty and non-empty directories.īy default, when used without any option rm does not remove directories. ![]() Is a command-line utility for deleting files and directories. In this case, you will need to use the rm command or manually remove the directory contents before you can delete it. If the directory is not empty, you will get the following error: rmdir: failed to remove 'dir1': No such file or directory For example, to delete a directory named dir1 you would type: rmdir dir1 To delete a directory with rmdir, type the command followed by the name of the directory you want to remove. It is useful when you want to delete a directory only if it is empty, without needing to check whether the directory is empty or not. Rmdir is a command-line utility for deleting empty directories. Otherwise, you will get “Operation not permitted” error.ĭirectory names with a space in them must be escaped with a backslash ( /). On most Linux filesystems, deleting a directory requires write permission on the directory and its content. When removing a directory using a desktop file manager, the directory is actually moved to the Trash and can be easily recovered.īe extra careful when removing files or directories from the command line because once the directory is deleted using the commands explained in this article, it cannot be fully recovered. In this article, we will explain how to delete directories in Linux using the rmdir, rm, and find commands. But, if you are working on a headless server or want to remove multiple directories at once, your best option is to delete the directories (folders) from the command line. If you use a Desktop file manager such as Gnome’s Files or KDE’s Dolphin, then you can delete files and directories using the manager’s graphical user interface. There are several different ways to remove directories in Linux systems.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |