This lesson uses every command from the last two chapters. When you change many files, the order of the steps keeps your files safe.
1. Lookls -a, tree
2. Make the directoriesmkdir -p, braces
3. Movemv, with patterns that you check with echo
4. Renamemv old new
5. Copycp, cp -r
6. Delete, lastrm, rm -r
Why this order
- Look first. You cannot plan without knowing what is there. Use
ls -a, so that you also see hidden names. - Make the directories before you move.
mv *.txt notesneedsnotesto exist. If it does not,mvstops with an error when there is more than one file. With only one file,mvrenames that file tonotes. - Delete last. There is no trash. If something goes wrong in an earlier step, you have lost nothing yet.
Check each pattern
Before each mv or rm with a wildcard, run echo with the same pattern. Read the list. Then run the real line.
The commands so far
| Command | Does |
|---|---|
touch f | Make an empty file |
mkdir -p a/b | Make directories, also the missing ones above |
cp src dst / cp -r | Copy a file / a directory |
mv src dst | Move or rename |
rm f / rm -r d | Delete a file / a directory and everything under it |
rmdir d | Delete an empty directory |
* ? [ ] | Match names that exist |
{a,b} | Write out new names |