Categories
Linux Tutorial Series

Linux Tutorial Series – 73 – The xargs command

Here is the video version, if you prefer it:

Let’s talk about the xargs command. The xargs command is used to accept input from the standard input and then converting it into an argument list for a specified command. (Shotts, 2019)⁠

Let’s look at an example:

mislav@mislavovo-racunalo:~/Linux_folder$ find /home -name 'ab*' -print | grep Linux_folder | xargs ls -l

-rw-r--r-- 1 mislav mislav 12 Feb 5 22:48 /home/mislav/Linux_folder/ab2.txt

-rw-r--r-- 1 mislav mislav 63 Jan 13 05:17 /home/mislav/Linux_folder/aba.txt

-rw-r--r-- 1 mislav mislav 0 Jan 11 23:00 /home/mislav/Linux_folder/aba.txt~

-rw-r--r-- 1 mislav mislav 12 Jan 13 05:17 /home/mislav/Linux_folder/ab.txt

-rw-r--r-- 1 mislav mislav 0 Jan 11 23:00 /home/mislav/Linux_folder/ab.txt~

Here I use find and grep to find files starting with ab in my Linux_folder. Then I use xargs to use those results and pass it to ls -l so that I get the long listing of each of the resulting files.

I have almost never had the need to use xargs. I only used it once or twice as a part of the “use Google to find a solution to your problem”. In that way, it is immensely useful to know what xargs does.

Hope you learned something useful!

References

Shotts, W. (2019). The Linux Command Line, Fifth Internet Edition. Retrieved from http://linuxcommand.org/tlcl.php. Pages 252-253

NewsletterUpdates on interesting things I am doing

Subscribe to my newsletter to keep abreast of the interesting things I'm doing. I will send you the newsletter only when there is something interesting. This means 0% spam, 100% interesting content.

Leave a Reply

Your email address will not be published.