Renaming a file with the Linux command line.

This is a short beginners guide on how to rename a file using the Linux command line.

The mv command.

To rename a file on Linux, you need to use the “mv” command. “mv” stands for move, which is what you are essentially doing when you decided to rename a file.

Let’s say for example that you want to rename a file called “error.log” as “error.log.old”:

The command above will move error.log to error.log.old.

The interactive option.

As an added safeguard against accidentally overwriting existing files, you can use the “-i” option. This “interactive” option will ask you if want to overwrite any existing files, regardless of what permissions they have:

If “error.log.old” already exists, you will be asked if you want to overwrite it or not. This may help to prevent a situation where you overwrite a file that you do not want to overwrite.

Using full paths.

Finally, here is an example of the mv command being used with full paths:

Hopefully, you found this short post useful.

Facebook Comments