Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps!

We spend hours on Instagram and YouTube and waste money on coffee and fast food, but won’t spend 30 minutes a day learning skills to boost our careers.
Master in DevOps, SRE, DevSecOps & MLOps!

Learn from Guru Rajesh Kumar and double your salary in just one year.


Get Started Now!

Linux Tutorials: xargs commands examples

xargs-commands

xargs-commands

Under Development

The xargs command is extremely useful when we combine it with other commands.This tutorials explains the usage of xargs command using few simple examples.
1. Xargs Basic Example
The xargs command (by default) expects the input from stdin, and executes /bin/echo command over the input. When you execute xargs without any argument, or when you execute it without combining with any other commands. you get Welcome message
> xargs
Hi,
Welcome to TGS.Hi, Welcome to TGS.
After you type something, press ctrl+d, which will echo the string back to you on stdout as shown below.
2. Specify Delimiter Using -d option
Delimiters can be applied so that each character in the input is taken literally using -d option in xargs.In the following example, when you use the -d\n, it will preserve newline delimiter in the output, and display the output exactly as it was typed.
> xargs -d\n
Hi,
Welcome to TGS.
3. Limit Output Per Line Using -n Option
By default as explained earlier, xargs displays whatever comes to its stdin as shown below.
> echo a b c d e f| xargs
a b c d e f
> echo a b c d e f| xargs -n 3
a b c
d e f
In the following example, we used -n 3, which will display only 3 items per line in the xargs output.
4. Delete Files that has White-space in the Filename
> find . -name “*.c” -print0 | xargs -0 rm -rf
Example
# fild /usr/preserve –mtime +30 –exec rm –f {} \;
is equivalent to….
# find /usr/preserve –mtime +30 –print | xargs rm –f
# find /usr/preserve –size +1024 –print | xargs –n20 rm –f
Subscribe
Notify of
guest
0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments

Certification Courses

DevOpsSchool has introduced a series of professional certification courses designed to enhance your skills and expertise in cutting-edge technologies and methodologies. Whether you are aiming to excel in development, security, or operations, these certifications provide a comprehensive learning experience. Explore the following programs:

DevOps Certification, SRE Certification, and DevSecOps Certification by DevOpsSchool

Explore our DevOps Certification, SRE Certification, and DevSecOps Certification programs at DevOpsSchool. Gain the expertise needed to excel in your career with hands-on training and globally recognized certifications.

0
Would love your thoughts, please comment.x
()
x