empty folder shell command?
Moderator: General Moderators
- potato
- Forum Contributor
- Posts: 192
- Joined: Tue Mar 16, 2004 8:30 am
- Location: my lovely trailer, next to the big tree
empty folder shell command?
Hi,
i have to empty my backup folder of my server.
I know that i can use rm filename to delete a filename, but isn't there a way to delete a folders contents, but leaving the folder itself?
Any help would be great...
friendly greetings,
tom
i have to empty my backup folder of my server.
I know that i can use rm filename to delete a filename, but isn't there a way to delete a folders contents, but leaving the folder itself?
Any help would be great...
friendly greetings,
tom
Code: Select all
rm -fr folder/*
Wouldn't that ignore hidden files and folders (the ones that have a name starting with . )?astions wrote:Code: Select all
rm -fr folder/*
If i'm not mistaken rm /path/to/delete/.* removes *all* the files... (probably want to recurse (-r).. and perhaps to force (-f)).
Yeah, doing that would leave hidden files.. I suppose you could do this..
The other command you mentioned would *only* delete hidden files.
It seems like there should be a better way though.
Code: Select all
[benjamin@viper ~]$ mkdir test
[benjamin@viper ~]$ touch test/.hidden
[benjamin@viper ~]$ rm -fr test/.* & rm -fr test/*
rm: cannot remove `.' or `..'
rm: cannot remove `.' or `..'
[benjamin@viper ~]$ ls -a test/
. ..
[benjamin@viper ~]$
It seems like there should be a better way though.
Code: Select all
find . -type f -exec rm -rf '{}' \;try this but be carefull not to delete more then you need
About being carefull, the first time you run the command you probably want to prepend 'echo' to exec optionrebus wrote:This finds all files of type file in current directory and executes rm -rf FOUND_FILE_NAME for each found file ....Code: Select all
find . -type f -exec rm -rf '{}' \;
try this but be carefull not to delete more then you need
Code: Select all
find . -type f -exec echo rm -rf {}\;
I prefer to just do..
Code: Select all
rm -rf ./directory && mkdir ./directory- Kieran Huggins
- DevNet Master
- Posts: 3635
- Joined: Wed Dec 06, 2006 4:14 pm
- Location: Toronto, Canada
- Contact: