Stack Exchange Network

Stack Exchange network consists of 174 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

0
votes
3answers
29 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
17 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
43 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
58 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
39 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
22 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
25 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
35 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
604 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
52 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
86 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
29 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
23 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
337 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
59 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
58 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
21 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
34 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
200 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
54 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
75 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
73 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
55 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
158 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
0answers
130 views

grep: conflicting matchers specified

I'm using find with xargs and grep to find text which we need to translate in our application. find . -name \*.vue -not -path "./vendor/*" -not -path "./node_modules/*" -not -path "./public/*" -not -...
0
votes
1answer
89 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
77 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
353 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
343 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
39 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
83 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
93 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
80 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
178 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 ...
4
votes
3answers
846 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
124 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
41 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
27 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 ...
3
votes
1answer
191 views

How to maintain sort order with xargs and gunzip

I'm attempting to extract the contents of some files by alphabetical (which in this case also means date and iteration) order and when I test the process first with ls: $ find /opt/minecraft/wonders/...
2
votes
2answers
71 views

Have `xargs` run the arguments it's received every <maximum amount of time> instead of every `-n` arguments?

I am using fswatch and xargs to watch for file system changes, and run commands depending on which files are changing. fswatch prints the changed files to stdout, and xargs <my command> ...
1
vote
2answers
68 views

Changing a multiple file extension using single line command

I have some files whose names contain multiple extensions: $ ls -r File1_345.R.12345 File1_3.234.R.6789 File1_2345.R.2345 File1_12345.R.12345 $ I want to rename them to remove all the existing ...
-1
votes
3answers
64 views

Why is this command working only for every other line?

When I run \ls | xargs -I {} echo {} | sed 'N;s/\n/xxxxxxxxx/', I get this: - Books aliasxxxxxxxxxA New Kind of Science Computability-and-Logic.pdfxxxxxxxxxComputability-and-Logic_k2opt.pdf Hein J. L....
8
votes
6answers
2k views

How do I create directories named after each month?

I would like to create a directory name for each month. I know, after some playing with the shell, that: date -d 1/01 +%b # Gives Jan date -d 2/01 +%b # Gives Feb . date -d 12/01 +%b # Gives Dec So ...
0
votes
1answer
65 views

What is the best method to get rid of a pattern in multiple php files? [closed]

Working on infected website with hundreds of php files with the following injected signature code in the top of each file: <?php /*457563643457563643*/ ?><?php /*5467543654675436*/ ?><?...
0
votes
2answers
42 views

Converting a working command into shell script file which gets arguments

Hi my working command is: grep -l "my text" file*.ext|xargs ls -lart this command is very useful for me and I wanted to create a shell file which does it with fewer typing, like this: fn "my text" ...
1
vote
3answers
36 views

Rename a group of files to a string that exists inside each one

I have a group of json files. Each file contains one json object and they all have the same schema. There is a field in the json that I want to rename the file to. How can I do that? I came up ...
3
votes
3answers
102 views

Listing number of files in each folder where folder name matches a pattern

I would like to recursively search a directory tree and list the number of files available in each folder that have a name corresponding to a given string. In effect, I would like to return results of:...
2
votes
1answer
2k views

how to solve the error “arg list too long” [closed]

I am running the commnad ls -lt *$ID* this command is working find if I am running separately but with in the script it returns the below error arg list too long. The id is a unique one there is only ...