Remove directory tree without following symlinks

Steven D'Aprano steve at pearwood.info
Sat Apr 23 06:24:51 EDT 2016


On Sat, 23 Apr 2016 06:13 pm, Paul Rubin wrote:

> Steven D'Aprano <steve at pearwood.info> writes:
>> I want to remove a directory, including all files and subdirectories
>> under it, but without following symlinks. I want the symlinks to be
>> deleted, not the files pointed to by those symlinks.
> 
> rm -r shouldn't follow symlinks like you mention.


"rm -r" gives me a NameError when I run it in my Python script :-)

But seriously, where is that documented? I've read the man page for rm, and
it doesn't say anything about treatment of symlinks, nor is there an option
to follow/not follow symlinks. So I never trust rm -r unless I know what
I'm deleting.



-- 
Steven




More information about the Python-list mailing list