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
votes
2answers
41 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
42 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
24 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
28 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
306 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
120 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
41 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
81 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
37 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
81 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
55 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
39 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
51 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
92 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
41 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
34 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: {}" >>...
3
votes
1answer
29 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
38 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
669 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
54 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
243 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
35 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
28 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
399 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
75 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
111 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
22 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
46 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
416 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
103 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
111 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
137 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
64 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
359 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
112 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
89 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-...
1
vote
2answers
673 views

echo list / array to xargs [duplicate]

Say I have a list/array: list=(a b c) how can I echo each element to xargs? Something like: for v in list; do echo v; done; | xargs is there a less verbose way?
0
votes
1answer
438 views

How to add a newline in xargs

I'm trying to write a command to capture every license in the linux OS (kali) and associate it with the correct package. The basic idea is that you search /usr/share/doc recursively for "copyright" ...
0
votes
2answers
69 views

Find with absolute path inside a bashscript | xargs basename

I have to find recursively inside a bash script. Since I can invoke the bash script from anywhere, I am forced to use the absolute path. Sometimes the absolute path can get very long, and the output ...
0
votes
1answer
126 views

Passing complete file path info to xargs

I have a bash script in which I'm trying to list jpg files in order of modification date, followed by renaming them in numerical order (0.jpg, 1.jpg, 2.jpg, etc...) using xargs. This needs to occur in ...
0
votes
2answers
185 views

Have xargs pass a flag from stdin instead of command parameter

Given an application, myApplication, that streams lines to stdout $ myApplication flag1 flag2 flag3 How do I use xargs to pass those values as flags to a command instead of passing them as ...
2
votes
3answers
82 views

Find command that excludes paths listed in a file

I need to exclude a bunch of paths from a find command. For example: find "$(pwd)" -not \( \ -path "*/.git"\ -o -path "*/.git/*"\ -o -path "*/.vscode"\ -o -path "*/.vscode/*"\ -o -path "*/...
1
vote
1answer
351 views

xargs: 'ls' terminated by signal 13 [duplicate]

find . -type f -print0 | xargs -0 ls -ltr | head -n 10 | awk '{print $NF}' | xargs rm This command is giving me this: xargs: 'ls' terminated by signal 13 However, it's executing fine. It's supposed ...
3
votes
3answers
1k views

Xargs to extract filename

I would like to find all the .html files in a folder and append [file](./file.html) to another file called index.md. I tried the following command: ls | awk "/\.html$/" | xargs -0 -I @@ -L 1 sh -c '...
2
votes
2answers
167 views

Fixed last argument with xargs

Is it possible to use xargs to invoke a command so that the last argument of the command is fixed? My attempt: printf '%s\n' a b c d | xargs -I{} echo {} LAST ends up doing echo a LAST echo b ...
0
votes
1answer
56 views

curl from sitemap.xml?

I would like to curl a list of URLs (Namely as defined in https://example.com/sitemap.xml The closest I've been able to get to this goal is xargs curl --referer https://mywebsite.ca --user-agent "It ...
0
votes
1answer
28 views

How to use parallel correctly in this situation?

I have a file with multiple URL's in it (separated by a newline) and want to execute a bash command for each line. Here is the command: xargs -n1 -I+ ./info.sh https://+/.info/ +/ How can I execute ...