
The date/time stamp, owner, and permissions will all remain the same. When you move or rename a file, it will keep all of its original attributes except for the name and possibly the path if you put it in a new location. Does moving a file change its date or permissions? Unlike the cp (copy) command, where you need to specify that it copies recursively, the mv command will automatically move everything underneath the directory to the new directory location and name. Sudo mv OldFileName NewFileName If I move a directory, does it also move all the files inside of it? If your login has admin privileges, all you need to do is prefix the mv command with sudo and type in your password after hitting return. The file or directory could be owned by another user or by the root user. This can happen if you are not the owner of the file or directory. What if I see a permission denied error message? All you need to do is run the mv command with the following format.īelow are some questions I frequently hear people ask about renaming files using the mv command.

Let’s start with a simple renaming in which we are in the directory where the file exists, and we will just rename it right there in the same directory. Just substitute the directory name for the file name, and you will get the same results. It is just that the item usually remains in the same location, but it does not have to.Īs we go through the different scenarios below, I will use examples with a file, but renaming a directory would be the exact same command and process. We are moving it from one name to another. Of course, you can use this command to move a file or directory from one location to another, which is technically what we do when we rename it. We simply use the mv (move) command to rename a file or directory. When working from the command line, most old schoolers like me use the word directory, which we will use for the rest of this article.Īs I mentioned above, Mac’s Terminal application and its shell, Z shell, do not have a rename command.

