>_ IzzyLab

Hands-on task

This task is step 21 of the course “Linux: everyday tasks”

Create files from a list of names via xargs -I

medium~5 min

The file /root/names.txt contains a list of service names, one per line: alpha, bravo, charlie. For each one, create an empty config /root/out/<name>.conf (the /root/out directory already exists). Use xargs with name substitution into a command template.

What you'll practise:
  • xargs
  • -I
  • argument substitution
  • reading from a file

Topic breakdown

By default xargs glues all arguments onto the tail of the command, but often the value needs to be inserted into a specific place in the template. For this you set a placeholder with the -I flag (usually -I{}): each input line is substituted in place of {}, and the command is run once per line. The list of values is supplied to standard input, for example from a file.

What's checked

  1. configs created from the template

What it looks like