Linux Rename File Command

www.‮iruttual‬.com
Linux Rename File Command

To rename a file in Linux, you can use the mv command. This command is used to move files and directories, but it can also be used to rename them by moving them to the same directory with a new name.

For example, to rename a file named "oldfile.txt" to "newfile.txt", you can use the following command:

mv oldfile.txt newfile.txt

This will rename the file "oldfile.txt" to "newfile.txt". If the file "newfile.txt" already exists in the same directory, it will be overwritten by the renamed file.

You can also use the mv command to rename a file and move it to a different directory at the same time. For example:

mv oldfile.txt /path/to/new/directory/newfile.txt

This will move the file "oldfile.txt" to the directory "/path/to/new/directory" and rename it to "newfile.txt".

Keep in mind that the mv command can only be used to rename files within the same filesystem. If you want to rename a file on a different filesystem, you will need to copy the file to the new filesystem and then delete the original file.

You can use the cp command to copy the file and the rm command to delete it. For example:

cp oldfile.txt /path/to/new/filesystem/newfile.txt
rm oldfile.txt

This will copy the file "oldfile.txt" to the new filesystem and rename it to "newfile.txt", and then delete the original file from the original filesystem.

Created Time:2017-10-30 10:17:37  Author:lautturi