Bootstrap FreeKB - Linux Commands - xargs (convert stdin to an argument)
Linux Commands - xargs (convert stdin to an argument)

Updated:   |  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 Buy Me A Coffee



Comments


Add a Comment


Please enter 7cbd04 in the box below so that we can be sure you are a human.