Learn

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

For example if we are in the scifi/ directory and want to make a backup of terminator.txt file we would run:

cp terminator.txt terminator.bak

This will make a copy of terminator.txt and save it as terminator.bak.

NOTE: The “.bak“ file extension is commonly used to notate a file as a backup of a file with the same name.

We could also copy a file to a destination directory:

cp source.txt directory

If we are in the comedy/ directory and wanted to put a copy of the-office.txt in the slapstick/ directory we would run:

cp the-office.txt slapstick

The above example will put an exact copy named the-office.txt in the slapstick/ directory.

If we wanted to rename the file as well, we would include the name in the path of the second argument:

cp the-office.txt slapstick/the-office-us.txt

Instructions

1.

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.

Then, list all files and directories in the working directory using ls (without any options).

Make sure to click the Check Work button once you’ve completed each checkpoint.

2.

While in the biopic/ directory, copy the file frida.txt to a file named frida.bak.

3.

Use cat on frida.bak to confirm that the information about Frida Kahlo has been copied into the frida.bak file.

Make sure to click the Check Work button once you’ve completed the task.

To clear the terminal of the text after its output, use the clear command.

4.

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.

5.

In a single command, make a copy of cleopatra.txt to go into the historical/ directory. Note that cleopatra.txt is in the biopic/ directorty.

Pay attention to your current position, which you can always access using the command pwd.

6.

Now move into the historical/ directory and list all the contents. You should see a new copy of cleopatra.txt in this directory.

Make sure to click the Check Work button once you’ve completed the task.

Sign up to start coding

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?