Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [xargs]

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

1
vote
1answer
37 views

How to use -I{} with xargs' with an -n greater than 1?

I have a very large number of files (tens of thousands) that I need to grep through for a specific string. A small handful of the files have spaces in them. There are so many files the process ...
0
votes
0answers
27 views

Alternative to `while read line` for pipe

I have this: export var=1 kbc get pods -o=json | jq -r '.items[].metadata.name' | while read line; do echo "$line"; done; kbc get pods -o=json | jq -r '.items[].metadata.name' | xargs echo var=$...
0
votes
2answers
35 views

log show command output manipulation

Following is a command executed on macOS high sierra. **`Command`** log show --info --predicate 'process="jamf" and eventMessage contains "Informing the JSS about login for user"' --start 2019-04-...
0
votes
0answers
19 views

macOS High Sierra “log show ” ouput

The log show command output from a macOS High Sierra is detailed below: **Command 1** log show --info --predicate 'eventMessage contains "system boot:"' log: warning: ./system_logs.logarchive ...
0
votes
2answers
35 views

xargs issue with grepped files containing spaces

I have a range of .html files all containing spaces in between. What I need is to locate the file using find in conjunction with grep, and if a match is found, basically I just want xargs to open it ...
0
votes
1answer
24 views

If $x represent column where x is 1..any what represents rows in bash

Team, i need to know how to operate on value row wise after performing grep. I can operate column wise using $ but how to on row value? my output is cat file.txt | grep -o 'test1[^. ]*' output: ...
0
votes
2answers
44 views

Convert parallel to xargs command

I'm trying to convert this command to something that does not use parallel. find . -type f -iregex '.*.ts\|.*.js\|.*.tsx\|.*.jsx' | parallel 'touch {} -d "$(date -d \@$((0x$(md5sum {} | cut -b 1-7))))...
3
votes
4answers
58 views

How to sed chunks text from a stream of files from find

I have a directory of many *.org files. I want to select a section of text out of all these org files. There is a * Learnings header in the content. I would like to select from the * Learnings header ...
2
votes
1answer
28 views

Moving child folders and their content up one level and deleting the empty folder, across many folders with automation

Top Folder (1) is the root folder Top Folder (1) contains only the folder Top (2). Top Folder (2) contains Top folders (3),(4),(5),(6),(7),(8),(9),(10) Top Folder (3) to (10) all containing ...
0
votes
1answer
102 views

Solution for Argument list too long

I have the below shell script which reads a file, copies the content of the file to a variable and passes the variable as argument to another command. declare -a arr=() while IFS= read -r var do ...
1
vote
1answer
26 views

How to rename all md type files under subfolders recursive?

$ tree . . ├── tmp1 │   └── acsfd.md ├── tmp2 │   └── adb.md └── tmp3 └── aa23aa.md ... └── tmpn └── random.md Want to rename all md files to index.md, I tried: find . -name "*.md" -exec ...
-1
votes
2answers
61 views

Pipe each batch of xargs trough wc -l

So my task is to find the file with the most hardlinks in a directory. So far i have : find . -name "file*" | xargs -I{} -n 1 find . -samefile {} which gives me: ./hardlinkFIle245 ./...
0
votes
2answers
54 views

bash remove members Slack from channels using xargs and sleep?

I'd like to be able to remove a batch of people from a "private" Slack channel. Use case: whoops, I just added 137 people to the wrong channel! The Slack Member ID list is obtained from an Airtable ...
0
votes
1answer
28 views

Use xargs to build and run a command list

How to use xargs to build and run a command list such as these: #1 cmd1 <arg1> && cmd2 <arg1> && cmd3 <arg1> #2 cmd1 <arg1> ; cmd2 <arg1>
0
votes
1answer
70 views

shell linux unix xargs -i replace string

I have hard time understanding the xargs part of this command : find -type f | sed 's/ /\\ /g' | xargs -ifil file fil | \ grep ELF | grep executable | cut -d: -f1 | xargs -ifil find fil -exec ...
2
votes
1answer
312 views

Who is eating data? Xargs?

I am trying to parse a recursive directory of PHP files using the built in PHP linter, which works like this: $ php -l good.php No syntax errors detected in good.php $ php -l bad.php PHP Parse error:...
2
votes
2answers
160 views

dirname appears not to work with xargs

xargs and basename work together as I would expect: $ printf '%s\n' foo/index.js bar/index.js baz/index.js | xargs basename index.js index.js index.js xargs and dirname, though, appear not to work ...
1
vote
2answers
42 views

Prevent the machine being slowed down by running out of memory

My software runs a command that looks something like: find | xargs do a potentially memory hungry job The problem is that sometimes a potentially memory hungry job gets too hungry, the system gets ...
1
vote
0answers
84 views

How to improve this 'sed' search & replace command?

How to search and replace recursively through multiple files in a directory, using essential tools installed in mostly any Debian/Ubuntu machine? There are multiple answers in Stack* where to find ...
0
votes
1answer
85 views

How can I use an argument from xargs to evaluate another expression?

I would like to evaluate a basename expression given an argument from xargs. I tested: find . -name '*.txt' | xargs -I f cp f DIR_OUT/copied_$(basename f) which gives no file or directory because $(...
0
votes
4answers
170 views

How to find filenames, sort it alphabetically then only head the first 3 characters?

I want to find all files in the current directory, sort them alphabetically before processing their content to extract the first 3 characters in each of them. Doing so will create a sentence that I ...
5
votes
4answers
59 views

Replicate directory structure applying a command to each file instead of simply copying it?

Over time, I've encountered the same pattern again and again: I have some kind of directory structure: example/ ├── a │   └── c │   ├── d.txt (120k) │   └── e.txt (60k) └── b └── f.txt (...
0
votes
3answers
46 views

Using xargs command

Can i use ls - t | xargs > output.txt by being outside the directory for example I want to access /home/123/script/final directory and then perform the above function. Something like this: ls - ...
0
votes
0answers
18 views

Using xargs -n and -I together [duplicate]

I have 600 files I wanted to copy to S3. Wanted to do it in batches of 10, so I wrote: $ ls -1 | xargs -ILST -n 10 echo s3 cp LST xx s3 cp LST xx f9b3ac7e-3683-42dd-aed3-41b36bcf822c f9c30a0d-c196-...
10
votes
4answers
1k views

Move all files NOT ending with .txt [duplicate]

In the directory /home/username/data I have both files and directories. Some of these filenames end in .txt (to which I'll refer as text files), others don't. The same happens in the subdirectories. ...
0
votes
0answers
59 views

problem with find xargs and tar concatenation

I want to store all the png files in a directory tree. I used find . -iname *.png| xargs tar -czf renderresultsall.tar.gz but I get only a part of the files, some directories are missing e.g. ....
2
votes
2answers
125 views

Why xargs can't work with tail -f?

I want tail -f /var/log/syslog | grep it with pattern "arpwatch" and send every line to myself via jabber: xmpp username@jabber.server using xargs tail -f /var/log/syslog | grep arpwatch | xargs ...
0
votes
1answer
44 views

Creating text files in every sub-directory

I have a directory hierarchy named, for example, abc and a text file names.txt. I need to choose several lines from the text file and then create new files with sample text, say "Hello world", in ...
0
votes
1answer
44 views

xargs vertical alignment of output

I want to extract certain values from files in many subdirectories. I have a working code that does this: for i in */; do grep "free energy" "$i"filename | tail -1 | xargs -I{} echo "$i: {}" >>...
4
votes
1answer
36 views

Can zargs run aliases?

I have pip install -U aliased as pi. I want to run: zargs ~/scripts/python/**/requirements.txt -- pi -r Is there any way to do this? I also tried this ugly alternative: zargs ~/scripts/python/**/...
1
vote
1answer
46 views

Why does `xargs -n ` on SmartOS (SunOS) behave differently than other implementations?

It seems the -n option on the xargs found in SmartOS (and I assume Solaris) does not behave like any other version of xargs I've encountered. Take this example: Builtin /usr/bin/xargs (odd behavoir):...
7
votes
2answers
712 views

How does xargs know when a stdin input ends, so that it can start processing it? [duplicate]

After reading Stephen Kitt's reply, xargs waits for receiving the stdin input before processing any of the input, such as splitting it into arguments. How does xargs know when a stdin input ends, so ...
1
vote
1answer
56 views

Does `xargs -x` never execute a proper subset of arguments where the command line length does not exceed the `-s` limit?

xargs has an option -x which specifies that xargs exits if the size (see the -s option) is exceeded. Does that mean that xargs either executes all the arguments at once (if the number of characters ...
0
votes
3answers
444 views

How can I specify to xargs to run a command with all the arguments at once?

xargs has an option -n for specifying the maximum number of arguments to a command to run at each time. Is there a way to specify that xargs should always run any command with all the provided ...
0
votes
1answer
37 views

Do the number of the arguments converted from the stdin have to be the same as the number of placeholders in the command?

When xargs creates multiple arguments from a stdin input stream (-d can specify the separator for splitting a stdin input stream into several arguments), how does xargs rearrange them in the command ...
0
votes
2answers
30 views

du calculating whole directory size when we pipe the null input, how to stop it

[emdfqmm@nfwne ncndnkln]$ ll -h | grep "Oct" | grep "2018" | xargs du -ch 5.0G ./something 5.0G . 5.0G total [emdfqmm@nfwne ncndnkln]$ ll -h | grep "Oct" | grep "2018" | wc -l 0 When it got ...
4
votes
2answers
447 views

find -exec {} + argument list limit

I know that when the maximum argument list size is reached, xargs keeps creating new lists until all of the files are included; but does find -exec <command> {} + do the same thing or will it ...
4
votes
1answer
95 views

GNU Parallel doesn't run the jobs until the program has exited

When I run (rss-notifier's code is included at the end), rss-notifier.zsh https://www.wuxiaworld.com/feed/chapters ".*"|parallel --null -k --lb echo {} I get, Title: Sovereign of the Three Realms - ...
0
votes
1answer
146 views

How to open file in sublime and execute with python using xargs [closed]

I'm trying to open a python script and run it at the same time using xargs. I've tried: subl script.py | xargs python3 And a few other variations but none seem to work. How would you do this using ...
0
votes
1answer
24 views

Trouble understanding gsettings + xargs behaviour

To set the stage, I have this 2 equivalent and working 'xargs' composed commands, in this sample echo scenario: // ok $ echo org.cinnamon.desktop.keybindings.wm move-to-workspace-5 | xargs echo org....
0
votes
1answer
27 views

Distinguish a command not a native second transmitter

suppose [root@iz2ze9wve43n2nyuvmsfx5z /]# find . -maxdepth 2 -type d | ls bin dev home lib64 media opt root sbin sys usr boot etc lib lost+found mnt proc run srv tmp ...
0
votes
0answers
82 views

curl stops working when used in combination with xargs

I need to check a list of domains in parallel. So I was planning on using curl and xargs. This is check.sh: #!/bin/bash domain=${1?Pass the domain as a parameter} curl -o /dev/null --silent --write-...
2
votes
2answers
604 views

Run curl commands in parallel using xargs with inputs from csv

I have a csv file with several columns including a sequence number and an image URL. The file is 450+ lines. 1,text1,text2,http://image_a.jpg 2,text1,text2,http://image_b.jpg 3,text1,text2,http://...
3
votes
2answers
150 views

How to pass a list of file names to xargs after checking if the file exists?

I have a command (command1) that returns a list of file names like below /consumer/a.txt /consumer/b.txt /consumer/doesnotexist.txt When I pipe the output like command1 | xargs command2 command2 ...
3
votes
1answer
147 views

Call a command, wait, then execute another command

This feels like a situation where I need to watch a stream (stdin), if a line comes in, wait a moment, then fire the command and wait some more. Using a tool like pyinotify or fswatch, we can watch ...
0
votes
0answers
194 views

xargs argument in the middle of command [duplicate]

Why is this command not working? echo 'foo bar' | xargs -I % -L 1 echo yeah % yeah It produces the following output: yeah % yeah foo yeah % yeah bar While I expected the following output: yeah ...
1
vote
1answer
72 views

xargs plus shell string manipulation vs sed [duplicate]

I am trying to summarise the file extensions in a directory recursively. find .| xargs -d "\n" -I@ echo "${@##.*}" | sort |uniq -c But this is giving me a series of blank lines. Not what I wanted. ...
0
votes
2answers
538 views

Using regular expression for rm and ls

QUESTION: What is happening here and how do I fix it? PROBLEM: When I do: $ls | grep -P "file[1-9]{3}.txt|file[1-9]{2}.txt" I get: file11.txt file12.txt file13.txt file14.txt file15.txt file16....
0
votes
1answer
136 views

how to use find + xargs to make symlinks to selected files while keeping relative directory tree (uses gnu cp -s)

I'm trying to replicate select files from a directory structure as symlinks in a duplicate directory, eg from a directory structure such as this: ../1/a/data1.txt ../1/a/file1.txt ../1/a/b/file2.txt ...
-2
votes
1answer
102 views

xargs: The command line for command is built up until it reaches a system-defined limit - What limit? [duplicate]

I looked briefly at the source code of xargs in findutils 4.6.0 and saw that 'n' defines: args_per_exec But there seems to be no default value for args_per_exec in find utils So where is the 'system-...