New answers tagged rm
If this happens and you're sure you want to delete everything, you should try using sudo rm -rf directory/
Just to make the story full, because when we want to delete all files older than a specified time within a directory, then that specified time is better specified as for e.g. two-week old or one-month old, instead of specifying a fixed date string. If so, let me present, a ready made Ubuntu package -- tmpreaper: Description: cleans up files in directories ...
Assuming there are only regular files and no funny things like subdirectories or other file like objects. find -not -newermt "Mar 31 08:04" -delete To see which files are going to be deleted run without -delete first. -not -newermt means to find files which modification time is older than the given time string. The time string is parsed like the date ...
move the file that you want to preserve to somewhere outside the directory remove everything in the directory using your favourite method move the file that you want to preserve back into the directory Not exactly 'hi-tech' but it is much harder to accidentally delete the file that you want to preserve if you use this approach. Obviously, this approach ...
Another solution is this one: http://stackoverflow.com/questions/11231937/bash-ignoring-error-for-a-particular-command Just add an OR-statement after your command: rm -rf my/dir || true This way, when statement #1 fails (throws error), run statement #2, which is simply true.
Top 50 recent answers are included