Removing the content of a directory recursively [closed]
I want to delete the content of a folder without deleting a folder: all files and all sub folders with sub files. This doesn't delete anything
sudo rm -rf /folder1/*
Why not? How to get it to work?
Is this folder1
really directly in root /
? You must either use relative or absolute path:
sudo rm -rf folder1/*
sudo rm -rf /full/path/to/folder1/*
Then you must remember that the wildcard is handled before sudo
. If the user doesn't have permission to read contents of folder1
, the wildcard returns nothing. You can test that with
sudo echo folder1/*
In that case you may
sudo bash
rm -rf folder1/*