mv command in Linux –
The mv stands for move. The mv command is used to move one or more files and directories from one place to another in Linux. It’s similar to
cp command in its usage, except
mv moves a file without making a copy.
To move a file into a directory, use
mv with the source file as the first argument and the destination directory as the second argument. Here we move my_file.txt into my_directory/.
mv my_file.txt my_directory/
Let’s use the ls command to see all the files and directories we have in our current folder.
Let’s say we want to move the test1.py file to the test directory.
mv test1.py test
To move multiple files into a directory, use
mv with a list of source files as the first arguments, and the destination directory as the last argument. Here, we move my_file_1.txt and my_file_2.txt into my_directory/.
mv my_file_1.txt my_file_2.txt my_directory/
Let’s move the test2.py and test3.py file to the test directory.
mv test2.py test3.py test
To rename a file, use
mv with the old file as the first argument and the new file as the second argument. By moving file_original.txt into file_renamed.txt, we rename the file as file_renamed.txt.
mv file_original.txt file_renamed.txt
Let’s rename the fact.py file to factorial.py
mv fact.py factorial.py