If it is not empty, you will get the error rm: test: Directory not empty. It is recommended to use the -d flag for empty directory cases instead of the -r flag because the -d flag ensures that a directory is empty.
![trash it gif trash it gif](https://media3.giphy.com/media/dZzy9Y1hlrE69BRSXm/source.gif)
To delete an empty directory, you can use this command: rm -d test Without this flag, you will get the same error rm: : is a directory. So, you can delete a directory like this: rm -r testįor an empty folder, you can still provide the -r flag, but the dedicated -d flag applies to this case. The -r flag informs the rm command to recursively delete the contents of a directory (whether it's files or subdirectories). You will get this error: rm: test: is a directory Without using this flag like this: rm test
Trash it gif how to#
How to delete a folder with contentsįor a directory with contents, you have to provide the -r flag. To remove a file, say test.txt, you can use the command without options like this: rm test.txtįor directories, you have to provide some flag options. For directories, this command can be used to delete a directory entirely – that is, it deletes a directory and all files and subdirectories within the directory. You use the rm command to delete files and directories in Linux. Let's look at both commands in more detail. The TL DR of both commands is that rm deletes directories that may contain content such as files and subdirectories, while rmdir ONLY deletes empty directories.Īlso, both commands delete directories permanently (rather than moving them to the trash), so be careful when using them.
![trash it gif trash it gif](https://media4.giphy.com/media/l0MYRE3WCmzXCzys8/giphy.gif)
There are two ways to remove directories in Linux: the rm and rmdir commands.
![trash it gif trash it gif](http://media.giphy.com/media/5xaOcLCBzBw4QrtdDP2/giphy.gif)
But how do you do this on the terminal? I'll explain that in this article. If you're using a user interface, you can right-click on a directory and select "Delete" or "Move to Bin".