Kudos to Distro Tube for coming up with numerous useful commands and utilities. If by any chance you do not yet know how to use xargs, this is a very useful video to watch.
I was introduced to xargs about 20 years ago, and could NOT imagine not having that in my toolbox.
xargs is meant for applying a command consecutively to an entire list of items that come via the input stream, such as the output of a
âfind -printâ command.
In my opinion, the best form is
xargs -I{} ${command} '{}'
# for example:
xargs -I{} file '{}'
xargs -I{} chown -v -h ${Owner} '{}'
xargs -I{} stat --format "%n|%A|%U|%G|%s|%Y|%Z|%F" '{}'
The single quotes around the last set of braces ensures proper handling of filenames that have spaces.
When performing such âbulkâ operations, keep in mind that some filenames may include single quotes. You have to build in a logic to split those items off into a separate list before attempting the xargs, and use the double quotes for those cases. Just make sure those same cases donât also include double quotes by some strange quirk of circumstances.
![]()
Iâve used xargs on occasion but for the things I usually do it is a bit too limited. Especially when you want to conditionally start each thread.
I often make a liberal usage of â&â instead, although it linguistically lacks some elegance. ![]()
Thatâs why I wrote a small âframeworkâ for âprocess oriented programmingâ.
It takes care of the process handling (and IPC) which enables a clean syntax for parallel and multi processing
xargs is definitely a valuable tool to have in your toolbox. The only thing Iâd add is that these days I try to default to find ⊠-print0 | xargs -0 ⊠for bulk operations, as it safely handles filenames containing spaces, quotes, and other unusual characters.
Itâs one of those classic Unix utilities that remains incredibly useful when used with the right safeguards.
My command line toolbag consists of:
sudo apt-get update
sudo apt-get dist-upgrade
pkill
sudo apt --fix-broken install (I copy and paste this one, but find it the most essential command in case an upgrade gets interrupted).
The rest I use a GUI for, and if in really serious trouble I have a cheat sheet I can copy and paste from. LOL
From a DistroWatch Poll:
How many command line shells do you use regularly?
|Zero:|20 (4%)|
|One:|343 (73%)|
|Two:|67 (14%)|
|Three:|14 (3%)|
|Four:|5 (1%)|
|Five:|2 (0%)|
|More than five:|22 (5%)|
More proof you donât have to be a tech geek to use Linux!
I donât need xargs very often any more, but it has definitely come in handy many times over the course of my career. Who knows when it may come in handy again though? Itâs still in my personal âtoolchestâ.