File operations: mkdir, cp, mv and rm
You tidy an inbox directory: create archive directories, copy and move invoices, copy a directory, use the three kinds of wildcard, and safely delete temporary files and an old backup; at the end you sort out the March invoices and the empty files on your own.
Level 101 · 45 min
The /srv/inbox directory on the accounting server is a mess: invoices, scanned documents, temporary upload files and an old backup nobody remembers. Daniel asks you to clean it up.
In this lesson you use four basic commands: mkdir (make a directory), cp (copy), mv (move or rename) and rm (remove). You will also learn the wildcards (*, ?, [ ]): they let one command pick many files.
Careful: on Linux a deleted file doesn’t go to a recycle bin, it is gone at once. That is why you will make a habit of looking at what you selected before you delete.
What you will do in this lesson
- Create the archive directories: mkdir -p
- Copy the January invoices: cp and *
- Move the February invoices: mv
- Rename: mv old-name new-name
- Copy a directory: cp -r
- More selective patterns: ? and [ ]
- Delete safely: ls first, then rm
- The March invoices
- Weed out the empty files
- Short quiz
Skills you will earn
- Creating nested directories (mkdir -p)
- Copying files (cp)
- Selecting files with a wildcard (*)
- Moving files (mv)
- Renaming a file (mv)
- Copying a directory with its contents and verifying it (cp -r, diff -r)
- Using selective patterns (?, [1-3])
- Deleting safely after trying with ls (rm)
- Deleting a directory with its contents (rm -r)
- Finding and cleaning empty files (find -empty)
← Moving around: pwd, cd and ls · Linux quick start · Reading and comparing content: cat, less and diff →
Start for free