rm --clear-directory /home/me/another_dir

deeptech71 at gmail.com deeptech71 at gmail.com
Wed Apr 11 18:10:09 UTC 2007


Pieter de Goeje wrote:
> On Wednesday 11 April 2007, deeptech71 at gmail.com wrote:
>> Is there a way to clear a directory with such a command (keeping the owner
>> and permissions of the folder)?
>>
>> Yes there are the obvious ones:
>> cd /home/me/another_dir && rm *
>> rm /home/me/another_dir/* // if cant traverse here
>>
>> But something that doesn't rely on the shell.
> cd /some/dir && find . -delete
> 
> Cheers, Pieter
> 

Well, IMO, for aesthetical and logical purposes, /some/dir should point to the 
directory, and /some/dir/ should point to the inside of the directory (as in 
copy INTO or FROM). So:

# cp /one /two/    // this copies dir one into dir two, so there will be a dir 
named /one/two after this command

# cp /one/ /two/
==> Do you want to recursively overwrite contents of dir /two with the content 
of dir /one ? [n] y

# cp /one /two
==> Do you want to recursively overwrite /two with /one ? [n] y

# cp /one/ /two
cp: error - overwrite a dir with some other contents? WTF?

oh and of course:
rm -R /dir    // removes dir
rm -R /dir/    // clears dir


How hard will it be to convince the developers to swich to this scheme? since 
all scripts will have to be reworked...


More information about the freebsd-questions mailing list