You can use the mv command to rename a folder or directory via command line in Ubuntu.
For instance, if you want to rename the directory current_name to new_name in your current working directory, you can simply use the following command:
mv -T current_name new_name
The -T option generates an error if the directory new_name already exists at that location.
For example, if your current working directory is /var/www and you want to rename the directory named sample inside of it to sample_new, you can simply use the command:
mv -T sample sample_new
Alternatively, you can provide absolute path like this:
mv -T /var/www/sample /var/www/sample_new
Both commands will have the same effect, because current working directory doesn't matter when you use absolute path. Any path that starts with a forward slash / is an absolute path.
Tip: The current working directory is the directory or folder where you are currently working. To change the current working directory, you need to use the cd command.
Use the
mvCommandYou can use the
mvcommand to rename a folder or directory via command line in Ubuntu.For instance, if you want to rename the directory
current_nametonew_namein your current working directory, you can simply use the following command:The
-Toption generates an error if the directorynew_namealready exists at that location.For example, if your current working directory is
/var/wwwand you want to rename the directory namedsampleinside of it tosample_new, you can simply use the command:Alternatively, you can provide absolute path like this:
Both commands will have the same effect, because current working directory doesn't matter when you use absolute path. Any path that starts with a forward slash
/is an absolute path.Tip: The current working directory is the directory or folder where you are currently working. To change the current working directory, you need to use the
cdcommand.