Challenge: ship the café’s new menu
Put the Intermediate level together: back up with tar, fix a file with sed, cut a column, make a link and copy the result to a server with scp.
A friend runs a small café, and its menu has a spelling mistake that customers keep pointing out. The menu is a CSV file in ~/cafe, and the website on web (pretend, like the other machines here) shows whatever menu.csv is in your home folder there.
There's more than one right way to do each part, and the checklist only looks at the results. Things you'll need:
tar -czf NAME.tar.gz FOLDERpacks a folder, andtar -tzflists one;sed -i 's/OLD/NEW/g' FILEreplaces text in a file;cut -d, -f1takes a column, andtail -n +2drops a header line;ln -s TARGET NAMEmakes a link;scp FILE web:copies a file to web.
cat cafe/menu.csvCheck as you go with cat, ls -l and diff, and remember that Reset puts everything back the way it was.
Your turn
Ship the new menu: (1) before changing anything, back up the whole cafe folder as ~/cafe-backup.tar.gz; (2) change every Expresso in cafe/menu.csv to Espresso; (3) save the item names, one per line and without the header, as cafe/items.txt; (4) make a link ~/menu.csv that points to cafe/menu.csv; (5) copy the fixed menu to your home folder on web.
Your task
Ship the new menu: (1) before changing anything, back up the whole cafe folder as ~/cafe-backup.tar.gz; (2) change every Expresso in cafe/menu.csv to Espresso; (3) save the item names, one per line and without the header, as cafe/items.txt; (4) make a link ~/menu.csv that points to cafe/menu.csv; (5) copy the fixed menu to your home folder on web.
- cafe-backup.tar.gz holds the cafe folder, from before the fix (not done yet)
- menu.csv says Espresso everywhere (not done yet)
- cafe/items.txt lists the items (not done yet)
- ~/menu.csv is a link to cafe/menu.csv (not done yet)
- web has the fixed menu (not done yet)
The checklist ticks itself off as you work in the terminal: any way that gets the result counts.
Hints come one at a time, then one way to do it. Try each before the next.
What this lesson uses, in one place.
tar -czf- Make a new archive; compress (or uncompress) with gzip: .tar.gz; the archive file (put it right after the f) More on tar
sed 's/old/new/g'- Replace every old with new on each line (without g, only the first) More on sed
cut -d- Fields are separated by DELIM (one character) instead of a tab More on cut
ln -s- Make a symbolic link instead of a hard link More on ln
scp- Copy files to or from another machine More on scp
Every everyday command on one page: the Linux commands cheat sheet.