Questions tagged [xargs]

xargs is a command that executes another command and generates its arguments from stdin

Filter by
Sorted by
Tagged with
0 votes
1 answer
40 views

How to grep "find -print0" output?

I tried this: find /usr/lib -print0 | grep zip | xargs -0 -I{} echo "found file: {}" find /usr/lib -print0 | grep --null zip | xargs -0 -I{} echo "found file: {}" But it doesn't ...
  • 779
-2 votes
1 answer
59 views

Using unix, copy, relocate and rename files from nested directories to dir with name derived from the path

I have a file.txt with a list of 100 files and their paths. Here are the first 3 entries: /project/msun/USERS/me/czi/data/lb/MAP-9-003/c44caf4c-cab7-4749-9940-a74a66bceec3/c44caf4c-cab7-4749-9940-...
  • 99
0 votes
1 answer
16 views

"xargs -I" not working for child command

xargs -I not working for child command Example: # Not working ls .... | xargs -n 1 -I % sh -c "cmd $(cmd2 % )" # working ls .... | xargs -n 1 -I % sh -c "cmd % " Is there any ...
  • 1
1 vote
1 answer
197 views

Vim: Warning: Input is not from a terminal

I am not an advanced linux user and I have a hard time wrapping my head around some new concepts. I recently read about xargs command and wanted to test some examples. One of them confused me like ...
  • 113
22 votes
1 answer
587 views

find . -print0 | xargs -0 cmd vs find . -exec cmd {} +

find . -exec cmd {} + find . -print0 | xargs -0 cmd Both are meant to be reliable ways to run a command on the files found by find. Which is preferred? Which is more portable, reliable, efficient, ...
-2 votes
5 answers
129 views

How to merge lines in groups of three

I have a file containing the below pattern, up to 2000 lines. For every group of three lines, the pattern repeats with different numerical values, but text values at the beginning are common up to ...
3 votes
3 answers
387 views

xargs treat multiple lines as arguments to single command invocation

I am having a hard time print a seq of number, and then appending something at the end. seq 1 3 | xargs -I {} echo {} 4 results in 1 4 2 4 3 4 However I want the result to be 1 2 3 4 Since I am ...
0 votes
1 answer
97 views

How to solve 'tee: Too many open files' when trying to redirect output to multiple files

I need to download hundreds of json files from a list of urls stored in a csv. As it would be impossible to do so manually, I wrote a short bash script to read the urls one by one using Python and ...
1 vote
1 answer
63 views

Can someone explain this xargs command structure to me?

This command is a part in a row of piped inotify workers (do you say that?) etc. I thought it would fit the one question per post policy better than asking for a dissection of the whole (very useful !)...
  • 365
0 votes
0 answers
92 views

How to test fastest mirror

I'm currently using xargs -n 1 -P 24 curl -s -w '%%{url_effective}\t%{time_total}\n' -o /dev/null < mirrors.txt to test the response time for each mirror. I want to be able to terminate all ...
0 votes
1 answer
46 views

Run two commands with the same argument, on one line

I need to parse a file line by line and pass a value found in them to 2 commands, in FreeBSD's sh (no other shells can be used). My plan was to use xargs and su: whatever_outputs_values | xargs -I {} ...
1 vote
1 answer
108 views

How to move files in a directory based on a substring in filename

I'm very new to scripting and working in Unix/Linux systems, so I appreciate any help. I'm sure this has been answered before but I cannot figure out why none of the other solutions are working for my ...
  • 11
1 vote
0 answers
62 views

xargs works in command line but not in Bash script?

Ok, so I am new to linux and also bash script. I am trying to use bash script to manipulate iptables. I need to delete all entries in the iptables where the source ip matches. I found a code which ...
  • 11
0 votes
1 answer
109 views

Passing value with xargs to generate dynamic output filename

I have some files in a folder. By running the following command I can create a list with the filtered filenames ( test1, test2,test3) and pass it using xargs to a grep filtering command filter file in ...
  • 19
1 vote
1 answer
54 views

What does the -I argument do from xargs?

I am writing a bash script and encountered this argument -I in answers here and here but I do not understand what it does. The manual is also not clear to me. The second answer also states the ...
  • 35
0 votes
1 answer
155 views

How to create multiple directories and populate them with files

I want to make some directory trees and populate each end of the tree with a text file with random content. Here is what I tried so far: #!/bin/bash set -e echo "Generating test folders" ...
  • 764
0 votes
1 answer
47 views

xargs combination of variable and piping

Hello I am building a bash script, I would like to use xargs to do a call of my_command in parallel, issue is that with the command below, the variable $input_file is not available. command is looking ...
  • 101
1 vote
1 answer
151 views

Pass multiple rows from awk to xargs

I want an easy way to monitor the resource usage of processes matching certain keywords. So I do something like: ps -aux | grep XX | awk 'FNR == 2 {print $2}' | xargs -o -I {} top -p {} (pgrep won't ...
  • 424
2 votes
3 answers
614 views

xargs ignore blank line when using -d'\n'

I have a file input that may have blank lines, I want any empty lines skipped. I am trying to find a solution that does not require using grep / tr and piping the output to xargs I use the following ...
4 votes
2 answers
275 views

The command `grep -Ilri foo . | xargs grep -i bar` works only if the resulting path has no space

To find all the files that have the word foo in it, and also the word bar in it, we can use grep -Ilri foo . | xargs grep -i bar (which is case insensitive and exclude binary files)... however, if ...
  • 2,849
1 vote
1 answer
904 views

Need to capture exit code of pylint command using find in Github actions

I am trying to implement a python linter using pylint. But I am getting the score of each python file and also displaying the suggestion to improve the score but I am also looking to terminate the ...
2 votes
2 answers
232 views

Difference between xargs and GNU parallel

I need to run an executable a large number of times, each time with two command line arguments. I've used to use xargs for this purpose, but lately I've been made aware of the existence of GNU ...
  • 145
0 votes
1 answer
77 views

Why basename don't work here [duplicate]

Why when I do this (I know, it's stupid) it returns the full path, not only the filename as expected? ls -l | awk '{print $9}' | xargs -I% find ./my_dir -type f -name "%" -exec echo $(...
  • 103
2 votes
4 answers
288 views

How to distribute files per directories based on names of these files?

I have camera pictures stored in files with names 192.168.33.16_01_20220723150356205_MOTION_DETECTION.jpg I want to move each file into separate directory per date I found that command find | awk '{...
  • 2,877
1 vote
0 answers
225 views

How to circumvent the "xargs: argument line too long" problem if one wants to send very long arguments to a command?

Say I have an executable script process_image that performs actions on a base 64 encoded image. I am storing every image in a file images_file line by line. Every line of images_file is a base 64 ...
1 vote
1 answer
251 views

Does xargs -P run background processes? How is it different from using an &?

I have a file processes.txt as follows: process_1.sh process_2.sh process_3.sh I will run the following on the terminal: cat processes.txt | xargs -L1 -P3 sh How would this be different if I had a ...
0 votes
2 answers
85 views

tar processing files multiple times with find -newer

I'm trying to use tar(1) to create an archive of files newer than a specific file (fileA). However, when I use find(1) to obtain the list of files to pass to tar, some files are listed multiple times: ...
0 votes
1 answer
109 views

"xargs" not sending argument to "cd" via stdio

I am seeing "xargs" behaviour that seems to be quite unexpected, in my experience. I use "ls" to find a matching folder name and sending it to "cd" using "xargs&...
0 votes
1 answer
50 views

Define rsync source files as last arguments

Say I am using find to define source files for an rsync-operation, making use of special capabilities I only know from these two commands: find /path/to/data -mtime -7 -mtime +5 -exec rsync -aAXu {} /...
  • 11.7k
2 votes
1 answer
270 views

Cannot source file using find, fzf, and xargs

I am trying to use fzf to select and activate different virtual environments. However, I am receiving the follow error: xargs: source: No such file or directory My command comprises three parts: find |...
1 vote
3 answers
140 views

What is the difference in how linux implements commands which accept input via pipe vs. command arguments?

Although there are many similar questions, I cannot find one that directly answers my question. I understand the basics of OS memory management, processes, communication between processes, etc. ...
0 votes
1 answer
333 views

xargs sed cmd error xargs: gsed: No such file or directory

I am trying to replace the below line in myfiles.hcl file "-var-file=${get_parent_terragrunt_dir()}/variables/eu-west-2.tfvars", with "-var-file=${get_parent_terragrunt_dir()}/...
  • 101
3 votes
3 answers
2k views

Remove all dnf modules currently installed

I have a CentOS 8.0 system with quite a few modules installed I don't want. I want to get rid of them to force an upgrade to CentOS 9.0, which I know is not officially supported but it is not actually ...
  • 1,870
0 votes
3 answers
276 views

Find number of lines between a pattern inside specific filetype

I have a notes.json file inside each directory. The following command counts length of each notes.json file and returns a sorted output by each file's number of lines. find . -name notes.json | xargs ...
  • 7
3 votes
1 answer
354 views

Safely redirect output to a single file with xargs parallel mode

I have a bunch of bzipped JSON file that I read with xargs in parallel, do some light processing with jq and redirect the output to a file as follows: # Number of workers is one less than the number ...
0 votes
1 answer
539 views

Dynamically generate arguments for python script input

I call a python script with some command line arguments like: python3 script.py --run 1 --filepath "this/file/dir" I now try to parse the arguments from a config file with: grep -v '^#' ${...
0 votes
2 answers
120 views

xargs running more than one command?

Is it possible to use xargs to run more than one command? The only related information I found was this question, but the answer was not related to xargs. I'm running a simple du / -ah | sort -r -n | ...
0 votes
2 answers
372 views

Piping find to xargs works in terminal, but not in shell script [duplicate]

I'm trying to write a Bash shell script that copies all the files in the current directory, minus a few exceptions, into another directory. The script builds a command, stores it in a variable, and ...
  • 101
0 votes
1 answer
186 views

Deleting files using xargs prints lots of No such file or directory (but seems to work...)

I have a script that deletes files older than N minutes. The script basically runs: find /some-folder/* -mmin +59 | xargs rm -rf But for some reason it prints tons of: No such file or directory but ...
  • 911
0 votes
1 answer
282 views

How to print domain name in the curl output

I am using xargs and curl command to get the response from the list of domains in the input file. xargs -n 1 curl -sS < input.txt 2>&1 | tee curltest It is hard to find which domain out is ...
  • 727
0 votes
0 answers
28 views

pass output as grep pattern [duplicate]

I wish to pass each line of a file as a grep pattern to be searched in data.txt file. Thus, i need cat allsearchstrings.txt | grep <should be lines of allsearchstrings.txt> data.txt cat ...
  • 427
-1 votes
1 answer
53 views

xargs -I# showing unexpected behavior - why?

I'd like to zip a whole bunch of folders which are in a certain directory, creating one zip file per folder. To do that, I use the following command: $ find -maxdepth 1 -mindepth 1 -type d | xargs -I@ ...
  • 2,473
0 votes
0 answers
52 views

turf-cli + xargs: argument line too long

I'm using turf-cli (it can be installed with sudo npm install -g turf-cli) for creating some geospatial data. turf-cli is a wrapper for the turf.js library just so we can use its functionalities from ...
  • 341
0 votes
1 answer
70 views

Why pipe doesn't work with upower -e

I've just found this command: upower -e that displays a list of files that can be used with upower -i to display plugged device status. So my first try was using: upower -e | xargs upower -i but it ...
  • 9,302
0 votes
1 answer
275 views

Command substitution with xargs inputs [duplicate]

I'm trying to write a simple command that will create symlinks for all files in a specific directory (Yes, exactly like lndir but I cannot use it so I try to mimic it). I tried the following using ...
4 votes
1 answer
646 views

execvp: /bin/bash: Argument list too long on Ubuntu 20.04 but OK on Ubuntu 18.04 (all using Windows 10 subsysem)

I bought a new windows 10 PC and installed WSL 2 using (as admin) wsl --install This installed WSL 2 with Ubuntu 20.04 LTS. I then copied my files from the old PC which was using same windows 10 pro ...
  • 809
0 votes
4 answers
228 views

Returning filename and number of pages for each pdf document in a directory

CONTEXT: Catalina MacOS: A set of .pdf files is in a directory. Some of the filenames have spaces (problematic with xargs. From the command line: the goal is to return for each .pdf file, the ...
  • 1,176
0 votes
2 answers
35 views

Edit a particular string in a file based on another file

Hello I have a file called users. In that file i have a list of users for example user1 user2 user3 Now i have another file called searches where there is a specific string called owner = user for ...
2 votes
1 answer
181 views

Why do I need to use the -I parameter in `compgen -G ... | xargs basename`?

I ran into a situation where I was piping the output of compgen -G to xargs basename and could not get it to work until I added the xargs -I parameter as seen below. Here is a script demonstrating ...
  • 123
0 votes
1 answer
923 views

How to tell `xargs` to ignore empty stdout? [duplicate]

How can this code be changed so as not to issue an error, in other words not execute the code after xargs if stdout is empty. Terminal: $ cat << EOF > dummy.sh #! /usr/bin/env bash [[ -f &...
  • 561

1
2 3 4 5
14