Subject: Re: bug#17618: ls -l dangerous when listing links

From: Eric Blake <[email-masked]>
Date: Wed, 28 May 2014 09:54:33 -0600

On 05/28/2014 09:46 AM, Eric Blake wrote:
> tag 17618 wontfix
> thanks
> 
> On 05/28/2014 07:36 AM, Michał Adamczyk wrote:
>> Call it a bug or call it a feature. It is dangerous though.
>>
>> When using `ls -l` to list a directory with links in it, it will produce
>> an output similar to this:
>>
>> lrwxrwxrwx 1 user group 30 1980-01-01 00:01 link_name ->
>> /path/to/destination/file
> 
>>
>> Since the output is empty, you'll get the target of that link
>> overwritten with an empty file.

One thing you CAN do is set the noclobber option of your shell.  POSIX
requires that 'set -C' cripple '>' redirection to an existing file
(scripts can force overwrites using '>|').  This would prevent the shell
from doing any overwriting to empty files if you accidentally paste ls
output, although it has the minor drawback that not all shell scripts
are robustly written to still work in the presence of set -C.

http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#set

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org