EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 600+ Courses All in One Bundle
  • Login

Linux Xargs

By Priya PedamkarPriya Pedamkar

Home » Software Development » Software Development Tutorials » Linux Tutorial » Linux Xargs

Linux Xargs

Introduction to Linux Xargs

In the Linux operating system, we are having multiple utilities to work on the streaming or live data. Xargs is one of the utility. It is used to capture the stream data from the standard input. After that, it will generate and perform the execution on arguments commands. In other words, we can say that it will get the previous command output as input to the next command. The output result will be useful for the next or arguments command.

As of GNU packages, we are getting the xargs version 4.2.X. The default behavior of the xargs tool or utilizes is not to have the logical end of file marker.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

Syntax

Linux Command [ OPTIONS ] [ FILE/DIRECTORY PATH ] | [ xargs ] [ OPTIONS ] [ LINUX COMMAND ]

  • xargs: We can use the “xargs” keyword in the syntax or command. It will take different arguments like options, Linux commands, etc. As per the provided arguments, it will pass the output data to the next command (as an input).
  • OPTIONS: We can provide the different flags as the option that is compatible with the “xargs” command.

How Linux Xargs Works?

The xargs are basically working on the input and output arguments. While working with the xargs utility, it will grab the previous command output and pass the same output as in input to the next command. As per the shared input to the next command, it will perform the execution of the command.

Below are the lists of option that are compatible with the xargs command.

Sr No Option Description
1 -0, –null Instead of by whitespace, the input items will terminate by a null character. With the help of this option, the quotes and backslash are not special.
2 -a file, –arg-file=file Instead of the standard input option, it will read items from the file. If we will use the same option then the stdin remains unchanged when the commands are running in the state.
3 -E eof-str It will help to set the end of file string to eof-str. The rest of the input may ignore. If the end of file string occurs as a line of input.
4 -e [eof-str], –eof[=eof-str] The same option is a synonym for the -E option. It is POSIX compliant while this option is not. There is no end of file string, if eof-str will omit.
5 -i [replace-str], –replace[=replace-str] The same option is a synonym for -Ireplace-str. If the argument is missing then the effect is the same as -I{}. But the option is deprecated, we need to use the option -I.
6 -L max-lines We need to use the same option while the most max-lines are nonblank input lines (as per the command line). The trailing blanks may cause an input line to be logically continued on the next input line.
7 -l [max-lines], –max-lines[=max-lines] The -l option is deprecated. IF we need to use the same option we need to use the “-L” Synonym. Unlike -L, the max-lines argument is optional.
8 -p, –interactive It will prompt the user level command. Whether to run each command line and read a line from the terminal. It will run in the verbose format. It will only run the input command if the user will share the response as “y” i.e. “yes”.
9 –process-slot-var=name It will help to set the environment variable value or name (the value will be unique) in each running process. Once the child process will exit, we can reuse the same value.
10 -r, –no-run-if-empty It will do not run the command if the standard input does not contain any nonblank. When there is no input then the command is run once. This option comes under the GNU extension.

Examples to Implement Linux Xargs

1. Linux Xargs Command

In the Linux environment, we are able to use the xargs command with the different operator.

Command :

ls *.jpg | xargs tar -cvzf img_jpg.tar.gz

Explanation :

As per the above command, we are listing the number of jpg images from the “/root/data” directory. Here, we are using the combination of multiple commands like ls, xargs, tar. With the help of xargs command, we are taking the list of files from the “ls” command and provide the same output files as an input to the tar command. Once the tar command will get the file, it will create the “img_jpg.tar.gz” tar file.

Output :

linux 1

2. Linux Xargs Command – Listing Lines/Words/Characters

In xargs command, we can list out the selected files in terms of lines, words, characters.

Command :

ls *.jpg | xargs wc

Explanation :

As per the above command, we are listing the number of jpg files and get the information of number lines, words, characters of sorted files.

Popular Course in this category
Kali Linux Training (3 Courses, 3+ Projects)3 Online Courses | 3 Hands-on Projects | 21+ Hours | Verifiable Certificate of Completion | Lifetime Access
4.5 (5,486 ratings)
Course Price

View Course

Related Courses
Linux Training Program (16 Courses, 3+ Projects)Red Hat Linux Training Program (4 Courses, 1+ Projects)

Output :

Linux Xargs 2

3. Linux Xargs Command: Remove Selected Files

In the Linux environment, we are able to use the xargs command to delete the specific set of files.

Command :

find. -name "*.png" | xargs rm -v -rf "{}"

Explanation :

As per the above command, we are listing the number of png images and creating tar file with the help xargs utility.

Output :

Linux Xargs 3

4. Linux Xargs Command – Read Input File

In the xargs command, we are having the functionality to read the file.

Command :

xargs -a text.txt

Explanation :

As per the above command, we are a list of files in the “/root/data” directory. With the help of xargs command, we are able to read the “text.txt” file. For reading the file, we need to use the “-a” option with the “xargs” command.

Output :

example 4

Conclusion

We have seen the uncut concept of “Linux Xargs” with the proper example, explanation, and command with different outputs. The xargs utility is use to get the outputs from the previous command and send the same output as an input to the next command. The xargs command or utility is majorly used in the shell/bash or application-level jobs.

Recommended Articles

This is a guide to Linux Xargs. Here we discuss the introduction, How Linux Xargs Works? and examples with code implementation. You may also have a look at the following articles to learn more –

  1. Linux Untar
  2. Linux Ping
  3. Vim Command in Linux
  4. Linux nslookup

All in One Software Development Bundle (600+ Courses, 50+ projects)

600+ Online Courses

50+ projects

3000+ Hours

Verifiable Certificates

Lifetime Access

Learn More

0 Shares
Share
Tweet
Share
Primary Sidebar
Linux Tutorial
  • Linux Commands
    • CAT Command in Linux
    • PS command in Linux
    • Mkdir Command in Linux
    • rmdir command in Linux
    • mv command in Linux
    • Linux rm Command
    • CHMOD Command in Linux
    • Zip Command in Linux
    • Linux Route Command
    • SCP Command in Linux
    • du Command in Linux
    • Less Command in Linux
    • Copy Command in Linux
    • Head Command in Linux
    • Help Command in Linux
    • Linux History Command
    • hostname Command in Linux
    • GREP Command in Linux
    • Linux Curl Command
    • Linux List Users
    • Linux List Directories
    • Linux Directory Permissions
    • Find Directory Linux
    • Linux User Permission
    • Linux Add User
    • Linux Delete User
    • Linux uniq
    • Linux Filter Commands
    • Linux sort Command
    • Linux Sort by Size
    • Remove dir Linux
    • Linux tr Command
    • Linux Touch Command
    • Linux More Command
    • Linux Cal Command
    • Linux OD
    • Linux Zcat
    • Linux tracepath
    • Linux Sleep
    • Linux bg Command
    • Linux WC
    • Linux Read
    • Linux Write
    • Linux Rename Command
    • Linux Free Command
    • Linux tac
    • Linux Shred
    • Linux wget
    • Linux Date
    • Linux Untar
    • Linux JQ
    • Linux Xargs
    • Linux Mount Command
    • Linux mdadm
    • Linux comm
    • Linux tee Command
    • Tail Command in Linux
    • Linux gzip
    • Linux Directory Structure
    • Linux Alias Command
    • Linux Inode
    • Linux Ping
    • Linux Watch Command
    • Linux Split Command
    • Linux Size
    • Linux Network Stack
    • Linux Diff Command
    • Vim Command in Linux
    • Linux nslookup
  • Basic
    • Introduction to Linux
    • What is Linux
    • Careers in Linux
    • How to Install Linux
    • How to Install Ubuntu
    • How to Install Ubuntu Server
    • How To Install Debian
    • Advantage Of Linux
    • What is Raid in Linux
    • What is Raid 5?
    • Raid 5 vs Raid 6
    • Careers in Linux Administration
    • What is Shell in Linux?
    • Bash Shell in Linux
    • Linux Emulator
    • Linux Operators
    • Linux Apps
    • Linux Keyboard Shortcuts
    • Linux Crontab
    • What is Raid Storage
    • What is Vmware
    • What is RedHat
    • What is Debian
    • Uses of Ubuntu
    • Career In RedHat
    • Linux Distributions
    • Linux From Scratch
    • Linux Format
    • Cheat Sheet Linux
  • Advanced
    • Install VMware
    • Install GRUB
    • Chown Command in Linux
    • Linux Network Command
    • Configuring Linux Network Environment
    • DNS Configuration in Linux
    • Linux Users
    • Create User in Linux
    • DHCP Server in Linux
    • FTP Server in Linux
    • Linux Regular Expression
    • IP Command in Linux
    • Set IP Address in Linux
    • Tar Command in Linux
    • Dynamic Host Configuration Protocol
    • Linux Kill Signals
    • Linux File Permissions
    • Linux File System
    • Linux Create File
    • Linux Concatenate Files
    • Linux Join
    • Linux Process Management
    • Linux Proxy Server
    • Linux System Commands
    • Linux System Logging
    • NFS in Linux
    • Linux LVM
    • Linux Repository
    • Samba Server in Linux
    • Top Commands in Linux
    • Types of Shells in Linux
    • Shell Script Types For Linux
    • GCC Command in Linux
    • Monolithic Kernel
    • YARN Package Manager
    • Linux Sed Replace
    • Linux List Groups
    • Linux Container
    • Linux Find File by Name
    • Create Folder in Linux
    • Linux Move Folder
    • Linux Error Codes
    • Linux Automount
    • Linux HugePages
  • Kali Linux
    • Install Kali Linux
    • Kali Linux Uses
    • Kali Linux Commands
    • Kali Linux Repository
    • Kali Linux Packages
    • Kali Linux root password
    • Kali Linux Alternative
  • Interview Questions
    • Linux Interview Questions
    • Linux System Administration Interview
    • Red Hat Interview Questions

Related Courses

Kali Linux Training

Linux Training Course

Red Hat Training Course

Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Java Tutorials
  • Python Tutorials
  • All Tutorials
Certification Courses
  • All Courses
  • Software Development Course - All in One Bundle
  • Become a Python Developer
  • Java Course
  • Become a Selenium Automation Tester
  • Become an IoT Developer
  • ASP.NET Course
  • VB.NET Course
  • PHP Course

© 2020 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA Login

Forgot Password?

EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

*Please provide your correct email id. Login details for this Free course will be emailed to you
Book Your One Instructor : One Learner Free Class

Let’s Get Started

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

Special Offer - Kali Linux Training Learn More