Convert stdin to an argument using the XARGS command in Linux

Home > Search > Linux commands
  by

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

 



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




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




Comments