Which is more expensive Rename or Move?

M

Mrmaster Mrmaster

Hello,

I'd like to create a ruby script that parses emails(that will grow with
volume) and I need to find a way to distinct which emails the script
touches. I can either rename the email after the script is done with it
or move it to another directory. Which would be a least costly operation
or are they both equal expensive?

Would you have any other suggestions for this problem?

The way I understand it is that when you rename or change directory you
are just changing the path. I will be using a linux box(ubuntu) and I
think the directories are stored in a tree structure in which rename
would be less expensive.

Thank you
 
K

Kyle Schmitt

Assuming it's on the same filesystem, and you're using a real
filesystem format (ext2/3, xfs, jfs, etc), they should be almost
identical....

According to the docs on the File class though, it uses syscopy for
move, which seems odd to me, but the performance should be almost
identical.

--Kyle
 
M

Mrmaster Mrmaster

Kyle said:
Assuming it's on the same filesystem, and you're using a real
filesystem format (ext2/3, xfs, jfs, etc), they should be almost
identical....

According to the docs on the File class though, it uses syscopy for
move, which seems odd to me, but the performance should be almost
identical.

--Kyle

Hi Kyle,

I'm using ext filesystem. Why would they operations be identical? I
thought the directories are stored in a tree structure so wouldn't it
require another n(logn) operation to find a new directory during a move?
 
K

Kyle Schmitt

Because moving and renaming files consist of the same operations.

To really really overly simplify it, moving a directory primarily
involves updating the directory, not every node under it.

I'm a bit busy to lookup papers on how it works, but do some googling
for how filesystems work.
 
M

Mrmaster Mrmaster

Kyle said:
Because moving and renaming files consist of the same operations.

To really really overly simplify it, moving a directory primarily
involves updating the directory, not every node under it.

I'm a bit busy to lookup papers on how it works, but do some googling
for how filesystems work.

Thanks, I'll do the research. I just neded to know of the costs :)
 
P

Phil Romero

Thanks, I'll do the research. I just neded to know of the costs :)

Just to add a bit more to this conversation, the only time an mv
operation would be more expensive is in the case of actually mv'ing
across filesystems. You could have mv'd a file from say your
/home/username directory on sda1 to /newhome/username on sda2 (two
physically different partitions). Strange that this would come up. I
think rename is mv with a cross filesystem limitation. I don't use
rename for anything in *nix, always has been mv.
 
M

Mrmaster Mrmaster

Phil said:
Just to add a bit more to this conversation, the only time an mv
operation would be more expensive is in the case of actually mv'ing
across filesystems. You could have mv'd a file from say your
/home/username directory on sda1 to /newhome/username on sda2 (two
physically different partitions). Strange that this would come up. I
think rename is mv with a cross filesystem limitation. I don't use
rename for anything in *nix, always has been mv.

I think the rename command in the linux box calls a perl script too
which will add to the cost.
 
R

Robert Klemme

I think the rename command in the linux box calls a perl script too
which will add to the cost.

There is rename functionality in Ruby's standard library. Why bother to
call some external command for this?

Kind regards

robert
 
M

Matthew K. Williams

Just to add a bit more to this conversation, the only time an mv
operation would be more expensive is in the case of actually mv'ing
across filesystems. You could have mv'd a file from say your
/home/username directory on sda1 to /newhome/username on sda2 (two
physically different partitions). Strange that this would come up. I
think rename is mv with a cross filesystem limitation. I don't use
rename for anything in *nix, always has been mv.

Historically (~15-20 years ago and prior) you couldn't do a mv across
filesystems; at that time mv only changed the inode tables, it didn't do
any copying of data. I think the first I ran into a mv which would work
across filesystems was in the mid to late 90's.

Matt
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top