Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

No mv command in Tcl

238 views
Skip to first unread message

Cecil Westerhof

unread,
Feb 4, 2020, 4:28:08 AM2/4/20
to
Is it true that there is no mv command in Tcl? I need to mv a range of
files and I am doing it like this now:
exec mv {*}${toConcat} ${orgDir}

But this will not work on a Windows machine.

--
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof

Ralf Fassel

unread,
Feb 4, 2020, 4:46:57 AM2/4/20
to
* Cecil Westerhof <Ce...@decebal.nl>
| Is it true that there is no mv command in Tcl? I need to mv a range of
| files and I am doing it like this now:
| exec mv {*}${toConcat} ${orgDir}
>
| But this will not work on a Windows machine.

See "file rename".

https://www.tcl.tk/man/tcl/TclCmd/file.htm#M31

HTH
R'

Cecil Westerhof

unread,
Feb 4, 2020, 5:44:09 AM2/4/20
to
I should have looked a bit more careful. :'-( I saw rename and thought
it was just renaming a file.

Thanks and sorry for the noise.

Rich

unread,
Feb 4, 2020, 8:54:18 AM2/4/20
to
Cecil Westerhof <Ce...@decebal.nl> wrote:
> Ralf Fassel <ral...@gmx.de> writes:
>
>> * Cecil Westerhof <Ce...@decebal.nl>
>> | Is it true that there is no mv command in Tcl? I need to mv a
>> range of | files and I am doing it like this now:
>> | exec mv {*}${toConcat} ${orgDir}
>>>
>> | But this will not work on a Windows machine.
>>
>> See "file rename".
>>
>> https://www.tcl.tk/man/tcl/TclCmd/file.htm#M31
>
> I should have looked a bit more careful. :'-( I saw rename and
> thought it was just renaming a file.

Be careful though.

The /bin/mv command will, silently, transform a cross device "mv" into
a "cp" followed by an "rm". The [file rename] command does not perform
that silent conversion and will instead generate an error on a cross
device move.

The [file stat] command will allow you to detect cross device moves if
you want to duplicate this functionality of /bin/mv.

Ralf Fassel

unread,
Feb 4, 2020, 10:40:04 AM2/4/20
to
* Rich <ri...@example.invalid>
| Cecil Westerhof <Ce...@decebal.nl> wrote:
| > Ralf Fassel <ral...@gmx.de> writes:
| >> See "file rename".
| >>
| >> https://www.tcl.tk/man/tcl/TclCmd/file.htm#M31
| >
| > I should have looked a bit more careful. :'-( I saw rename and
| > thought it was just renaming a file.
>
| Be careful though.
>
| The /bin/mv command will, silently, transform a cross device "mv" into
| a "cp" followed by an "rm". The [file rename] command does not perform
| that silent conversion and will instead generate an error on a cross
| device move.

Is this OS-specific? I can "file rename" on Linux just about anything
(files, empty and filled directories) from local disk to NFS and back,
and also between local disk partitions... tcl 8.5.19, Opensuse 15.1

R'

Cecil Westerhof

unread,
Feb 4, 2020, 11:28:06 AM2/4/20
to
Rich <ri...@example.invalid> writes:

> Cecil Westerhof <Ce...@decebal.nl> wrote:
>> Ralf Fassel <ral...@gmx.de> writes:
>>
>>> * Cecil Westerhof <Ce...@decebal.nl>
>>> | Is it true that there is no mv command in Tcl? I need to mv a
>>> range of | files and I am doing it like this now:
>>> | exec mv {*}${toConcat} ${orgDir}
>>>>
>>> | But this will not work on a Windows machine.
>>>
>>> See "file rename".
>>>
>>> https://www.tcl.tk/man/tcl/TclCmd/file.htm#M31
>>
>> I should have looked a bit more careful. :'-( I saw rename and
>> thought it was just renaming a file.
>
> Be careful though.
>
> The /bin/mv command will, silently, transform a cross device "mv" into
> a "cp" followed by an "rm". The [file rename] command does not perform
> that silent conversion and will instead generate an error on a cross
> device move.

In this case that is better, because the concatenate is depending on
the timestamps of the files. So I do not want them to change.

Cecil Westerhof

unread,
Feb 4, 2020, 11:44:04 AM2/4/20
to
It does not go wrong. I just touched a test file. Waited five minutes
and did a mv to another device. The timestamp was still correct.

Rich

unread,
Feb 4, 2020, 1:25:52 PM2/4/20
to
Cecil Westerhof <Ce...@decebal.nl> wrote:
> Ralf Fassel <ral...@gmx.de> writes:
>
>> * Rich <ri...@example.invalid>
>> | Cecil Westerhof <Ce...@decebal.nl> wrote:
>> | > Ralf Fassel <ral...@gmx.de> writes:
>> | >> See "file rename".
>> | >>
>> | >> https://www.tcl.tk/man/tcl/TclCmd/file.htm#M31
>> | >
>> | > I should have looked a bit more careful. :'-( I saw rename and
>> | > thought it was just renaming a file.
>>>
>> | Be careful though.
>>>
>> | The /bin/mv command will, silently, transform a cross device "mv" into
>> | a "cp" followed by an "rm". The [file rename] command does not perform
>> | that silent conversion and will instead generate an error on a cross
>> | device move.
>>
>> Is this OS-specific? I can "file rename" on Linux just about anything
>> (files, empty and filled directories) from local disk to NFS and back,
>> and also between local disk partitions... tcl 8.5.19, Opensuse 15.1
>
> It does not go wrong. I just touched a test file. Waited five minutes
> and did a mv to another device. The timestamp was still correct.

Ok, I learned something I did not already know about Tcl today (at
least with 8.6, which was the version I used to test).

It is not documented in the manpage, but file rename does silently
switch to performing a cp/rm when crossing devices. The only thing
that changed is that the timestamp applied to the moved file lost its
fractional seconds (but as Tcl's file stat also ignores fractional
seconds, I'm not too concerned there).

Which now makes me wonder if there is any value in explicitly calling
this out in the manpage?

Rich

unread,
Feb 4, 2020, 1:27:40 PM2/4/20
to
In my test I referenced in my other posting, Tcl seems to drop
fractional seconds from the timestamps, so that's only a problem if
your sorting relies on those fractional seconds being preserved to
obtain the proper ordering.

Ted Nolan <tednolan>

unread,
Feb 4, 2020, 1:43:56 PM2/4/20
to
The one of these that bit me badly was the related "file copy", which
unlike the unix "cp" command copies the timestamp, so all my scripts that
were based on doing "ls -t" to find newly copied in files broke. Something
else to be aware of (and I think there needs to be a -nocopytimestamp or
somesuch option..)
--
columbiaclosings.com
What's not in Columbia anymore..

Cecil Westerhof

unread,
Feb 4, 2020, 3:44:05 PM2/4/20
to
Rich <ri...@example.invalid> writes:

>> In this case that is better, because the concatenate is depending on
>> the timestamps of the files. So I do not want them to change.
>
> In my test I referenced in my other posting, Tcl seems to drop
> fractional seconds from the timestamps, so that's only a problem if
> your sorting relies on those fractional seconds being preserved to
> obtain the proper ordering.

No, I order on filename. What I mend is when file n is above a certain
size it could be that file n + 1 has to be concatenated to it. This is
decided on the file-size of n + 1 and the difference between the
timestamps of n and n + 1.
0 new messages