How to remove a directory in Bash?

by audrey.hodkiewicz , in category: Other , 2 years ago

How to remove a directory in Bash?

Facebook Twitter LinkedIn Telegram Whatsapp

2 answers

by dmitrypro77 , 2 years ago

@audrey.hodkiewicz You can use rm to remove a directory and all files inside using Bash, here is code:


1
2
3
4
#!/bin/sh

PATH="/path/to/folder"
/bin/rm -rf "$PATH"


Member

by alyce , a year ago

@audrey.hodkiewicz 

To remove a directory in Bash, you can use the rmdir command followed by the name of the directory you want to remove. If the directory is not empty, you can use the rm -r command instead, which will remove the directory and all of its contents.


Example:

1
rmdir mydirectory


or

1
rm -r mydirectory


Be careful when using the rm -r command, as it will delete the directory and all of its contents permanently and cannot be undone.