mv

mv linux command cheatsheet by Thamizhiniyan C S

Introduction

This command is used to move the files and directories from the source to destination. Also used for renaming files.


Syntax

mv [OPTION]... [-T] SOURCE DEST

mv [OPTION]... SOURCE... DIRECTORY

mv [OPTION]... -t DIRECTORY SOURCE...


Important Flags

FlagDescription

-b, --backup

Create a backup of files that will be overwritten or removed.

-f, --force

Overwrite destination files without prompting the user.

-i, --interactive

Prompt the user to confirm if the mv action should overwrite a file.

-S, --suffix=

Provide a suffix for a backup file. The default suffix is ~.

-u, --update

Perform the mv action only if the source file is newer or the destination file does not exist.

-v, --verbose

Show an output describing the action taken.

--help

Output the command help and exit.

--version

Show the command version and exit.


Examples

CommandDescription

Rename the file name1 to name2. The command produces no output, but ls confirms the operation was successful.

To move a file from one folder to another

To move an entire directory

Rename a file: Rename source_file_name to Destination_file_name. Overwrites Destination_file_name if it exists.

Renames filename2 to filename1. Overwrites filename1 if it exists.

Move a file: Move source_file_name(s) to Destination_path.

Moves filename1 to /home/user/test/.

Move multiple files: Move source_file_name_1, source_file_name_2, etc., to Destination_path.

Moves file_1 and file_2 to /home/user/test/.

Rename directory: Rename source_directory_name(s) to Destination_directory_name. Overwrites Destination_directory_name if it exists.

Renames test to new_file. Overwrites new_file if it exists.

Renames filename2 to filename1, prompts for confirmation if filename1 exists.

Move the files name1, name2, and name3 to test-dir in the home directory and show verbose output. The output confirms successful file movement.

Rename the file name1 to name2 and print the output. This command produces an output listing the performed actions.

Rename name1 to name2, prompting for confirmation if name2 already exists.

Forcefully renames file to filename1, overwriting filename1 if it exists.

Renames oldfile to newfile, does not overwrite newfile if it exists.

Renames first_file to second_file, creates a backup of second_file if it exists.

Displays the version of mv.

Loops through all the files with .24bes extension and removes the extension `.24bes`.

Last updated