Code / Command Line & Git / Unit 2: Making & changing files

Copy, move and delete कॉपी, मूव और डिलीट

Lesson 5 of 12 · about 15 minutes · cp, cp -r, mv to move or rename, rm, rm -r and rmdir.

⚡ 0 XP

Step 1 of 3

cp: make a copy

cp from to copies a file: cp menu.txt menu-backup.txt.

Folders need -r (recursive, meaning "everything inside too"): cp -r shop shop-backup.

A backup before a big change is a habit every developer should have. (Git, coming soon, is the super-powered version of this!)

Example
cp marks.txt marks-old.txt
ls

🎯 Challenge: Back up the shop +15 XP

Two backups, please:

  1. Copy shop/menu.txt to shop/menu-backup.txt.
  2. Copy the whole shop folder to a new folder shop-backup in your home (use cp -r).

Try twice to unlock the solution (0/2)

terminalCtrl ⏎

A safe practice terminal. Type a command and press Enter. Type help to list commands. Tab completes names, ↑ recalls the last command.

Files · ~ = /home/asha
  • shop/
  • menu.txt
  • photos/
  • stall.jpg
Git timeline

No git repository yet. Start with git init.

Checklist

Press Run to check your code.

  • shop/menu-backup.txt is a copy of the menu
  • ~/shop-backup has the photos too
  • You used cp -r
Lesson notes (text version)

1. cp: make a copy

cp from to copies a file: cp menu.txt menu-backup.txt.

Folders need -r (recursive, meaning "everything inside too"): cp -r shop shop-backup.

A backup before a big change is a habit every developer should have. (Git, coming soon, is the super-powered version of this!)

                cp marks.txt marks-old.txt
ls
              

Challenge: Back up the shop

Two backups, please:

  1. Copy shop/menu.txt to shop/menu-backup.txt.
  2. Copy the whole shop folder to a new folder shop-backup in your home (use cp -r).

2. mv: move or rename

mv does two jobs with one command:

  • Rename: mv IMG_0042.jpg rangoli.jpg (same folder, new name).
  • Move: mv rangoli.jpg photos/ (the destination is a folder, so the file goes inside it).

Unlike cp, the original is gone afterwards — it moved!

Challenge: Tidy the rangoli photo

Your phone saved IMG_0042.jpg in your home. Rename it to rangoli.jpg with mv, then move it into the photos folder. In the end only ~/photos/rangoli.jpg should exist.

3. rm: delete (carefully!)

  • rm junk.txt deletes a file.
  • rm -r old-project deletes a folder and everything inside it.
  • rmdir empty-box deletes a folder only if it is empty (a safe choice).

Warning: on a real computer, rm does not use a Recycle Bin. Deleted means gone. Always ls first and read your command twice before pressing Enter. Here in practice mode, nothing real can be harmed.

Challenge: Spring cleaning

Clean your home folder:

  • delete the file junk.txt with rm
  • delete the folder old-project (it has files inside) with rm -r
  • delete the empty folder empty-box with rmdir

Do not touch the keep folder.

Search by task, format or tool name.