Let’s move on to copying, moving, and removing files and directories from the command line. The cp
command copies files or directories. Below, we copy the contents of a source file into a destination file:
cp source.txt destination.txt
We could also copy a file to a destination directory:
cp source.txt destination/
Instructions
For this exercise, we need to start in the drama/biopic directory. Use pwd
to check where you are. If you aren’t in the drama/biopic directory, you can use the command cd /home/ccuser/workspace/movies/drama/biopic
to quickly get there. As you move to the correct file path, ignore any errors that pop up.
Then, list all files and directories in the working directory using ls
.
Using a single cp
command, copy all the contents of frida.txt to lincoln.txt.
Use cat
on lincoln.txt to confirm that the information about Frida Kahlo has been copied into the lincoln.txt file.
To clear the terminal of the text after its output, use the clear
command.
Great job! You just copied the contents of a file using the command line!
Now, let’s navigate one level up to the drama/ directory, then list all files and directories in the working directory.
In a single command, make a copy of cleopatra.txt to go into the historical/ directory.
Pay attention to your current position, which you can always access using the command pwd
.
List all files and directories in the historical/ directory without changing the working directory. You should see a new copy of cleopatra.txt in this directory.