Questions tagged [xargs]

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

Filter by
Sorted by
Tagged with
-1
votes
0answers
23 views

Why is find -print0 | xargs -0 so much faster than find -exec? [duplicate]

~ ❯❯❯ time find ~/Desktop/to_sync -type f -print0 | xargs -0 ls -lh | tr -s ' ' | sort -k 5 -h > asort noglob find ~/Desktop/to_sync -type f -print0 0.00s user 0.01s system 89% cpu 0.014 total ...
1
vote
2answers
35 views

How can I expand a single-quoted tilde from xargs in sh?

I have a list of files stored in a file, and I want to grep each of those files for a search term. However, xargs forwards arguments as single quoted strings, so for all of the files prefixed with a ~,...
1
vote
1answer
28 views

Handle umlauts in file names when using xarg

I've seen some similar questions here where people have problems with xargs handling spaces in file names. Surprisingly, I don't run into this issue, but a similar one. I'm copying a fixed amount of ...
1
vote
1answer
8 views

How can I run `gradlew clean build` in all subdirs starting with given prefix?

I have multiple project directories project-one, project-two, different-project. I want to run ./gradlew clean build within all these directories that begin with project-. Can I use xargs to do that? ...
1
vote
1answer
25 views

Search for a string in all searched files gives /bin/grep: Argument list too long error

I tried the below command to search for in all files user /var sudo find . -type f | xargs sudo grep 202007602 | tee /tmp/202007602.log Output: grep: ./www/html/jenkins/workspace/node_modules/xpath/...
1
vote
0answers
28 views

xargs with zgrep is giving the error

I have many gzipped files and I am trying to find some string pattern from the thousands of file but I am getting extra .gz while trying to zgrep it. Please refer the below, could you please advise. ...
0
votes
1answer
47 views

How to run second command only when first is successful when using find and xargs?

My situation is: I have many files with a name timestep1_i for many values of i and I am trying to combine all the files for timestep1 with a program called combinefiles. I want to do it in parallel (...
5
votes
3answers
389 views

Reliable way to open files given by the result of find … -exec grep … {} \+

I often run commands like this: find … -exec grep … --color=always -l {} \+ and sometimes I need to open the matching files in Vim. But what is the most reliable way to do so? One way seems to be vim ...
0
votes
1answer
31 views

Why does host and nslookup think IP address is a hostname?

Why does this command fail (this is a simplified version of the actual command)? /tmp $ echo 74.6.231.20 | xargs -n1 -I {} echo "$(host -d {})" Trying "74.6.231.20.<REDACTED>.<...
2
votes
2answers
132 views

-exec to xargs conversion in find command

I'm using the below command in my script to perform a dos2unix operation on the files which I copy from Windows to Linux. There are many files, so it takes a considerable amount of time to perform ...
0
votes
0answers
15 views

Issue launching vim using xargs -r on a fzf result [duplicate]

I think I am misunderstanding something in the Linux piping with respect to xargs -r in combination with fzf. In my bashrc I have the function ef () { fzf | xargs -r -I vim } But written like ...
1
vote
2answers
46 views

running tasks in parallel as well writing to single file

#!/bin/bash range=$(seq -f "ma%04g" 5001 5505) for n in $range;do ping -q -c 1 -w 3 -s 10 $n >/dev/null if [ $? -eq 0 ];then awk -F, -v key="${n}" -v ...
5
votes
1answer
218 views

Why is `-r` seemingly ignored when used with `-0` in GNU xargs?

The regular case with linefeeds, xargs calls printf and something is printed: >>printf "foo\n" | xargs -r printf "->%s\n" ->foo >> With an empty input instead, -...
-2
votes
2answers
36 views

How to search for a sub-string in the files which contain another sub-string

I wanted to search for a string in a list of files which has another string. Basically, I had to get the list of files with the first string and then do a search on these files for another string. The ...
8
votes
1answer
722 views

Why do I get an error when deleting entries from Bash history?

I have some commands in my Bash history that I want to remove. I can find them with history | grep "command with password" then remove them with history -d <line-number> However, when ...
0
votes
1answer
25 views

cant modify files with the same name which are in different locations when piping find to xargs

on mac using gnu tools Im not sure whats happening but it seems piping the output of find to xargs has some issue with touching files with the same name that appear in the directory structure in ...
6
votes
5answers
375 views

How to edit a list of generated files whose names contain spaces

I've got a relatively small list of filenames generated from a pipeline based on find. The file names contain spaces and possibly punctuation but definitely no other non-printing characters or ...
0
votes
2answers
47 views

Using tail -f together with sed and xargs

Suppose I have the following process to write a number + single quote to the file /tmp/test every second: for i in {1..1000} ; do echo $i\' ; sleep 1 ; done > /tmp/test I then want to use tail -f ...
2
votes
2answers
32 views

Process in Pipe which Processes 256 bytes at a Time

I have a c program on a Cyclone 5 that does an FFT using the connected FPGA. This program currently takes 256 bytes from stdin and then process it gives the FFT results on stdout. I run it like this ...
1
vote
3answers
154 views

Making a pipe from `ls` to `mv`

I am trying to make a small utility for myself on the command line - for a given current work directory I would like to find the most recently added file and mv it to a name given by argument I have ...
0
votes
0answers
41 views

zgrep large number of files with regex pattern

I am attempting to search a large number of .gz compressed files in a single directory using zgrep. The files in this directory represent the logs for a service I am working on. In these files I am ...
0
votes
1answer
32 views

Change multiple file's content

I have a file called list.txt and its content is as follows: paswd.c acnt.c control.c ... (The rest is omitted) I want to do something like the pseudo code: point to first line of list.txt; while (...
0
votes
1answer
31 views

need script to rename files replacing double space with single space

Can someone help me figure out how to remove double spaces from directory names? I'm using a service which gives me a directory structure of files whose names contain spaces. Sometimes the directory ...
1
vote
0answers
33 views

Inconsistent behaviour when piping output of Tail into Xargs through an editing command

I'm giving in to asking the SE spirits for assistance. I will expand in detail below, but I've boiled the inconsistency down to these 3 lines. I am trying to grep a string in between single quotes (...
1
vote
2answers
24 views

Search and replace login string in all .php files in directory when filenames contain spaces

I changed my password and username for mySQL and I need to replace the connection string in all of my PHP scripts accordingly. I am having trouble with the command because many of my php file names ...
1
vote
3answers
22 views

How can I render newline escape sequences in xargs?

The following command prints 3 lines: echo -e 'a\nb\nc' result: a b c How can I achieve the above result when passing from xargs? echo 'a\nb\nc' | xargs -I{} echo -e {} Current result: ...
0
votes
3answers
55 views

How to get the total duration of all video files in current folder and sub-directories [duplicate]

I am trying to get the duration of a bunch of files in current directory and its sub-directories all ending in .mp4. I'm trying to use ffprobe. To make things simple, I am not using find, but ls. If ...
0
votes
1answer
29 views

How could I solve the error of psql: Argument list too long?

I have a script that contains the following psql command: psql -h $PHOST -p $PPORT -U $PUSER -d $PDATABASE -c "SELECT COUNT(*) FROM (${SQL%?}) AS query;" when I passed a simple query that query one ...
1
vote
2answers
70 views

Using xargs in case statement

I want to pipe the output of a long command (which cannot be placed inside $()) to a case statement, so I'm using xargs like this echo "this" | xargs -I{} case {} in; this) echo "is a test";; esac ...
0
votes
1answer
21 views

Why none direcotry send via pipe to a grep get searched result?

My current directory: pwd /home/debian Search a string -dig in /home/debian/mydoc/source. grep -lr -e "-dig" /home/debian/mydoc/source #get nothing as output In my opinion ,sent nothing via pipe ...
0
votes
1answer
24 views

How to symbolic link the files to new directory based on names in text file?

I have a directory named STRBAM. In that, I have following .bam files that are symbolic linked from another directory. Sample-CK-4952-01A-01D-1719-10.bam Sample-A6-5656-01A-21D-A270-10.bam Sample-AZ-...
3
votes
4answers
54 views

Is there a way I can process the combined output of multiple commands at once, using xargs?

I have multiple shell commands that I want to pipe into the same xargs instance so I can process them together. I have two inputs, a file and a glob expression: $ cat subdomains.txt admin.site.com ...
3
votes
0answers
59 views

Measuring cumulative peak memory usage of multiple parallel processes

Imagine I run a bunch of processes in parallel using xargs and want to measure their cumulative peak memory usage. How can I do that in Linux? GNU time only measures peak RSS of a single process I run....
2
votes
1answer
70 views

Passing PID from ps command to netstat for port #

I have a process that can have multiple instances. ps shows the instance name, whereas netstat of course gives the name of the binary instead of the instance name. My goal is to use something like ...
0
votes
2answers
38 views

How to use grep -f and perl to replace file inline substituting new lines with “;X”

I have the following file: $$ head on_this_file.txt Instance,Session,SenderCompID,Type,SrcAddr,SrcPort,DstAddr,DstPort,Protocol,Client,MIC,curr 304,PBAR29,PBAR29,V,146.127.180.96/27,,162.69.138.157,...
0
votes
1answer
11 views

Copying a list of test/path/to/files to list of prod/path/to/files

I would like to copy a list of files in the form test/path/to/file/filename.xyz to their corresponding production path prod/path/to/file/filename.xyz. If the test path and the prod path are the same ...
0
votes
2answers
55 views

xargs and zcat: silence errors

Suppose I have: ** EDIT TO HAVE CLOSER CORRESPONDENCE TO ACTUAL USAGE ** find ... -regex ... | head -n 1 | xargs -I {} zcat {} | head -n 1 # next, I do some other things now, everything works ...
0
votes
1answer
42 views

Why the 'xargs' command do not work with figlet but works fine when i run it with 'ls' argument

For example: find /usr/share/figlet/ -type f -name "*.flf" | xargs ls -l -rwxr-xr-x 1 root root 3369 Mar 31 17:54 /usr/share/figlet/Tombstone.flf -rwxr-xr-x 1 root root 7641 Mar 31 17:54 /usr/...
2
votes
3answers
60 views

How to execute a script on multiple files using find?

So basically I need to find a bunch of .csv files then use my script that I wrote on all of them. I have find . -type f -name "*.csv" | xargs ./extractdata this works but only does one file and not ...
1
vote
1answer
44 views

Collapse grep results into one line while keeping unique values and removing duplicate values?

I'm using zsh but open to a bash solution as well. Suppose I have the following command: ls **/*/assessment(.) | xargs egrep "(^ \[\./.*\]$|^ input = .*$)" Which gives me an output that ...
2
votes
1answer
58 views

How to retry xargs commands that have failed up to 5 time

I am facing a challenge with my script. I am using xargs with curl to make over 100 000 curl command to an REST API, occasionally some of them will fail with 502 or 504 errors. What I need to do is ...
1
vote
1answer
50 views

Curly brackets not getting replaced on xargs command

I've been trying to run this command. However, I'm getting some rather unexpected results. It seems that it's an obvious overlook on my part, but I can't figure it out. Here's what I tried: Given ...
0
votes
1answer
106 views

Force xargs to stop on first command error

I'm running a command to find all make files in a directory and run make build. I would like to get xargs to stop on the first make build that fails. Here's the command I have so far. $ find . -...
0
votes
1answer
251 views

xargs does not quit on error

I have a bash script where I use find to get a bunch of files in a directory, from which I then use xargs to execute said files in a chroot environment 1 script at a time. My understanding has been ...
0
votes
1answer
336 views

CP invalid option error

I'm getting an error that I can't make heads or tails of when trying to use cp through xargs grep -l -r .mp4 * | xargs cp -t ./Destination Results in cp: invalid option -- 'G' The goal here is to ...
0
votes
3answers
203 views

How do I tar all files without paths

I want to find all .c files in current directory and subdirectories and tar them. I try to use the following way to achieve this goal but when i unzip files, the files in different folders. I don't ...
-1
votes
2answers
119 views

Why does xargs output results with new line characters?

When executing the command find . -maxdepth 1 -regextype posix-egrep -regex '.*/[a-zA-Z]+\.txt, it returns the following results. ./testfile.txt ./testread.txt In contrast the the command find . -...
2
votes
6answers
352 views

How could I improve this script which sorts files according to extension?

I have a small script which simply shall go through my Downloads folder and then sort the files according to the extension. How can I make this cleaner/better? I would like to simply maintain a list ...
0
votes
3answers
96 views

Run find on find

I did a web seach for "linux run find on find" but it produced no relevant results. I want to build list of files by find and then run find again on that list. After fixing some "silly" mistakes I ...
0
votes
1answer
97 views

Why does `ls | xargs wc -l` format prettily?

Running wc -l (line count) individually on a file gives: λ wc -l pacman_Qemq.txt 235 pacman_Qemq.txt But running ls | xargs wc -l gives: λ ls | xargs wc -l 242409 pacman_database.tar.bz2 235 ...

1
2 3 4 5
11