Questions tagged [xargs]

utility in Unix-like operating systems for passing large numbers of arguments to programs that can only take a small number of arguments

Filter by
Sorted by
Tagged with
0 votes
0 answers
9 views

atool just hangs with `xargs -- zip -r test.csv` on Mac?

First off, I couldn't seem to find why the -- two dashes to xargs, but here's what I'm getting: $ atool -E -a --format=zip words.csv xargs -- zip -r words.csv [...hangs...] The docs are at https://...
Lance's user avatar
  • 377
1 vote
2 answers
132 views

How to run xargs utility on all expanded lines of input?

I have a file with a list of files and directories, containing the wildcard *. I am trying to output the size of the entries with du and would like a grand total. If I start with: cat file | xargs du -...
Francisco Leon's user avatar
2 votes
1 answer
1k views

How do you move (mv) in ZSH all files from current directory except two or more to a child directory?

(There is plenty of information about this on bash, but much less on zsh and NOT AT ALL for TWO or more files. No idea how to apply the ^ ("caret") TO MORE THAN ONE FILE). I want to know (...
nostromo's user avatar
0 votes
1 answer
71 views

xargs and echo limited number of replacements

I want to duplicate some text a few times. Xargs doesn't do more than 5 items. I don't know if there is a better way to do this. echo "sometext " | xargs -n 9 -t -I RRRR echo RRRR RRRR RRRR ...
nelaaro's user avatar
  • 13.6k
0 votes
1 answer
556 views

Why is xargs unable to call basename properly in a subshell?

I ran into the following problem: user@machine:/$ echo ./dir/fil | xargs -I {} bash -c "echo $(basename {})" ./dir/fil Why is it not just printing fil? So basename seems to get the expected ...
SebDieBln's user avatar
  • 103
1 vote
1 answer
5k views

Using jq with xargs

I have a json-file with n users. I need to replace the id-field with a different UUID for each user. After that, I need to make n curl calls with the json as payload. How can I achieve this? My json ...
sjoblomj's user avatar
0 votes
2 answers
118 views

Find files in git that have entry in .editorconfig

I want to find all of the files in git that have some extensions. The list of extensions is generated from my .editorconfig file. Say I have a list of file extensions such as: .css .html .java .js (...
User1648374637563's user avatar
0 votes
1 answer
622 views

Why does `xargs` not work with `echo` but work with `ls`?

root@home:~$ ls root@home:~$ echo abc > z1 root@home:~$ echo xyz > z2 root@home:~$ ls z1 z2 root@home:~$ ls | xargs -I{} cat {} abc xyz root@home:~$ echo z1 z2 | xargs -I{} cat {} cat: 'z1 z2': ...
xmllmx's user avatar
  • 444
0 votes
1 answer
314 views

grep for lines in shell script, send to xargs with $1 set

I have a shell script (I use GNU bash 4.4.20 on Ubuntu 18.04) with a list of commands I often run, e.g.: sudo program1 $1 foo arg1 sudo program2 $1 foo arg2 sudo program1 $1 bar arg3 sudo program2 $1 ...
nonagon's user avatar
  • 583
1 vote
2 answers
173 views

Generalized chmod function differentiating between directories and files (i.e.: with find)

Is there a generalized bash function available that mimics chmod in every aspect, except that it also let's me differentiate between files and directories? I know there's already numerous examples ...
Decent Dabbler's user avatar
2 votes
1 answer
1k views

How to batch delete the redis keys from local machine and through a jump machine inside kubernetes cluster?

I need to delete some keys in my redis cluster which can only be accessed from a jump machine deployed in the kubernetes cluster. So if I know the key I can delete it by the following command without ...
Jeff Tian's user avatar
  • 207
0 votes
1 answer
254 views

awk multiple commands and multiple args

I'm trying to turn this output: ❯ hg branches -T'{node} {branch}\n' 4b0826975cb29da26a6dd13f463241463c43c6a7 maria 5c31751cdb774f8b6337b6f64232b15903530997 default Into these commands: hg bookmark -r ...
mpen's user avatar
  • 12.1k
0 votes
2 answers
369 views

xargs how to string commands together

Hey guys im a newbie scripter with no formal training in programming so apologies in advance for the messy code. What I want to accomplish: This what directories look like. /home/AAA /home/BBB /...
Hani Umer's user avatar
2 votes
1 answer
3k views

xargs and git issues in windows powershell

I've been using the following command to delete any merged git branches: git branch --merged | grep -v "\*" | grep -v "master" | grep -v "staging" | xargs -n 1 git branch ...
MichaelK's user avatar
1 vote
3 answers
4k views

Why does xargs split on spaces even with -0?

According to the docs and advises on the internet, any of these: $ ls $(env -0 | xargs -0) $ ls $(env | xargs -d '\n') given LESSOPEN is | %s _=/usr/bin/env should produce this: ... ls: cannot access ...
Pavel Koryagin's user avatar
0 votes
2 answers
273 views

Symlinking with (i.e.) find | sed | xargs without xargs: argument line too long

I got stuck at symlinking using find, xargs and sed. Given folder structure: /abc /def /*/def /builds on my local machine the following statement works. find ./abc \ -type d \ -...
mowtheone's user avatar
  • 109
1 vote
2 answers
159 views

How to exit less follow mode without exiting less when xargs is used?

ls -rt *.log | tail -1 | xargs less +GF I use this command to tail -f my logs, but when I ctrl+c to exit follow mode, it quits less too. I think it is caused by xargs, because if you just less <...
Shuman's user avatar
  • 241
1 vote
2 answers
1k views

Accessing parent and grandparent directory from linux find and passing to xargs

I'm trying to do a batch imagemagick conversion on all tiffs in directories. The structure of the directories looks like: test 123 456 image.tif 256 857 ...
Goat Karma's user avatar
1 vote
1 answer
643 views

xargs run bash script with threads (2 arguments)

I have a file in the following format: "192.168.2.1" "80" "172.16.1.1" "443" "10.1.1.1" "8080" which contains multiple local IPs and i'm trying to run a script with threads using xargs to execute ...
Gerald's user avatar
  • 21
0 votes
1 answer
285 views

Why does xargs with cp fail for recursion?

I am trying to copy files from one directory into a whole collection of other directories, such that the set of files in the source directory will be present in every one of the destination ...
Toby's user avatar
  • 836
1 vote
1 answer
2k views

delete several permanent entries from arp table by command line

I am trying to remove the permanent entries from my arp table. but the following command only removes those that are not permanent ip -s -s neigh flush all With the arp utility I was able to ...
acgbox's user avatar
  • 775
2 votes
1 answer
379 views

Why does `echo | xargs > >(cat)` hang on my Mac?

This is reproducible in zsh and bash. Confusing me further, echo | ( xargs; : ) > >(cat) does not hang. This is also reproducible in zsh and bash. If I use GNU's xargs as provided by brew ...
johncs's user avatar
  • 51
3 votes
2 answers
7k views

Bash Script to delete oldest files but keep latest files including sub-directories

I'm trying to delete old files but should keep latest 3 days log files.i tried below command, ls -tr /home/httpd/htdocs/pathname/pathname/config//build/logs/apps/.log | tail -n +4 | xargs rm -- but ...
Sudesh Lakmal Pathirana's user avatar
1 vote
2 answers
692 views

Similar commands with find are not outputting the same

I'm trying to run a find command on a directory which contains unit files: find /home/pi/units -type f -name "*.service" which returns /home/pi/units/manager.service I then want to pipe that ...
Devin's user avatar
  • 13
1 vote
1 answer
449 views

In "find ... | xargs ...", why does xargs iterate even when find returns zero results?

I recently had a find ... | xargs ... use case that surprised me. The issue involves the case where find returns no matches. Testing on two systems, I found that one behaves as I would expect: $ ...
Jim L.'s user avatar
  • 859
6 votes
1 answer
862 views

Using xargs with pdftk

I am using the following code to concatenate all the pdf files in the current directory: find . -iname '*.pdf'|sort|xargs|xargs -I {} pdftk {} cat output union.pdf The first invocation of xargs has ...
Mizar's user avatar
  • 135
2 votes
2 answers
592 views

Use tmux attach with xargs

I'd like to create an alias that lets me browse all of my tmux windows with FZF and then attach that single window. What I have so far: tmux list-windows -t main -F '#{session_name}:#{window_name}' | ...
sudoremo's user avatar
  • 165
0 votes
1 answer
92 views

Find and rename first result in linux?

I have try using this commanline. find *.txt | head -1 | xargs -0 mv *.txt test.txt i receive. mv: target ‘02.txt\n’ is not a directory What wrong :(?
Adam Trinh's user avatar
1 vote
2 answers
5k views

How to get line number in xargs?

I want to upload some files to machines in parallel. There's a list of hosts and a list of files that should be uploaded by index: 1.txt goes to hostOne, 2.txt goes to hostTwo etc. Here's what I try ...
Poma's user avatar
  • 1,816
2 votes
1 answer
7k views

using xargs pass arguments to sub shell with pipe

I want to rename a number of files. I think I can use xargs to do it. find ./ -name "upload.log-*" ./upload.log-20180622.gz-20180624.gz-20180626.gz ./upload.log-20180624.gz-20180626.gz ./upload.log-...
nelaaro's user avatar
  • 13.6k
0 votes
1 answer
2k views

Pass command output as argument in grep

I want to compare two text files for changes line by line. If the files are store locally I know I can do it with grep -Fxvf file1 file2 I have a problem because file 2 is in Hadoop File System. I ...
Michail N's user avatar
  • 111
0 votes
1 answer
145 views

Replacing a line in multiple files

I have a list of files and corresponding line numbers where I want to perform the substitution: s/LOG.error/LOG.warn There are other places where this might occur and don't want to disturb those ...
ayushgp's user avatar
  • 223
1 vote
1 answer
657 views

How to move the folders to new directory based on their match in csv file?

In my present directory I have many folders like F1, F2, F3, F4, F5, F6, F7, F8, F9, F10. I have a csv file "dan.csv" in the present directory which has a column with folder names. csv file looks ...
beginner's user avatar
  • 223
4 votes
3 answers
2k views

How to pipe a single item from a command output into another command?

Basic example using grep (note that grep would not be my only use-case for this): $ grep -Irl "foo" path/to/directory/help.js path/to/directory/config.js path/to/directory/task.js Now I want to open ...
jewbix.cube's user avatar
3 votes
1 answer
4k views

Specify a list of files as input into pdftk

I have a list of files that I need to specify as input to pdftk so it will concatenate them in the order specified. I don't see an input file list as an option in the pdftk man page, but perhaps ...
Jeffrey Bauer's user avatar
0 votes
2 answers
1k views

Find get the files I want,the pipe to xargs and Tar don't

I'm using the following command line: find . -mtime -15 -mtime 0 -print0 | xargs -0 tar cjvf /home/user/adjuntos.tar.bz2 The left side of the pipe works like a charm, but the right side of the ...
JuanEs1eban's user avatar
0 votes
2 answers
42 views

find a file and send some text to it

I would like to find a file in folder /opt and send some text to it. I tried the following syntax: sudo find /opt -name filename-*.conf | xargs -I '{}' echo "text_to_send" > '{}' \; Unfortunately,...
Piotr G's user avatar
  • 121
1 vote
1 answer
503 views

What does this do? `Find ... -type d|xargs chmod 770`

What does these two lines do? find /backup/folder -type d|xargs chmod 770 find /backup/folder -type f|xargs chmod 660 I googled around, but can't figure out what d|xargs and f|xargs does.
Zeth's user avatar
  • 103
0 votes
2 answers
320 views

Cannot make xargs construct to work

I have a strange problem with xargs. I have an xargs construct which does not work, even though when I echo the command, it works perfectly. My one liner is the following: exiftool -p ...
Grigoris L. 's user avatar
0 votes
1 answer
284 views

ssh into a machine and search for process, kill using xargs

I am doing this, [email protected] ~> ssh <machine> jps | gawk '$2 == "<process>" {print $1}' | xargs kill kill: sending signal to 75797 failed: No such process guastest@iridium06....
Vinu Shankar's user avatar
4 votes
3 answers
2k views

Add text to list of files

I'm trying to use xargs to manipulate a set of files. A file called filelist.txt contain the file names john paul george ringo steve I can create all these files with this command: cat filelist....
cannyboy's user avatar
4 votes
1 answer
10k views

xargs on windows: No such file or directory

I wanted to resync the tags on my local git repository with the ones on our remote server, using this answer provided on StackOverflow: git tag -l | xargs git tag -d git fetch --tags I've got git ...
gerrod's user avatar
  • 185
0 votes
2 answers
785 views

oldest to newest file in directory tree and delete each file interactively

In the step 1, I am trying 'find' the oldest file in directory tree, which I solved by following this question. Now I want to use xargs to delete interactively from oldest to newest. Since this ...
Schultz Hartmut's user avatar
3 votes
2 answers
4k views

Multiple read from a txt file in bash (parallel processing )

Here is a simple bash script for HTTP status code while read url do urlstatus=$(curl -o /dev/null --silent --head --write-out '%{http_code}' "${url}" --max-time 5 ) echo "$url $...
user7423959's user avatar
1 vote
2 answers
3k views

Piped xargs doesn't execute the command

I want to monitor nginx access.log for malformed requests and notify myself about such cases. To do this i have written following command: tail -n0 -f access.log | grep --line-buffered '\{' | ...
pro100sanya's user avatar
0 votes
1 answer
3k views

Use xargs on file or content that contains quotes/single quotes

I am having difficulty using xargs with files with ', is there a way to by pass this problem? $ find . | xargs -I FILE echo FILE xargs: unterminated quote file name $ ls mike's sample 16
user2167582's user avatar
0 votes
1 answer
2k views

How to generate a list of URLs in bash?

How can I generate a list of URLs in bash so that I can pipe them to xargs and then to curl? http://somewebsite.com/{}.file where {} is a number.
Testr's user avatar
  • 21
1 vote
1 answer
2k views

How to launch multiple urls per process with cURL?

I am trying to download a list of URLs with cURL with multiple URLs per process. The following works but it returns a weird result if the xargs -L parameter is more than 1. I want to launch 8 ...
Testr's user avatar
  • 21
1 vote
0 answers
93 views

Summing selective du sizes output

I am trying to find out how much space is consumed in total by files exceeding 50M in size. I am able to generate a list of file sizes with the following command: find $PWD/soccer -maxdepth 50 -type ...
Sridhar Sarnobat's user avatar
1 vote
1 answer
253 views

How to rename multiple file name include subfolders?

For example i have the following files: ./dirA/fileA.png ./dirA/fileB.png ./dirA/fileC.png ./dirB/fileD.png ./dirB/fileE.png ./dirB/dirC/fileF.png Is there any one line command or script to rename ...
srjohnhuang's user avatar