The mv
command moves files. It’s similar to cp
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/
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/
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_origin.txt file_renamed.txt
Note that you can access the layout of the filesystem here.
Instructions
For this exercise, we need to start in the action/ directory. Use pwd
to check where you are. If you aren’t in the action/ directory, you can use the command cd /home/ccuser/workspace/movies/action
to quickly get there.
After moving into the action/ directory, list the contents.
Move the file superman.txt into the directory superhero/.
In a single command, list all the files and directories in the superhero/ directory. You should now see superman.txt in it.
Now let’s move multiple files at the same time!
Move both wonderwoman.txt and batman.txt to the superhero/ directory.
Again, list all the files and directories in the superhero/ directory. You should now see wonderwoman.txt and batman.txt in it.
Using mv
, rename the file superhero/batman.txt to superhero/spiderman.txt.
Remember to use the relative path of the files.
Let’s use the clear
command to clean up before we run this last command.
After that, list all the files and directories in the superhero/ directory. You should now see spiderman.txt in place of batman.txt.