File handling using the mv command (moving and renaming)
The mv or move command is used when we wish to move files from one directory to another, and we don't want to create duplicates while doing this (something that happens when using the cp
command).
Getting ready…
Since mv
is a built-in command of Linux, we don't have to configure anything else to understand how it works.
How it works…
On every Linux system, this command is installed by default. Let's take a look at how to use the mv
command by taking different kinds of examples:
- To move the
testfile1.txt
file from the current directory to any other directory, such ashome/practical
/example
, the command is as follows:mv testfile1.txt /home/practical/example
The preceding command will work only when the location of the source file is different from the destination.
When we move the file using the preceding command, the file will get deleted from the previous location:
- To move multiple files using a single command...