Linux Commands - xargs (convert stdin to an argument)

by
Jeremy Canfield |
Updated: March 09 2020
| Linux Commands articles
Let's say you have a few files in the PWD.
[user1@server1 ]# find . -name "*file*"
./file1
./file2
./file3
xargs will put the output inline.
[user1@server1 ]# find . -name "*file*" | xargs
./file1
./file2
./file3
Let's say we have a directory with a variety of files.
[user1@server1 ]# find . -name "*"
./file1
./file2
./file3
./test1
./test2
./test3
./sample1
./sample2
./sample3
Let's say we want to remove files in the PWD that contain the word "test."
[user1@server1 ]# find . -name "*test*" | xargs rm
Now if we view the directory again, we can see all the files that contain "text" have been removed.
[user1@server1 ]# find . -name "*"
./file1
./file2
./file3
./sample1
./sample2
./sample3
Did you find this article helpful?
If so, consider buying me a coffee over at