GNU bug report logs - #7463
truncate

Previous Next

Package: coreutils;

Reported by: Rupert Bruce <rbruce <at> nearshore.biz>

Date: Mon, 22 Nov 2010 14:39:01 UTC

Severity: normal

Done: Pádraig Brady <P <at> draigBrady.com>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 7463 in the body.
You can then email your comments to 7463 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to owner <at> debbugs.gnu.org, bug-coreutils <at> gnu.org:
bug#7463; Package coreutils. (Mon, 22 Nov 2010 14:39:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Rupert Bruce <rbruce <at> nearshore.biz>:
New bug report received and forwarded. Copy sent to bug-coreutils <at> gnu.org. (Mon, 22 Nov 2010 14:39:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Rupert Bruce <rbruce <at> nearshore.biz>
To: bug-coreutils <at> gnu.org
Subject: truncate
Date: Mon, 22 Nov 2010 09:41:33 -0500
truncate (GNU coreutils) 7.4

Unexpected behavior:

$ ls -l
total 0
$ truncate --size 0 *.log
$ ls
*.log

I would expect "truncate --size 0 *.log" to truncate any files ending 
with ".log"; instead I get a new file called "*.log"

FYI, one of the first changes I make on a new installation is to alias 
truncate in .bashrc:
alias ll='ls -l'
alias la='ls -A'
alias truncate='truncate --size 0'





Information forwarded to owner <at> debbugs.gnu.org, bug-coreutils <at> gnu.org:
bug#7463; Package coreutils. (Mon, 22 Nov 2010 15:16:02 GMT) Full text and rfc822 format available.

Message #8 received at 7463 <at> debbugs.gnu.org (full text, mbox):

From: Erik Auerswald <auerswal <at> unix-ag.uni-kl.de>
To: Rupert Bruce <rbruce <at> nearshore.biz>
Cc: 7463 <at> debbugs.gnu.org
Subject: Re: bug#7463: truncate
Date: Mon, 22 Nov 2010 16:21:08 +0100
Hi,

On Mon, Nov 22, 2010 at 09:41:33AM -0500, Rupert Bruce wrote:
> truncate (GNU coreutils) 7.4
>
> Unexpected behavior:
>
> $ ls -l
> total 0
> $ truncate --size 0 *.log
> $ ls
> *.log
>
> I would expect "truncate --size 0 *.log" to truncate any files ending  
> with ".log"; instead I get a new file called "*.log"

That is caused by your shell, see the "nullglob" option (at least for
bash).

Erik
-- 
Trying to understand [the GNU GPL] in terms of the goals and values
of open source is like trying [to] understand a CD drive's retractable
drawer as a cupholder.
                        -- Richard Stallman




Reply sent to Pádraig Brady <P <at> draigBrady.com>:
You have taken responsibility. (Mon, 22 Nov 2010 15:28:02 GMT) Full text and rfc822 format available.

Notification sent to Rupert Bruce <rbruce <at> nearshore.biz>:
bug acknowledged by developer. (Mon, 22 Nov 2010 15:28:02 GMT) Full text and rfc822 format available.

Message #13 received at 7463-done <at> debbugs.gnu.org (full text, mbox):

From: Pádraig Brady <P <at> draigBrady.com>
To: Rupert Bruce <rbruce <at> nearshore.biz>
Cc: 7463-done <at> debbugs.gnu.org
Subject: Re: bug#7463: truncate
Date: Mon, 22 Nov 2010 15:32:04 +0000
On 22/11/10 14:41, Rupert Bruce wrote:
> truncate (GNU coreutils) 7.4
> 
> Unexpected behavior:
> 
> $ ls -l
> total 0
> $ truncate --size 0 *.log
> $ ls
> *.log
> 
> I would expect "truncate --size 0 *.log" to truncate any files ending
> with ".log"; instead I get a new file called "*.log"
> 
> FYI, one of the first changes I make on a new installation is to alias
> truncate in .bashrc:
> alias ll='ls -l'
> alias la='ls -A'
> alias truncate='truncate --size 0'

That's a function of your shell.
Search for "nullglob"

cheers,
Pádraig.




Information forwarded to owner <at> debbugs.gnu.org, bug-coreutils <at> gnu.org:
bug#7463; Package coreutils. (Mon, 22 Nov 2010 15:44:02 GMT) Full text and rfc822 format available.

Message #16 received at 7463 <at> debbugs.gnu.org (full text, mbox):

From: Eric Blake <eblake <at> redhat.com>
To: Rupert Bruce <rbruce <at> nearshore.biz>
Cc: 7463 <at> debbugs.gnu.org
Subject: Re: bug#7463: truncate
Date: Mon, 22 Nov 2010 08:48:29 -0700
[Message part 1 (text/plain, inline)]
On 11/22/2010 07:41 AM, Rupert Bruce wrote:
> truncate (GNU coreutils) 7.4
> 
> Unexpected behavior:
> 
> $ ls -l
> total 0
> $ truncate --size 0 *.log
> $ ls
> *.log

Thanks for the report.  However, this is not a bug, but how the shell
works.  By default, if a shell glob has no matches (in your case, there
are no files ending in .log in the current directory), then the glob is
passed as-is to the child process.  And truncate assumes that when given
a file name that it should create that file.

> 
> I would expect "truncate --size 0 *.log" to truncate any files ending
> with ".log"; instead I get a new file called "*.log"

Then your expectations need to be refined in light of standardized shell
globbing behavior.

Also, since you mentioned you use bash, you can change your shell
defaults.  For example, 'shopt -s failglob' would make your above
command abort because no .log files were present, rather than passing
the unexpanded glob on as a filename.  Likewise, 'shopt -s nullglob'
would make a non-matching glob silently result in no output (use with
caution; things like 'cat *.log' become a much different beast when
nullglob is enabled).

-- 
Eric Blake   eblake <at> redhat.com    +1-801-349-2682
Libvirt virtualization library http://libvirt.org

[signature.asc (application/pgp-signature, attachment)]

Information forwarded to owner <at> debbugs.gnu.org, bug-coreutils <at> gnu.org:
bug#7463; Package coreutils. (Mon, 22 Nov 2010 15:53:01 GMT) Full text and rfc822 format available.

Message #19 received at 7463 <at> debbugs.gnu.org (full text, mbox):

From: Steve Ward <planet36 <at> gmail.com>
To: Rupert Bruce <rbruce <at> nearshore.biz>
Cc: 7463 <at> debbugs.gnu.org
Subject: Re: bug#7463: truncate
Date: Mon, 22 Nov 2010 10:32:25 -0500
[Message part 1 (text/plain, inline)]
On Mon, Nov 22, 2010 at 09:41, Rupert Bruce <rbruce <at> nearshore.biz> wrote:

> truncate (GNU coreutils) 7.4
>
> Unexpected behavior:
>
> $ ls -l
> total 0
> $ truncate --size 0 *.log
> $ ls
> *.log
>
> I would expect "truncate --size 0 *.log" to truncate any files ending with
> ".log"; instead I get a new file called "*.log"
>
> FYI, one of the first changes I make on a new installation is to alias
> truncate in .bashrc:
> alias ll='ls -l'
> alias la='ls -A'
> alias truncate='truncate --size 0'
>
>
>
>
>

In newer versions of truncate there is a "--no-create" option.



Steve
[Message part 2 (text/html, inline)]

Information forwarded to owner <at> debbugs.gnu.org, bug-coreutils <at> gnu.org:
bug#7463; Package coreutils. (Mon, 22 Nov 2010 18:37:02 GMT) Full text and rfc822 format available.

Message #22 received at 7463 <at> debbugs.gnu.org (full text, mbox):

From: Rupert Bruce <rbruce <at> nearshore.biz>
To: 7463 <at> debbugs.gnu.org
Subject: Re: bug#7463: truncate
Date: Mon, 22 Nov 2010 13:41:16 -0500
The '--no-create' option works well - I have modified my alias to
    alias truncate='truncate -cs 0'

The 'glob' options look interesting ( I've noticed that 'touch *.log' 
does the same thing ) but I'll stick to the scope of the problem at hand...

Thanks to all !




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Tue, 21 Dec 2010 12:24:04 GMT) Full text and rfc822 format available.

This bug report was last modified 14 years and 181 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.