- If your AI-generated code becomes faulty, who faces the most liability exposure?
- These discoutned earbuds deliver audio so high quality, you'll forget they're mid-range
- This Galaxy Watch is one of my top smartwatches for 2024 and it's received a huge discount
- One of my favorite Android smartwatches isn't from Google or OnePlus (and it's on sale)
- The Urgent Need for Data Minimization Standards
Lesser-known xargs command is a versatile time saver
First, the xarg command’s basic function is pretty simple. It echoes what you toss at it. In a sense, it’s not very different from echo, except that content needs to be redirected to it, not presented as an argument.
$ echo a b c
a b c
$ echo a b c | xargs
a b c
Obviously, nothing is gained in the example above. The pipe and the use of xargs are just making the command more complex and a bit more time-consuming. But the command does illustrate how xargs takes each string that is passed to it and repeats it.
In the example below, we just type xargs and then hit enter. Then we type some text. I typed control-d after the text and pressing the enter key. You won’t see the control-d (^d), of course, but I included it below to show where it was entered. The xargs command displays the text again. You could enter as many lines of text as you cared to and all would be repeated after the control-d.
$ xargs
Hello, World!
Goodbye for now.
^dHello, World! Goodbye for now.
In a similar fashion, if you need to have the contents of a simple file show up on a single line, basically flattening the file, xargs will comply with your wishes.
First, the file:
$ cat data
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Then the flattening of its contents with xargs: