How to Move Files in Linux

How to Move Files in Linux bu using Linux Commands 

The "mv" command does one thing – it moves a file from one location to another. This can be somewhat misleading, because mv is also used to rename files. How? Simple.
Here’s an example. Say you have the file testfile in /home/amit/ and you want to rename it to testfile2 (while keeping it in the same location). To do this, you would use the mv command like so:

[root@amitmaheshwari.in] # mv /home/amit/testfile /home/amit/testfile2

or, if you’re already within /home/amit:

[root@amitmaheshwari.in] # pwd
/home/amit

[root@amitmaheshwari.in] # mv testfile testfile2

The above commands would move /home/amit/testfile to /home/amit/testfile2 – effectively renaming the file. But what if you simply wanted to move the file? Say you want to keep your home directory (in this case /home/amit) free from stray files. You could move that testfile into /home/amit/Documents with the command:

[root@amitmaheshwari.in] # mv /home/amit/testfile /home/amit/Documents/

With the above command, you have relocated the file into a new location, while retaining the original file name.

What if you have a number of files you want to move? Luckily, you don’t have to issue the mv command for every file. You can use wildcards to help you out. Here’s an example:

You have a number of .mp3 files in your ~/Downloads directory (~/ – is an easy way to represent your home directory – in our earlier example, that would be /home/amit/) and you want them in ~/Music. You could quickly move them with a single command, like so:

[root@amitmaheshwari.in] #  mv ~/Downloads/*.mp3 ~/Music/

That command would move every file that ended in .mp3 from the Downloads directory, and move them into the Music directory.

Should you want to move a file into the parent directory of the current working directory, there’s an easy way to do that. Say you have the file testfile located in ~/Downloads and you want it in your home directory. If you are currently in the ~/Downloads directory, you can move it up one folder (to ~/) like so:

[root@amitmaheshwari.in] #  mv testfile ../

The “../” means to move the folder up one level. If you’re buried deeper, say ~/Downloads/today/, you can still easily move that file with:

[root@amitmaheshwari.in] # mv testfile ../../

Just remember, each “../” represents one level up.