Deleting, Writing and Editing
Delete without regret, write and add to files from the terminal, edit a file in the terminal, and watch a file grow.
Updated
Deleting
- Deleting Safely: rm and rmdir (Novice): rm deletes files for good, with no trash can to undo it, so you check the same names with ls first, let rm -i ask about each file, and use rmdir for empty folders and rm -r only after looking inside.
Writing
- Writing to Files: echo, > and >> (Novice): echo prints a line of text, > (read "into") sends it into a file and replaces whatever the file had, >> (read "add to") adds it to the end, and printf writes neat lines from a pattern.
- Editing in the Terminal: nano (Novice): nano is a text editor that runs inside the terminal, where you open a file with nano and its name, move with the arrow keys, save with Ctrl+O and quit with Ctrl+X; and if vim opens by accident, Esc and then :q! get you out.
Watching
- The Start and End of a File: head and tail (Apprentice): head prints the first lines of a file and tail the last, ten unless -n says how many, and tail -f keeps watching a file and prints each new line as it's added.
Exercise: The Moving-Day List
- Exercise: The Moving-Day List (Apprentice): Finish a new apartment's moving-day jobs in the terminal, deleting the trash safely, removing an empty box, writing a door sign and a to-do list, fixing a setting in nano and reading the ends of long files, then let a check script tell you what's done.