How to Remove a Folder in on Linux/Mac
Are you wondering how to permanently remove a folder/directory on Linux or Mac from your terminal?
To check what your current directory is, you can use the pwd
command. And to list all of the files and directories in your current folder, use ls
.
- Use
rmdir
orrm -d
command to remove empty folders. - Use the
rm -r
command to remove non-empty folders.
Example:
rmdir <directory-name>
Or if that folder had files I also wanted deleted:
rm -r <directory-name>
As an example, if I was in a directory with node_modules
that I wanted to delete its contents I would run:
rm -r node_modules
⚠️ Caution ⚠️
This can't be undone!!! Your files will be lost, so be very careful before you use this command, especially the rm -r
, which can be particularly destructive if run in the wrong directory.
Follow me on Twitter or connect on LinkedIn.
🚨 Want to make friends and learn from peers? You can join our free web developer community here. 🎉