Creating, copying, moving, deleting and wildcards
You build folder trees and file series in one command with brace expansion, copy with cp’s -a, -n, -i, -u options keeping times and without overwriting, use every form of wildcard ([ ], [! ], ?, extglob), fix names with spaces in a loop and pick up safe deletion habits; at the end you move the files in a given range and archive the reports. The range differs in every lab.
Level 101 · 50 min
The /srv/drop folder on the file server has been everyone’s dumping ground for years: reports, hundreds of images, backups, names with spaces, leftovers ending in .bak and ~. Daniel wants order, on one condition: "Lose nothing, don’t spoil any file’s date, don’t overwrite anyone’s changes."
In this lesson you will tell apart two powerful shell features: brace expansion ({a,b}, {1..10}) produces text without checking whether it exists; wildcards (*, ?, [ ]) match existing file names. The figure shows the difference.
Remember: the shell expands patterns before the command runs. Seeing what a pattern you give rm selects, with ls or echo first, is the most valuable habit you’ll gain in this lesson.
What you will do in this lesson
- A folder tree in one command
- Series: {01..12}
- Copy keeping the time: cp -a
- Don’t overwrite: cp -n
- Every form of wildcard
- Extended patterns: extglob
- Fix the names with spaces
- A safe clean-up
- Move a given range
- Archive the reports
- Short quiz
Skills you will earn
- Creating nested directories (mkdir -p)
- Generating series and trees with brace expansion ({a,b}, {1..10})
- Keeping evidence with its time and permissions (cp -p)
- Copying safely with cp -a, -n, -i, -u
- Using selective patterns (?, [1-3])
- Extended patterns (extglob, !(…))
- Moving files (mv)
- Quoting rules and names with special characters
- Deleting safely after trying with ls (rm)
- Previewing before deleting with a pattern
← Knowing your files: ls, hidden files, types · Linux fundamentals · Links and finding files →
Start for free