Creating and organizing files
On this page
Your notes are in ~/lab/Documents, but you need a separate place for a project: a working note, an empty checklist, and a directory for drafts. You want to keep the original notes intact.
By the end, you can build that workspace, copy a small directory, and move or rename files. You can also stop before a command replaces a file you meant to keep.
Before you start
Section titled “Before you start”Finish Practice: Navigating the Filesystem (B05). Keep the existing ~/lab from B04.1’s setup; do not recreate its files.
Before starting, take a VM snapshot named Before B06.1, following B02.4. Restoring that snapshot also discards other VM changes made since it. The scoped Reset this lesson is the lighter option for repeating this lesson. Keep all work here disposable.
Add only the B06 working directory:
cd ~/labmkdir -p b06cd b06pwd/home/learner/lab/b06You met mkdir -p in B04.1: it creates directories, including missing parents, and accepts directories that already exist. Here it adds only b06. cd b06 makes that your current directory. Every remaining command runs in ~/lab/b06; ../Documents/notes.txt reaches the existing note one level above, without changing it.
Give the project a place
Section titled “Give the project a place”mkdir projectNo output means mkdir created the directory without reporting a problem. Check the name in your prompt before continuing: relative paths start there.
Put a copy of the note inside it:
cp ../Documents/notes.txt project/cp copies. Its first path is the source, what you copy from. Its second is the destination, where the copy goes. Because project is an existing directory, the copy keeps the name notes.txt. The source stays in Documents.
Give the working copy a name that describes its job:
mv project/notes.txt project/plan.txtls projectplan.txtmv moves a source to a destination. Here both paths have the same parent, so it renames the file. There is no longer a notes.txt inside project; there is a plan.txt. The original ../Documents/notes.txt remains.
learner@rootvolt:~/lab$ cd b06learner@rootvolt:~/lab/b06$ mkdir projectlearner@rootvolt:~/lab/b06$ cp ../Documents/notes.txt project/learner@rootvolt:~/lab/b06$ mv project/notes.txt project/plan.txtlearner@rootvolt:~/lab/b06$ Files ~/lab/b06
- ~
- lab/b06/cwd
- project/
- plan.txtcreated-rw-r--r--
Steps (8)
- Type
cd b06 - Press Enter
- Type
mkdir project - Press Enter
- Type
cp ../Documents/notes.txt project/ - Press Enter
- Type
mv project/notes.txt project/plan.txt - Press Enter
Watch project appear, then notes.txt inside it. On the rename step, the old name is marked removed and the destination created. These are name changes, not two copies. The static transcript and final tree show the same outcome: project contains only plan.txt.
Create the missing parents
Section titled “Create the missing parents”You want a directory for the first day’s drafts. Guess first: does this create both drafts and day1?
mkdir project/drafts/day1Run it, then compare with your guess
mkdir: cannot create directory ‘project/drafts/day1’: No such file or directorymkdir names the full path, but its parent project/drafts does not exist. Without -p, it does not create missing parents.
mkdir -p project/drafts/day1mkdir -p project/drafts/day1ls -R project/draftsproject/drafts:day1
project/drafts/day1:The first line creates the missing directories. The second succeeds silently too: -p accepts an existing directory. ls -R, from B04.3, lists the directory and its subdirectories. Nothing follows the day1: heading because it is empty.
Make an empty file, or update its times
Section titled “Make an empty file, or update its times”touch project/checklist.txtls -l project/checklist.txt-rw-r--r-- 1 learner learner 0 Nov 11 08:23 project/checklist.txtThe size before the date is 0: there is no content. When its path does not exist, touch creates an empty file. It does not open an editor or ask you to type text.
Guess first: does touch also empty a file that already contains text? Read the note’s modification time, run touch, then check again:
ls -l --full-time project/plan.txttouch project/plan.txtls -l --full-time project/plan.txtcat project/plan.txtRun it, then compare with your guess
-rw-r--r-- 1 learner learner 40 2026-11-11 08:23:12.944446467 +0000 project/plan.txt-rw-r--r-- 1 learner learner 40 2026-11-11 08:23:18.533475384 +0000 project/plan.txtBuy printer paperRenew lab VM snapshotThe time changed; the size and text did not. For an existing file, touch updates its access and modification timestamps, the recorded times for reading and changing it. It does not empty the contents. ls -l shows modification time; --full-time includes seconds and finer detail so you can see this short interval.
Your timestamps and time zone will differ. The Files panel does not track timestamps, so touching an existing file produces no change mark there. The terminal metadata above shows the change.
Read the destination before you run
Section titled “Read the destination before you run”An existing directory and an unused filename mean different things:
cp ../Documents/notes.txt project/reference.txtcp project/plan.txt project/drafts/ls project/draftsday1 plan.txtThe first destination is an unused filename, so the copy is called reference.txt. The second is an existing directory, so the copy keeps plan.txt. A trailing / makes your directory intent clear; it does not create the directory.
Move the reference into the drafts:
mv project/reference.txt project/drafts/reference.txtls projectls project/draftschecklist.txt drafts plan.txtday1 plan.txt reference.txtCopying left the source in place. Moving removed its old name. mv can change the directory, the filename, or both. Unlike cp, mv moves a whole directory without -r, because it changes where the name points instead of copying the contents.
To copy the small drafts directory, first see what plain cp does:
cp project/drafts archivecp: -r not specified; omitting directory 'project/drafts'The message says the source is a directory. Add -r, for a recursive copy: copy the directory, its contents, and directories inside it.
cp -r project/drafts archivels -R archivearchive:day1 plan.txt reference.txt
archive/day1:Because archive did not exist, it becomes the copy of drafts. If archive already existed as a directory, the copy would go inside it as archive/drafts. Check first rather than assuming the same command always makes the same layout.
Stop before replacing content
Section titled “Stop before replacing content”Both cp and mv can overwrite an existing destination file. You can lose the version previously available at that path. Learn the safeguard first. -i means interactive: ask before overwriting.
cp -i ../Documents/report.txt project/plan.txtcp: overwrite 'project/plan.txt'?The command is waiting for your answer, not another shell command. Press Ctrl+C to cancel, as in B03.4. Then check:
cat project/plan.txtBuy printer paperRenew lab VM snapshotThe notes remain. mv -i provides the same kind of safeguard when moving or renaming onto an existing file.
cp ../Documents/report.txt project/plan.txtcat project/plan.txtQuarterly lab reportThe report replaced the working note. The command succeeded silently, so silence alone cannot tell you whether a destination was safe.
Mistakes to recognize
Section titled “Mistakes to recognize”Creating an existing directory without -p.
mkdir projectmkdir: cannot create directory ‘project’: File existsFile exists names a collision. Here it is a directory; you do not need to create it again. -p accepts that directory, but cannot turn an existing regular file into a directory.
A misspelled source.
cp ../Documents/missing.txt project/cp: cannot stat '../Documents/missing.txt': No such file or directorycannot stat means cp could not inspect that source. Read the ending: no file has that path. Check the spelling with ls or Tab. Changing the destination does not fix a missing source.
Try it yourself
Section titled “Try it yourself”Goal: Prepare a handoff with a backup taken before a rename.
Inside ~/lab/b06, create handoff/source. Copy the original Documents/report.txt into it and add an empty ready.txt. Copy the whole source directory to the unused name handoff/backup. Then rename only the source’s report to summary.txt.
Expected: The backup keeps report.txt; the source has summary.txt. Both contain the report text, and each directory has an empty ready.txt.
Hint
Create missing parents with -p. Copy the directory before renaming its report. From b06, the original report is ../Documents/report.txt.
Solution
mkdir -p handoff/sourcecp ../Documents/report.txt handoff/source/touch handoff/source/ready.txtcp -r handoff/source handoff/backupmv handoff/source/report.txt handoff/source/summary.txtls -R handoffhandoff:backup source
handoff/backup:ready.txt report.txt
handoff/source:ready.txt summary.txtcat handoff/backup/report.txtcat handoff/source/summary.txtQuarterly lab reportQuarterly lab reportEach cat prints the same line. Renaming the source did not rename the independent backup.
Reset this lesson
Section titled “Reset this lesson”Use this after finishing, or after stopping partway through. First return to ~/lab/b06 and inspect only this lesson’s three directories:
cd ~/lab/b06ls -AR project archive handoff-A includes hidden entries; -R lists subdirectories. After the solution, the captured listing is:
archive:day1 plan.txt reference.txt
archive/day1:
handoff:backup source
handoff/backup:ready.txt report.txt
handoff/source:ready.txt summary.txt
project:checklist.txt drafts plan.txt
project/drafts:day1 plan.txt reference.txt
project/drafts/day1:If you stopped earlier, you will see the files left at that point instead.
rm -r ~/lab/b06/project ~/lab/b06/archive ~/lab/b06/handoffWhen all three directories exist, it succeeds silently. If a directory is already absent, rm reports it and still removes the others. With project absent and the other two present, the captured message is:
rm: cannot remove '/home/learner/lab/b06/project': No such file or directoryRestart from Give the project a place. This reset leaves the B06 parent directory in place and preserves the other lessons’ work.
mkdircreates directories;-palso creates missing parents and accepts existing directories.touchcreates an empty file when none exists. On an existing file, it updates timestamps and preserves content.cpkeeps the source;mvremoves its old name. An existing destination directory receives the source’s name.cp -rcopies a directory and its contents. Check whether the destination already exists.cp -iandmv -iask before overwriting. Cancel if the named destination is one you need to keep.
Next, Removing files deliberately (B06.2) removes disposable files and directories while preserving your earlier work.