CodingNic

Advanced Terminal Commands

Advanced Terminal Exercises

Advanced Terminal Commands 15 min read

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:

text
Owen-Baker-sushi
Maya-Fields-gummybears
Noah-Reyes-bagels
Priya-Chen-tacos
Leo-Hughes-pizza
  1. Replace every - with :, using sed.
  2. Produce a file with just the first and last name, separated by a space (you can do this with cut and sed, or with sed alone).

Given the following mapping:

text
1 >>>> 2
2 >>>> 3
3 >>>> 4
4 >>>> 5
  1. Using cut, print out just the numbers 2, 3, 4, and 5. Use xargs to print them all on one line.
  2. In the ~/Desktop directory, use find piped into xargs to locate every file containing the text “Welcome”.

Part II — Scripting and Awk

  1. Write a shell script called access_file.sh that accepts one argument and changes that file’s permissions to 755.
  2. Write a shell script called restrict_file.sh that accepts one argument and changes that file’s permissions to 300.
  3. Using sed, write the command to replace every instance of “foo” with “bar” in a file called baz.txt.
  4. Using awk, write the command to print only the PIDs from ps aux.
  5. Run df -h to see your available disk space, then use awk to 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.