0

Is it just me, or is copying then removing the old file a hassle? Why doesn't Linux have a built in rename command for single files / directories?

5
Contributors
10
Replies
11
Views
10 Years
Discussion Span
Last Post by eggi
Featured Replies
  • No, thats actually exactly wrong. The mv command does not make a new file. Period. The datablocks holding the information remain unchanged. All that happens is that the entry in the directory file that holds the inode information is copied to the new directory, and then the inode information is … Read More

0

Hey there,

You can use "mv" for files and directories.

Perhaps I'm misunderstanding.

Hope that helps :)

, Mike

0

I'm sorry. Looking at your profile, I think you're just kidding ;) You got me :)

,Mike

1

No, thats actually exactly wrong.

The mv command does not make a new file. Period. The datablocks holding the information remain unchanged. All that happens is that the entry in the directory file that holds the inode information is copied to the new directory, and then the inode information is removed from the old directory.

To demonstrate this; create a file, and change ownership to someone in your group, but first chmod the file to 600. Chmod the directory the file is located in to 770, and make sure that it is owned by your group and/or you.

Create a new directory (770), with the same ownership. Now, technically, you will not have write access to the file (600 owned by Joe). But, since you have permissions to change the inode information contained in both directory listings, you will be able to run an mv command on the file. You will not, however be able to read from that file to perform the cp command. You can mv, but not cp. You have no access to the stored data, just to the inodes pointing to the data. Therefore, you change the location from which those inodes can be accessed, but do not modify the original file. This is a true mv.

Votes + Comments
Wow, lots of information. Thanks.
0

Well, not exactly ;)

I threw that one out there without thinking, I'll admit and you are correct in the circumstance that both files are on the same partition.

If you mv /bob/dir1 to /bob/dir2 - assuming /bob is one partition/filesystem containing dir1 and dir2 - then the pointer to inode explanation is correct.

However, if you mv a file from /bob/dir/1 to /joe/dir/1 - assuming /bob is one partition/filesystem and /joe is another partition/filesystem - Unix (at least, Solaris) actually does do a cp and then an rm. The same test you propose will not allow you to mv or cp the file you don't have permissions to access in that situation.

Hopefully, this post is finally resolved. If I'm not mistaken it all started out as a joke ;)

Take care,

Mike

0

Hey,

Sunny side up: We were both correct :) Nothing wrong with healthy debate and you made an excellent point!

, Mike

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.