Questions tagged [xargs]

A command that constructs an argument list for a command from text given as xargs' standard input (or read from a specified file) thus allowing execution on the results of a search, for example. It is provided by the findutils package

Filter by
Sorted by
Tagged with
1 vote
2 answers
28 views

find special characters in filenames and copy them into new folder. filenames may contain weird non ascii characters and special ones

I like to copy all files with special character "|" in filenames (not the pipe one) into a folder. However, i have several problems cause filenames may include ascii and not ascii characters,...
Estatistics's user avatar
1 vote
2 answers
181 views

Performant sort files into subdirectories by content of metafile

-edit: more details, correct code- I want to move files from a directory into sub directories by data out of a metadata file. There are groups of files like <name>.<extension>. Each group ...
Andy A.'s user avatar
  • 133
0 votes
1 answer
321 views

grep command to get file list with concatenated custom text

I am trying to list of files' names with custom text(my another command) with it. I am using below command: grep -rl --include=*.php --include=*.html --include=*.js 'ajax.googleapis.com/ajax/libs/...
Atul's user avatar
  • 219
0 votes
1 answer
477 views

get xargs to run a command once for each input instead of once with every input

I thought I could run the following find ./ -iname "*\.mkv" | xargs -d "\n" ffprobe -show_streams -i to get codec information for each file, but it appears xargs is trying to pass ...
Aaron's user avatar
  • 1
0 votes
1 answer
48 views

How to change script for deleting files while names misses symbols?

I am trying remove files by names according this answer How to delete files listed in a text file But get following error: rm: cannot remove 'var/Resources/Images/fd29d33d.jpg'$'\r': No such file or ...
Mateech's user avatar
  • 131
0 votes
0 answers
260 views

Output of find | xargs not redirecting to log file

I'm developing a Bash script which cleans up old data files periodically, and right now everything works except for the log file I'm trying to generate so I can see what it did. The structure I'm ...
KneadToKnow's user avatar
0 votes
1 answer
81 views

How to move a matched id of mat files in different folder

I have Matlab (.mat) files in a particular folder. In a text document, I have some IDs list marked as 0 and 1. First I need to match the IDs and separate the mat files that are marked as '1'. For your ...
Jammy's user avatar
  • 1
2 votes
1 answer
424 views

Delete files not matching pattern using xargs

The following command is from https://www.tecmint.com/xargs-command-examples/ the example #9. It is to delete files not matching *gz from current directory. $ find . -type f -not -name '*gz' -print0 | ...
Logan Lee's user avatar
  • 123
0 votes
1 answer
429 views

nohup can't save the pid of the process into file with xargs command

In the script that I am building I am having problem saving the pid to file. If run in the terminal the command below: nohup mvn spring-boot:run > $HOME/logs/app.log 2>&1 & echo $! > $...
Rando Shtishi's user avatar
1 vote
2 answers
258 views

How to add .sh extension to script files in Linux

I have a dozen of files without extention, and I need to add .sh to all the files are a script Bourne-Again shell. How do you achevie that without using sed, awk,... I located the files like so: file *...
kaileeno's user avatar
2 votes
1 answer
2k views

Need to move files found using grep into a folder

As part of a University course, I'm trying to reclusively search for a string in a list of 500 files, and then copy those items found into a new folder. I can find the files without a problem using ...
Steve's user avatar
  • 33
0 votes
2 answers
123 views

Linux Command [Requirement] [duplicate]

Can anyone tell me what this command means? I've seen it in a tutorial but can't get it well. find . -type f | xargs file
user avatar
0 votes
1 answer
255 views

How can I pass command output as first argument to next command

I am using Virtualenv in Python, and I have to execute the pip command with sudo because of windows filesystem... executing sudo pip executes the pip outside virtualenv ... so im directly executing ...
zhong's user avatar
  • 1
0 votes
3 answers
475 views

How to count files separated by null characters, as returned by; find . -type f -print0?

Extract from man find: -print0 True; print the full file name on the standard output, followed by a null character (instead of the newline character that -print uses). This allows file names that ...
Broadsworde's user avatar
  • 4,012
0 votes
1 answer
130 views

Error when trashing oldest files in a directory. (gio trash error when used with xargs)

In 18.04 I was able to find and trash all but the newest n (e.g. 8) files in a directory with: find . -maxdepth 1 -type f | sort -r | sed 1,8d | xargs -d \n gio trash When I try this in a freshly ...
Broadsworde's user avatar
  • 4,012
0 votes
2 answers
95 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 ...
ermSO's user avatar
  • 101
11 votes
1 answer
5k views

How to pass list of names to be searched by grep using xargs?

I have a text file containing names (nameslist.txt) and I want to read them using cat and pipe the result with xargs to a grep command, so that grep checks the existence of each name that it receives ...
arash deilami's user avatar
0 votes
4 answers
76 views

Script to generate a list of urls from a list of authors

I need to take a list of authors names of which may consist from 1 to 4 words like this Osho Hartmann Nicolai Bird Robert Montgomery Coates Ta-Nehisi and generate URLs like this site.com/word1+word+...
Коля's user avatar
2 votes
1 answer
2k views

How to make xargs execute in parallel but show complete output of a single instance at a time?

I am running some query commands in remote host with xargs in parallel which is working efficiently and very well but I have some problem in finding in which host I am getting the query from. Right ...
Rakib Fiha's user avatar
2 votes
1 answer
342 views

Unzip a .zip file to all directories that contain a .php file that contains the text “house” inside?

How to unzip a .zip file to all directories that contain a .php file that contains the text "house" inside? Something like: grep -rl --include='index.php' 'house' /directory/path/of_the_index_file* |...
Jaro's user avatar
  • 23
3 votes
1 answer
52 views

Removing certain file types that do not contain the hostname in the file name

I am doing a file deployment for multiple machines per site, so it is much easier for me to zip all the files once and deploy to every machine. However I would like to remove the config for all the ...
Andrew Williams's user avatar
6 votes
1 answer
2k views

xargs: invalid option -- 'o'

I was trying to execute this command to fix yet another error (Unable to use a TTY - input is not a terminal or the right kind of file): kubectl get pods -n foobar | grep baz | awk '{print $1}' | ...
Moobie's user avatar
  • 183
15 votes
1 answer
15k views

xargs: unmatched single quote; by default quotes are special to xargs unless you use the -0 option

I'd like to count all the ordinary file on home directory with commands: $ find ~ -type f | xargs echo | wc -w xargs: unmatched single quote; by default quotes are special to xargs unless you use the ...
user10726006's user avatar
6 votes
1 answer
5k views

"-bash: /usr/bin/rename: Argument list too long" [duplicate]

I would like to rename files within each sub-directory by adding the name of the sub-directory. Following the answer from Rename files by adding their parent folder name, I tried: rename 's/(.*)\//$...
Josselin's user avatar
1 vote
2 answers
2k views

How to list all files where the first line is a blank line

I would like to find all the Java files that have a blank line as the first line of the file. I have the following which simply outputs the first line (and filename) of each file into the output file ...
Phil's user avatar
  • 145
0 votes
2 answers
4k views

find: paths must precede expression: )xargs [duplicate]

mkdir dregsfolder find /home/tony/Desktop/unsorted_files/ -maxdepth 1 -not \( -type d -or -iname "*.jpg" -or -iname "*.gif" -or -iname "*.docx" \)xargs -0 --no-run-if-empty mv /home/tony/Desktop/...
Jack White's user avatar
0 votes
1 answer
2k views

How to copy files from a folder using the find command with the -exec action, or with xargs, to another folder

I'd like to use the find command with the -exec action with the plus (+) sign (for efficiency), or with xargs to copy files from one directory to another. The following answer did not work for me. I'm ...
John_Patrick_Mason's user avatar
0 votes
1 answer
1k views

create a file in each subdirectory and write its path into it

I'm studying Linux and I've found an interesting exercise. Create a number of directories in ~ (abc, abc/def, abc/xyz, abc/def/ghi/123, abc/def/ghi/456), which is an easy task. After that create a ...
Alex F's user avatar
  • 283
7 votes
3 answers
5k views

What is the difference between find with -exec and xargs?

trying to learn Bash scripting I want to execute some command on all files below my current directory that satisfy a certain condition. Using find -name *.flac Specifically I want to convert .flac ...
Suppenkasper's user avatar
1 vote
1 answer
414 views

Can't rename each 'file' to 'file.text' (using xargs)

I have received a task to do these commands on a text file: Choose each second field from the file Sort and choose first 3 unique values Print the contents of each value.text while redirecting ...
Alex F's user avatar
  • 283
0 votes
1 answer
78 views

Remove files and words

In the moment, when I run git status, I got modified: loanwolf/alerts/locale/fr/LC_MESSAGES/django.mo modified: loanwolf/alerts/locale/fr/LC_MESSAGES/django.po modified: loanwolf/...
J.Doe's user avatar
  • 171
7 votes
2 answers
3k views

Read a URL from a file and open it in a Firefox tab

PreTabs.txt is a file I have on my desktop, and it just contains the line google.com I want to pipe the content of that file into Firefox so that it will open the URL in a new tab. If you execute ...
user avatar
2 votes
0 answers
1k views

Multithread downloading

I have 464 links in txt file, and i want to download them as fast as it is possiblle. Each url is a link to json file. TXT File: http://textuploader.com/ddgry i ve tried cat urls | xargs -n 1 -P ...
przem's user avatar
  • 19
9 votes
1 answer
11k views

How can I solve "unmatched double quote" error using dbus-monitor in combination with xargs?

To intercept (notify-osd) notifications on Linux (Ubuntu), I am using the dbus-monitor script below. Subsequently, the script runs another script (/opt/nonotifs/nonotifs/silent) with the intercepted ...
Jacob Vlijm's user avatar
12 votes
3 answers
3k views

deleting folders with spaces in their names using xargs [duplicate]

Why can't xargs delete directories with spaces in their names, and how to fix that? 76 find . -type d |xargs rm -rf 77 rm -rf fire\ hydrant/ 78 rm -rf wine\ glass/ 79 rm -rf tennis\ racket/ 80 ...
Mona Jalal's user avatar
  • 4,429
2 votes
1 answer
500 views

How to pass to tar.gz a file after rename using xargs?

I'm trying to rename log files and make tar them as 'tar.gz', I ended with below command but it doesn't get the renamed file name from STDIN (output of mv command) and it causes the tar command to ...
αғsнιη's user avatar
  • 35.4k
40 votes
4 answers
93k views

What does "xargs grep" do?

I know the grep command and I am learning about the functionalities of xargs, so I read through this page which gives some examples on how to use the xargs command. I am confused by the last example,...
AlphaOmega's user avatar
  • 1,413
17 votes
1 answer
2k views

Difference between "xargs" and command substitution?

In many cases I use command substitution instead of xargs. For example rm $(ls) is the same as ls | xargs rm What really are the differences between them? I think one of the differences is that ...
Sinoosh's user avatar
  • 2,011
5 votes
1 answer
4k views

Does gzip accept stdin?

When i pipe to gzip it can not accept stdin i should using xargsto convert stdin to argument $ls 1.txt $ls |xargs gzip && ls 1.txt.gz every thing is ok . but when i want to compress a cpio ...
Sinoosh's user avatar
  • 2,011
1 vote
3 answers
101 views

How do I fix my bash command to make a year-based hierarchy of my photos using symlinks?

I'm new to bash and I'm having problems with using variables in xargs I think. imanuel@orangepipc:~$ find /media/et10000 -name '*' -exec file {} \; | grep -o -P '^.+: \w+ image' | cut -d':' -f1 | ...
Imanuel Habekotte's user avatar
0 votes
2 answers
5k views

Why does not pipe work with 'find' and 'ls'

Why does not pipe work with 'find' and 'ls' If I do find . -name *foo* | ls -lah , it does a ls on $PWD and not the output of find. The solution however is find . -name *foo* | xargs -r ls -alh or ...
sadashiv30's user avatar
1 vote
1 answer
444 views

How can I copy all files and folders from one directory to another with similar structure with `find` and `xargs`?

For example, I use find command find /usr/share/icons -iname 'foxitreader*' find the files: /usr/share/icons/hicolor/32x32/apps/FoxitReader.png /usr/share/icons/hicolor/48x48/apps/FoxitReader.png /...
zhenguoli's user avatar
  • 286
2 votes
1 answer
206 views

Elegant way of copying list of directories to target directory

Background: I have started using beets for managing my music collection. It uses the command line as the primary interface. The command beet ls -ap for example emits a list of paths (folders) that ...
ojdo's user avatar
  • 147
4 votes
0 answers
2k views

fswatch | while read | xargs running command twice

Thanks in advance for any advice I'm working on an fswatch command to launch a script when files hit the Downloads folder. fswatch --event Created Downloads/ | (while read x; do echo $x | xargs -0 ...
Curtis Everingham's user avatar
2 votes
1 answer
625 views

Troubles piping echo output to xargs script for mv command

and thank you in advance for any advice. I'm working on a script that will automatically sort my downloads. The script is very simple, and running it manually has the intended effect. The problem I'm ...
Curtis Everingham's user avatar
0 votes
1 answer
2k views

make clean in several subdirectories

I want to clean several (>20) subdirectories with make clean. I thought about someting like this: find ./ -type d -maxdepth 1 | xargs "make clean" but it doesn't work. Could you please help me?
musbach's user avatar
  • 1,415
9 votes
1 answer
23k views

Command to change permissions only on files not directories

I have the following command find . -type f -print0 | xargs -0 chmod 644 which would successfully change to 644 the permissions on all files in ., provided that the filenames contained no embedded ...
Leo Simon's user avatar
  • 1,519
2 votes
1 answer
362 views

Bash Command Arguments ${...}

I noticed this type of command argument in a bash script: node ${debug?--nocrankshaft --nolazy --nodead_code_elimination --debug-brk=15454} app.js I am wondering what ${....} means? How is it used?...
E.S.'s user avatar
  • 133
3 votes
1 answer
59 views

Finding, moving and removing in Ubuntu

OS: Ubuntu 14.04.2 LTS (GNU/Linux 3.13.0-62-generic x86_64) I have a directory like the following: ~/total/ test1/ test1.txt some_other_file_i_dont_care.py test2/ ...
tomasyany's user avatar
  • 133
35 votes
3 answers
45k views

Piping find -name to xargs results in filenames with spaces not being passed to the command

Normally to remove files with spaces in their filename you would have to run: $ rm "file name" but if I want to remove multiple files, e.g.: $ find . -name "*.txt" | xargs rm This will not delete ...
Ashley's user avatar
  • 497