Renaming files and directories

Renaming files and folders

How to rename a file from terminal in Linux?

Using vifm

vifm (a tool that works with vim shortcuts) is an alternative to this. Using vifm, we can change the name of a file or folder using `cw` (change word).

Other options:

In order to rename a file in Linux you can use either of two approaches

Copy the existing file with a new name and delete the old file

  1. Create a copy of the existing file with the new desired name and then delete the old file.
    $ cp oldfile newfile
    
    This creates a copy of the same file with a new name in the same location.
    $ rm oldfil
    
    This will delete the old file keeping the newfile intact.

Using mv command

  1. Rename a file by moving it with the mv command.

    Rename by moving

    $mv old-file-name  new-file-name
    

    This just moves the old file, to a new name.

  2. Rename a directory on Linux, use the mv command and specify the directory to be renamed as well as the destination for your directory.

    mv <source_directory> <target_directory>
    

Links to this note