Shorter post today – I wanted to share how to rename a file in Linux.
This post is also on Medium!
Introduction
Renaming files in Linux isn’t really a thing. You don’t directly rename a file like you do in Windows.
Instead, you move the file and simply provide a new name.
How To Rename A File In Linux
So to rename a file in Linux, you can use the move (mv) command. You can see an example of this below:
mv /dir/old-filename.txt /dir/new-filename.txt
That’s it!
How To Rename A Dir In Linux
If you want to know how to rename a directory in Linux – you can use the below example:
mv /dir/old-dir /dir/new-dir
Since we are still using the mv command, you can use the same options below.
Move Command Options
The move command also has a number of options – I will leave these below:
- -i : This stands for interactive and it is used to prompt the user prior to overwriting the existing file
- -u : This stands for update and it’s used to only move the file if the source is newer than the destination or if the destination file is missing
- -v : This is the verbose option and it’s used to display the file names as they are moved
- -n : This stands for no clobber and it prevents an existing file from being overwritten