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
mv
CommandYou 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
tonew_name
in your current working directory, you can simply use the following command:The
-T
option generates an error if the directorynew_name
already exists at that location.For example, if your current working directory is
/var/www
and you want to rename the directory namedsample
inside 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
cd
command.