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/
Let’s try the
cp command out in our environment.
In a single command, navigate to the drama/biopic/ directory. Keep in mind that we’re now back in the top-most
Then, list all files and directories in the working directory using
Using a single
cp command, copy all the contents of frida.txt to lincoln.txt.
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
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.
and 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
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.