Advanced Terminal Exercises
Objectives
This chapter introduces no new commands — it’s a chance to put Module 4 together: cut, sed, awk, xargs, shell scripting, and Vim.
Part I — Text Processing
Use the following file to answer these questions:
Owen-Baker-sushi
Maya-Fields-gummybears
Noah-Reyes-bagels
Priya-Chen-tacos
Leo-Hughes-pizza
- Replace every
-with:, usingsed. - Produce a file with just the first and last name, separated by a space (you can do this with
cutandsed, or withsedalone).
Given the following mapping:
1 >>>> 2
2 >>>> 3
3 >>>> 4
4 >>>> 5
- Using
cut, print out just the numbers 2, 3, 4, and 5. Usexargsto print them all on one line. - In the
~/Desktopdirectory, usefindpiped intoxargsto locate every file containing the text “Welcome”.
Part II — Scripting and Awk
- Write a shell script called
access_file.shthat accepts one argument and changes that file’s permissions to755. - Write a shell script called
restrict_file.shthat accepts one argument and changes that file’s permissions to300. - Using
sed, write the command to replace every instance of “foo” with “bar” in a file calledbaz.txt. - Using
awk, write the command to print only the PIDs fromps aux. - Run
df -hto see your available disk space, then useawkto print out only the first percentage-capacity value.
Recap
You can now connect to a remote server over SSH, slice and reshape text with cut, sed, and awk, batch-process files with xargs, and write your own shell scripts — the last core skills for working like a professional in Terminal.
That’s the whole course. From navigating a filesystem in Module 1 to scripting and remote servers here in Module 4, you now have the everyday toolkit most developers rely on constantly. The best next step is using it — the more of this you do for real, the faster it becomes second nature.