I am trying to remove all files and subdirectories in a directory. I used rm -r
to remove all files, but I want to remove all files and subdirectories, excluding the top directory itself.
For example, I have a top directory like images
. It contains the files header.png
, footer.png
and a subdirectory.
Now I want to delete header.png
, footer.png
and the subdirectory, but not images
.
How can I do this in linux?
Best Answer
If your top-level directory is called
images
, then runrm -r images/*
. This uses the shell glob operator*
to runrm -r
on every file or directory withinimages
.