Linux Labs

First steps / Stage 7 of 15

Creating and organising files

Not running Starting usually ~20 s
Leave the lesson

Step 3 of 10 · on a machine · 6 min

A copy: source and destination

The same cp notes.txt X can put the copy in three different places. Which one depends on what already goes by the name X.

cp copies a file. The first path is the source, what you copy. The last one is the destination, where it goes. The source stays put, and what happens to the destination depends on what already has that name:

What X is Result of cp notes.txt X
no such name a new file X, a copy of notes.txt
a directory a copy inside it: X/notes.txt
a file the contents of X replaced, no questions asked

A trailing slash on the destination works as a safeguard. cp notes.txt archive/ only works if archive is a directory. If it does not exist, cp fails with Not a directory and creates nothing.

With -i, cp asks before replacing a file: y replaces it, n keeps it. The -r option copies a directory with everything in it: cp -r config config.bak.

In the exercise you choose the commands.

Exercise · do it

Prepare a copy for handoff

In ~/file-lab, put a copy of source/site.conf into a new handoff/config directory under the same name. The original must stay where it is.

Sign in and start The machine is available after signing in

Goals · 0 of 2

  • Create the handoff/config directory not done yet
  • Copy site.conf there, leaving the original alone not done yet

Step goals

0 of 2
  • Create the handoff/config directory — not done yet
  • Copy site.conf there, leaving the original alone — not done yet
Ubuntu 24.04

Step goals

0 of 2
  • Create the handoff/config directory — not done yet
  • Copy site.conf there, leaving the original alone — not done yet
Loading…