Questions tagged [xargs]

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

Filter by
Sorted by
Tagged with
2 votes
2 answers
68 views

Problems with using AWK with XARGS

I'm having trouble with the following command --> find . -type f -name 'out*' | xargs awk 'BEGIN{print "Filename, Energy"}/TOTAL ENERGY/{print FILENAME, "," $4}' >> ...
dtx1's user avatar
  • 21
0 votes
1 answer
39 views

saving xargs ouput from multi files to one file

I have these three text files : #1.txt hey stackoverflow #2.txt hey stackexchange #3.txt hello world I am using this command to list the last 3 files in my dir and then cat them and then save ...
Anonymous101's user avatar
0 votes
0 answers
124 views

Distrobox can´t export applications - xarg throws error

distrobox-export --app emacs isn´t working as expected. it throws the output: xargs: unmatched single quote; by default quotes are special to xargs unless you use the -0 option Error: cannot find any ...
Lucas Suppes's user avatar
0 votes
1 answer
32 views

Use find + xargs to edit multiple files at once with KDE Kate

The problem: Edit many files in one single kate process. FILE_LIST is a variable which contains a list of path FILE_LIST="$MAIN_PATH1 $MAIN_PATH2 ... $MAIN_PATH3" DST_DIR is the ...
jcdole's user avatar
  • 1
0 votes
0 answers
31 views

Skip pipe when empty in bash [duplicate]

How can I let the pipe work only when there's output in first command? I'm looking for a workaround for pick. I've tried find|xargs -r pick, but pick only receives input from pipe. Thanks in advance!
Rashedul Hasan Rafi's user avatar
0 votes
1 answer
44 views

Slow down a `split`

I have a really large archive consisting of really small files, concatenated into a single text file, with a "" dilimiter. For smaller archives, I would split the archive using "" ...
Alex's user avatar
  • 1,165
0 votes
0 answers
164 views

xargs cat a file with aws cli (amazon s3 move)

I have a file called file.csv, which is a list of the files (or more precisely, file paths path in an S3 Bucket) that need to be moved to another folder in s3. This file lists 53,00,000 files. I have ...
hanu's user avatar
  • 1
0 votes
2 answers
88 views

How to catch newlines in user input

I want to do something with user input to use in grep. Like, instead of uin="first\nsecond\n" printf $uin | grep d which outputs second, I want to have the user input it, like read uin ...
user14094230's user avatar
2 votes
1 answer
83 views

Replacing a character in all files names of a directory

This is homework! I'm trying to replace all spaces in file names with an underscore in the yay directory. It asks me to use the commands xargs and sh without using $(command). I tried using conducts ...
cow's user avatar
  • 81
1 vote
3 answers
117 views

Make `xargs` use the maximum multiple of N arguments

I have a a file that contains more than a hundred thousand of IDs. Each ID is composed of 8~16 hexadecimal digits: 178540899f7b40a3 6c56068d 8c45235e9c 8440809982cc 6cb8fef5e5 7aefb0a014a448f ...
Fravadona's user avatar
  • 561
2 votes
1 answer
177 views

Piping xargs into GNU parallel

I have the following script which gets the absolute paths of some directories and pipes them into GNU parallel for zipping. I keep getting a signal 13 error and I'm not sure why. find $directory -...
testing09's user avatar
1 vote
2 answers
108 views

How to find the most recent file that contains a string

I have a directory containing several files. I need to know the full path of only the most recent file that contains a certain string. This needs to work on macOS, and the directory path contains ...
Andrew Parks's user avatar
-4 votes
1 answer
81 views

copy multiple directories in multiple directories without loop [duplicate]

I want to copy directories from one variable to directories from another one but without loop. from="fromdir1 fromdir2" to="todir1 todir2" I mean fromdir1 to todir1, fromdir2 to ...
trilisser's user avatar
  • 103
2 votes
1 answer
232 views

make xargs accept multiline string as single parameter

git log --format=%B -n 1 HEAD | xargs -I{} npx ts-node --esm ./foobar.ts {} I have this line of code, which has the purpose of using git to pass the latest commit-message to a script which will look ...
Phil's user avatar
  • 123
1 vote
2 answers
246 views

How can I run `$(nproc)`× parallel instances of `openssl dhparam` & when first instance exits with `0`, kill the other instances?

I'm running openssl dhparam -out dhparam4096.pem 4096 and it pegs a single core at 100% for the duration of the task (which can be considerable on some processors). I have 1 or more additional cores ...
Pete Cooper's user avatar
3 votes
4 answers
376 views

Apply arithmetic into piped command

So far I have this: sudo find /path/to/dir -type f | xargs -d "\n" sudo stat -c "%Y %n" | {arithmetic to check if %Y is between 1685518962 and 1685624474??} | {show ...
MonkeyZeus's user avatar
0 votes
1 answer
58 views

How to find a file and copy its directory without copying the other files in that same directory?

I have a lot of different folders with pdf files and other extensions. I want to copy all the pdf files to another destination. But if I do that with find like this: "${SEARCHDIR}" -iname &...
pwrsheller's user avatar
-4 votes
1 answer
83 views

xargs command output is not predicated

When I use find like this: echo 1 2 3 | xargs -I{} find {} I get the following output: find: ‘1 2 3’: No such file or directory But when I use it like this: echo 1 2 3 | xargs find I get this ...
what is what's user avatar
0 votes
1 answer
83 views

Flush output continuously with xargs

The function output the size of the downloaded file and the speed of transfer separated with newline. Example: 20 #<< data 3.0M #<< speed 25 1.2M Now, it goes like this: output_data_func |...
decipher's user avatar
  • 302
6 votes
2 answers
1k views

Why xargs does not process the last argument?

Observe: mark@L-R910LPKW:~$ echo a b | xargs -d' ' -I{} bash -c 'echo {} 1' a 1 b bash: line 2: 1: command not found mark@L-R910LPKW:~$ What is going on?
mark's user avatar
  • 387
2 votes
1 answer
38 views

How to concatenate files and give another name to output based on the match from another file?

I have a directory data in which there are several fastqs like below: SRR13456784_1.fastq SRR13456784_2.fastq SRR13456784_3.fastq SRR13456785_1.fastq SRR13456785_2.fastq SRR13456785_3.fastq ...
stack_learner's user avatar
0 votes
3 answers
219 views

Handle parentheses in this xargs multi-command

I suspect the following has been answered already but I don't know the terminology for the issue I'm having well enough to find an existing answer. I'm working on a command to go through a list of ...
SSilk's user avatar
  • 153
1 vote
1 answer
79 views

Remove entire folder when grep find no files with a match inside the folder

I have thousands of folders with a single html file in each folder. I want to remove the entire folder if grep find no match to example.com in the html file. I know how to remove the non matching file....
xorghelpneed's user avatar
2 votes
3 answers
3k views

xargs: run a command for each line and separate arguments with whitespace?

I can reproduce this issue on cygwin bash and oh-my-zsh with wsl.exe. My intent is to run these two lines on the command line: npm rm plugin-alias npm i -D plugin-alias Here is how I'm trying to do ...
Daniel Kaplan's user avatar
3 votes
1 answer
542 views

Difference between -i and -I for xargs

I understand -i but I don't know how it is different from -I and why the manual says that -i is deprecated. For example what is the difference between using the two lines below: ls -t | tail -n 4 | ...
Malachy_P's user avatar
0 votes
1 answer
240 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 ...
zomega's user avatar
  • 962
-2 votes
1 answer
69 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-...
Lucas's user avatar
  • 99
0 votes
1 answer
95 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 ...
JOEL's user avatar
  • 1
1 vote
1 answer
3k 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 ...
dimitar.d's user avatar
  • 113
24 votes
1 answer
2k 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, ...
Stéphane Chazelas's user avatar
0 votes
5 answers
339 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 ...
C S Pallapu's user avatar
5 votes
4 answers
2k 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 ...
infoclogged's user avatar
0 votes
1 answer
136 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 ...
Francesco Ghizzo's user avatar
1 vote
1 answer
110 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 !)...
von spotz's user avatar
  • 435
0 votes
0 answers
220 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 ...
tacostes's user avatar
0 votes
1 answer
256 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 {} ...
user548250's user avatar
1 vote
1 answer
329 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 ...
Melanie's user avatar
  • 11
1 vote
0 answers
159 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 ...
frank's user avatar
  • 11
0 votes
1 answer
210 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 ...
peti27's user avatar
  • 51
1 vote
1 answer
70 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 ...
Nick_Z0's user avatar
  • 45
0 votes
1 answer
475 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" ...
DEKKER's user avatar
  • 926
0 votes
1 answer
133 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 ...
stanedav's user avatar
  • 101
1 vote
1 answer
464 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 ...
ahron's user avatar
  • 404
2 votes
3 answers
1k 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 ...
Jacob Jarick's user avatar
4 votes
2 answers
295 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 ...
nonopolarity's user avatar
  • 3,059
1 vote
1 answer
1k 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 ...
sidharth vijayakumar's user avatar
2 votes
2 answers
906 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 ...
Tor's user avatar
  • 145
0 votes
1 answer
231 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 $(...
Alysko's user avatar
  • 103
2 votes
4 answers
332 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 '{...
Dims's user avatar
  • 3,255
1 vote
0 answers
720 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 ...
sriganesh's user avatar
  • 101

1
2 3 4 5
15