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

learn more… | top users | synonyms

0
votes
5answers
57 views

How I delete all files in a directory with specific extensions except the last 5 of them [duplicate]

The directory contains files with different extensions. I would like to delete all files with extensions .gz, zx, ext4 except the last 5 files. I can list all those files with ls -l | grep '\.gz\|xz\...
1
vote
2answers
40 views

How to find and copy files based on extension?

I have a photorec folder from a data recovery process that has 2481 folders with the recovered files. The folder names are in the sequence recup_dir.1, recup_dir.2 ... recup_dir.2481 I got a list of ...
3
votes
1answer
38 views

Processing timestamps of tcpdump output in realtime

I would like to maintain a file which contains the number of seconds since a packet matching a tcpdump filter has been seen. The aim is to work out when a chatty client is no longer on the network. ...
5
votes
8answers
415 views

Remove all duplicate word from string using shell script

I have a string like "aaa,aaa,aaa,bbb,bbb,ccc,bbb,ccc" I want to remove duplicate word from string then output will be like "aaa,bbb,ccc" I tried This code Source $ echo "zebra ant spider ...
0
votes
2answers
37 views

source and destination path for the copy command in single file then how to copy?

I have a single file which contains source file paths and destination file paths. example $ cat test.txt /home/data/source.txt /home/code/destination.txt /home/abc/def.txt /home/mnp/xyz.txt ...
0
votes
1answer
27 views

find … | xargs grep --> colors missing for output of grep [duplicate]

This way I get colored output: grep class testdata.py Since this gets set in my .bashrc: alias grep='grep -n --color' But if I search like this, I see no colored output: find -name '*.py' | ...
2
votes
2answers
155 views

cp after xargs not working

I run debian jessie on Host 64-bit and in virtualbox 32-bit. To spare traffic I try to cp the i386 packages from host to the shared folder, for using them in virualbox. My Hostname/var/cache/apt/...
5
votes
5answers
213 views

Find fullpath and filename under a directory then pass to an executable file as arguments

I'd like to find fullpath and filename of all .txt under a directory, and pass to a executable file ./thulac . It cost me some time to reach: find /mnt/test -name "*.txt" -print0 |xargs -l bash -c '....
0
votes
3answers
90 views

Redirecting sed to curl then to file

I need to download some pages from a site. What am I trying to do is using sed on the site source code to get the links, passing them one by one to curl and then output the downloaded file on the ...
0
votes
1answer
79 views

Why does “find / -name '*.txt' | cp /junk” not work?

If I want to find any files with .txt in the name, and for every match that is found copy it into the /junk folder the following could be considered to work; find / -name "*.txt" | cp /junk but ...
11
votes
4answers
957 views

How do I use `find` to go to directory of that file

I want to find a file and then enter the directory containing it. I tried find /media/storage -name "Fedora" | xargs cd but of course, I the is not a directory error. How do I enter its parent ...
1
vote
1answer
50 views

Why is xargs -n 1 so slow for long lines

A line generated with command echo {,·}{,·}{,·}{,·}{,·}{,·}{,·}{,·}{,·}{,·}{,·}{,·}{,·} contains 8191 words, which is 114687 characters: 106497 dots and 8190 spaces. Why does splitting it with | ...
1
vote
2answers
41 views

How to create symlinks from file

I have directory scalable for vector icon theme and I have bunch of symlinks in there which I want to replace by a file that contain names that I can use with ln command, I've create the file it ...
7
votes
2answers
88 views

output garbled when running “xargs ls” in parallel

I want to list all files in /usr/ using ls. I am not calling ls directly, but via xargs. Moreover, I am using xargs parameters -L and -P to utilize all my cores. find /usr/ -type f -print0 | xargs -...
3
votes
3answers
92 views

Bulk renaming of camelcase files to include spaces

I'm attempting a batch rename of camelcase-named files to include spaces between adjacent upper and lower case leters. I'm using Mac OS so the utils I'm using are the BSD-variant. For example: 250 - ...
0
votes
3answers
54 views

map the results from find

I have these results from find: $ find subprojects -mindepth 1 -maxdepth 1 subprojects/install-globally-first subprojects/installation-test-project-custom-config subprojects/install-via-github ...
0
votes
1answer
115 views

Using sed to Replace Environment Variable with directory path

I am unsure if I am misunderstanding something or just not searching correctly. However, I have an issue that I am testing with a simple echo command and piping to sed to replace part of the string ...
1
vote
2answers
35 views

How to surround xarg's inputs with more arguments?

I'm trying to somehow use xargs so a program whose outputs are the lines <ARG1> <ARG2> ... <ARGN> will cause the execution of the following command: command <...
3
votes
1answer
60 views

Executing the same command with different arguments in parallel [duplicate]

I think that xargs is intended exactly for this, but I tried using it and couldn't figure it out. I have a command foo -bar 123 --baz=whatever. I want a Bash one-liner to run three copies of it in ...
3
votes
3answers
60 views

Applying bash function to each file in subfolder recursively

I am trying to write a script that will apply a bash function for each file in a directory recursively. For example if the directory tests had all my files and sub-directories in it, the script find ...
3
votes
3answers
285 views

Check file content looking for corruption, file size indicates size “zero”

I have a very strange situation where I have a file system that contains a number of files that are of varying size but appear to have been corrupted and show no contents when cat-ing the file. I ...
0
votes
2answers
219 views

ssh-add add all private keys in .ssh directory

In my day-to-day, I need to ssh to various machines, all of which I have a different private key for. When I start a new shell session - only my default id_rsa is added to the ssh key chain - I have ...
1
vote
3answers
89 views

Search for a string in a file and rename multiple files to the results

I am attempting to recursively search through a list of files and if the file contains a string, rename the file to the grep results of said string. The sample files contain a the following content: ...
0
votes
1answer
42 views

How can I prevent arguments to `xargs` from being prefixed with spaces?

I have extracted an archive whose contents are not stored in a sub-directory into a directory with filled with other files and is now cluttered and confusing. To fix this I have extracted the archive ...
1
vote
5answers
74 views

Deleting some of the largest files in a directory

I would like to delete a certain number of the largest files in a directory. I can get the filenames of the first ten with: ls -S | head (or a richer albeit more complex to parse ls -lS | head) How ...
0
votes
3answers
47 views

What are replstrs like {}?

In the documentation for xargs there is mention of a "replstr" that the -I flag takes. I started reading about it when I found this command to run fswatch: fswatch -0 -e ".*" -i ".rb" . | xargs -0 -n ...
0
votes
3answers
47 views

Run command output lines as another command in linux

I am running this command : find ./ -type f -printf "wc -l \"%p\"\n" which gives this output: wc -l "ANLS 457567.pl" wc -l "ANLS 457567.pl" Now I want to run this whole line as another command. ...
0
votes
2answers
31 views

locate(1) buffers its output [duplicate]

I'm using locate(1) from GNU findutils for a little task and it seems as if it buffers its output. I am piping the output of locate to another task that will process the lines as locate finds them. ...
1
vote
1answer
52 views

How to check xargs's version?

I'm on a Mac and I want to get the xargs's version. I tried xargs -v, xargs --version, xargs -h, xargs --help, xargs, man xargs but still can't find and version related info. How can I get its version?...
1
vote
2answers
128 views

How to recursively side by side diff directories with line numbers in the diff in unix?

My scenario is to perform side by side diff directories using: diff -ry <folder1> <folder2> along with the line numbers in the diff output. By default line numbers are not displayed in ...
1
vote
1answer
291 views

Piping list of files and directories to du only shows sizes of directories?

Let's say I have a directory with multiple subdirectories, each of which contains some files: 1/a.txt 1/b.txt 2/c.txt 2/d.txt 3/e.txt 3/f.txt I want to see the size of each file. Please keep in mind,...
3
votes
1answer
428 views

How to use scp with xargs? [duplicate]

I am trying to move very big file from one host to another host. Also the file names are too large so I have to use xargs. Also all the sub directories need to be copied also I am using the below ...
2
votes
1answer
289 views

How do I get xargs to show me the command lines it's generating without running them?

A fair number of linux commands have a dry-run option that will show you what they're going to do without doing it. I see nothing in the xargs man page that does that and no obvious way to emulate it. ...
0
votes
1answer
47 views

How to list SVN repository name with latest revision number

I want to get for each of my SVN repository its latest revision number. My command looks like currently like this: ls | xargs -n 1 svnlook youngest This prints a list of revision numbers. But I'd ...
2
votes
2answers
108 views

finding a folder names based on list contained in .txt file

I have a .txt file containing 150 different ID number on each line like so: 12345 15876 19643 12586 Located in the same directory as the .txt file, I have 300 folders and I want to copy only the ...
0
votes
1answer
408 views

xargs give me error cannot open `{}' (No such file or directory)

Can anyone explain why the command below produces the following error: cannot open `{}' (No such file or directory) Command $ ls -al|grep -v '^d\|^$'|awk '{print $10}'|xargs file '{}' I get the ...
1
vote
1answer
99 views

What does '-t' do in mv command? Example below

ls -lrt |grep 'Jun 30th' | awk '{print $9}' | xargs mv -t /destinationFolder I'm trying to move files from certain date or pattern or createuser. It doesn't work properly without the -t option. ...
2
votes
3answers
144 views

Accessing each line in .txt file, download and rename links

Let's say I have a .txt file where I have a list of image links that I want to download. example: image.jpg image2.jpg image3.jpg I use: cat images.txt | xargs wget and it works just fine What I ...
0
votes
3answers
408 views

piped command after grep not working

I want to monitor a file. So I have tailed a file using below command, to execute a script per line. tail -3f logfile.log | grep "action.*add" | sed -u -e "s/^/'/" -e "s/$/'/" | xargs -L 1 -P 5 bash ...
2
votes
2answers
684 views

Pass input file through pipe as argument?

I have two issues. I am trying to pass files through a pipe as an argument, and I am trying to use that file as a variable inside the sh function. Here is my command: find . -name 'segment*' | ...
1
vote
3answers
151 views

How to Distribute Computing of `tar czf` for Longer Time?

My systems go under heavy load when I run sudo tar czf /media/masi/ntfsDisc/backup_home.tar.gz $HOME/ Fans goes to max etc. I would like to find a better balance between computing and power ...
1
vote
2answers
252 views

parallel processing using xargs

How to execute a bash script in parallel for each line ? Actually, I will be tailing to log file and for each line found, I want to execute script in background something like below: tailf logfile....
-1
votes
1answer
134 views

How can I pass the file names to xargs and truncate them? [closed]

I have to write a script which will ssh into servers and truncate log files My script is #!/bin/bash for server in $(cat c10_servers.txt) do ssh $server " ls /var/log/hello grep -i hello.log. |...
1
vote
1answer
441 views

xargs: argument line too long

When I run below line in a shell script: /sbin/iptables-save -t filter | grep -- "-A INPUT" | grep -v "fail2ban-\|f2b-" | sed -e "s#^-A#apply_rule /sbin/iptables -D#g" | xargs -0 echo -e "`...
0
votes
2answers
208 views

How to print lines using find and sed in multiple files?

I've many files in a directories structure. I want to extract some string (namely urls) by using a regexp, from those files. I've tried this : find . -path "*alder/ * / * .html" -print | xargs sed -...
3
votes
1answer
59 views

Shell syntax for redirecting arguments?

If I want to redirect not the stdio but as arguments the output of a program , should I use xargs? For example, I do ls and I want the filenames to be arguments to the next command rather than an ...
2
votes
2answers
2k views

xargs on OSX: illegal option --

I'm on OSX. I want to run a python script against all pngs in a particular directory. This is what I've tried: find docs/ -name "*png" | xargs --replace=F python myscript.py "F" But I see this: ...
3
votes
3answers
87 views

How can you move or copy specific files from a list of text files

So I have a directory of like 200 of the the following types of files: gre_6_c1_d34567.h3 gre_6_c1_d95543.h3 gre_6_c1_d42354.h3 gre_6_c1_d01452.h3 gre_6_c1_d23168.h3 gre_6_c1_435435.h3 The only ...
3
votes
4answers
286 views

'find -mtime -1 -print | xargs tar' archives all files from directory ignoring the -mtime -1 argument

I'm trying to create a backup script. I've managed to get this script working fine on a CentOS 6.7 machine and am now trying to get it working properly on Debian 7. I am running into a problem I can'...
1
vote
3answers
823 views

Right syntax for awk usage in combination with other command inside xargs sh –c

How to make this command work: ls * | xargs -I {} sh -c 'echo {}; awk '{print $1}' {} | uniq' It should do the simple thing: print for each file in the folder its name and uniq values in the first ...