Rename directory in linux system
Asked Answered
M

2

7

I asked 'change filename without using mv command and rename function' few days ago, and @nos answered me. So I try to use 'link' function.(It seems to create a hard link.)

But, it is not available with a directory.

Is there any way to change a directory name without using 'rename' function and 'mv' command?

I can use my copy function and delete function, but it is too hard and wasteful to just change a directory name.

I just want to know whether there is any way to change a directory name without using 'rename' function and 'mv' command.

I'm so sorry about my poor English skill... ;(...

Melcher answered 19/11, 2014 at 4:59 Comment(8)
why? In linux the directory is basically a text file you can manipulate to change names of what is in it.Monofilament
Is there any way to read directory as file? I tried to open directory and read (using file descriptor), but failed to read.Melcher
it's pretty dangerous, and you'd probably need to do it at disk level, although you could try to use chmod to change the type. things like that used to work but have mostly been nailed down now.Monofilament
but you should be able to use open("/dirname",O_RDONLY). You just can't open it for writing.Monofilament
Well, you wanna tell "change the directory permission to ordinary file for editing file and edit that file", isn't it?Melcher
I would shy away from attempting to open a directory inode in any type of writable mode. Your directory inode is a special file containing the inode->filename mappings for the contents. Mess that up and you could be hoping and praying that fsck could correct it. I thought about that as a solution for your problem -- then decided it was unwise. In modern Linux, you cannot even cat the directory inode contents anymore -- there was probably a good reason for the change.Chopin
It is banned using shell command... ;)...Melcher
Hi! As seen from both of your questions, maybe sharing your overall intension will improve the solution quality! To me, it does not make sense at all not to use mv. Explain me the case where this is useful! Thank you!Rounce
A
13

Try this answer!

mv /home/user/oldname /home/user/newname
Archuleta answered 1/4, 2019 at 14:28 Comment(1)
I'm appreciate to your answer. But... It's already done. and... I said I cannot use 'mv' command. I maybe solved that question using 'link' system call. Thank you for your answer.Melcher
H
2

If you just want to rename the folder(not moving file to different folder) use below command.

mv oldFolderName newFolderName

Hoary answered 30/4, 2021 at 5:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.