Questions tagged [xargs]

xargs is a command on Unix and most Unix-like operating systems used to build and execute command lines from standard input.

xargs is a command on Unix and most Unix-like operating systems used to build and execute command lines from standard input. Under the Linux kernel before version 2.6.23, arbitrarily long lists of parameters could not be passed to a command, so xargs breaks the list of arguments into sublists small enough to be acceptable.

xargs often covers the same functionality as the backquote(`) feature of many shells, but is more flexible and often also safer, especially if there are blanks or special characters in the input. It is a good companion for commands that output long lists of files like find, locate and grep, but only if you use -0, since xargs without -0 deals badly with file names containing ', " and space.

1303 questions
-1
votes
1 answer

Create pattern list dynamically from file for running in grep -f

Lets say I have this input 11 12 31 40 42 90 I need to get all number lines from the file and add the | character after each that can be used as a pattern list to run with grep -f. I was thinking of using xargs but I have no idea how to use | as a…
Eric Stotch
  • 141
  • 4
  • 19
-1
votes
1 answer

Installing with pip through xargs

I am trying to do some filtering on requirement.txt before installing individual python packages with pip (v3). I am stumped though why my usage of xargs here is messing up the pip command: cat ./requirements.txt | xargs -I XXX pip --no-deps install…
Magnus
  • 3,086
  • 2
  • 29
  • 51
-1
votes
2 answers

how to delete a sub directory whose name is appended to the end of its parent folder's name

Parent folder contains subdir name appended at the end Delimiter is underscore _: a_b_c (parent folder contains sub directory name at the end) |c/ (to be deleted) |.. d_f |.. |f/ (to be deleted) g_h |h/ (to be deleted) |.. Output…
Dinesh Ravi
  • 1,209
  • 1
  • 17
  • 35
-1
votes
1 answer

macOS xargs will not open app found by mdfind and grep

I'm looking for one command that find path and open all of .app with only change app name in Terminal. I tried : mdfind "calendar.app" "kind:app" | grep -v '/Users/' | xargs open Work well with calendar, safari, calculator --> find and open…
Vitiligo
  • 5
  • 1
-1
votes
1 answer

Random behaviour when pipping find output to xargs and then to sed

I'm using the gnu version of these tools. I'm trying to unzip an archive and transform a file. The file is "myfile.txt" and it appears in multiple folders in the archive- so I thought passing the full path to xarg would transform all files: mkdir…
red888
  • 27,709
  • 55
  • 204
  • 392
-1
votes
3 answers

Conditions in bash

Bash script for my Jenkins pipeline remove all docker images by condition: docker images --format="{{.Repository}} {{.Tag}} {{.ID}}" | grep -v "latest" | cut -d ' ' -f3 | xargs docker rmi -f But sometimes images list is empty by cut -d ' ' -f3, and…
Pavel
  • 2,005
  • 5
  • 36
  • 68
-1
votes
1 answer

xargs cp how to use asterix?

I'm trying to copy files by mask with preserving folder structure(using --parents), I can't use cp -r --parents or rsync directly because of argument list too long error. ls folder1/folder2/ | head | xargs -I {} cp -r --parents…
mrgloom
  • 20,061
  • 36
  • 171
  • 301
-1
votes
1 answer

Scp multiple files created in last one day from server to local fails

I want to get multiple files that were generated in last 1 day, from server to local. I'm using the following command which says "No such file or directory". find username@server.xyz.com:/path-from-which-files-need-to-be-copied/ -type f -ctime -1 |…
Ron
  • 149
  • 2
  • 16
-1
votes
1 answer

Only display the found output a grep of multiple files

I'm using grep to find a string in a file. The grep will probably only find one file that matches the file name, possibly two, but i only need it to put the string if it found it, and just the string. grep -oh 'Closing finished'…
T_Wrong
  • 59
  • 5
-1
votes
1 answer

Pass configuration parameter(s) to a git command via xargs util

I am trying build a command using xargs to pass configuration parameters : user.name and user.email to git commit. Command to be built by xargs : git -c user.name=abc -c user.email=abc@mail.com commit What I have tried : echo "-c user.name=abc -c…
Saurabh P Bhandari
  • 6,014
  • 1
  • 19
  • 50
-1
votes
1 answer

Pipe output from command to another command

A bash function, prepend_line, takes two parameters: a string and a fully-qualified path to a file. It's used for logging, inserting the current date/time and the string at the top of the log file. Standalone use works fine: prepend_line "test…
Lorccan
  • 793
  • 5
  • 20
-1
votes
1 answer

How to move files including full path to a subfolder?

I've got a public folder that includes .html and non .html files in its root and subfolders. I need to move all non .html files to a subfolder of the public folder, e.g. to public/assets, preserving their full path. So far I got something like…
szimek
  • 6,404
  • 5
  • 32
  • 36
-1
votes
3 answers

converting four columns to two using linux commands

I am wondering how one could merge four columns into two in the following manner (using the awk command, or other possible commands). For example, Old: A B C D E F G H I J K L M N O P . . . New: A B C D E F G H I J K L M N O P . . …
kwaldner
  • 95
  • 1
  • 6
-1
votes
3 answers

xargs echo `echo {} | sed 's/pattern/replace/'` doesn't work but for each loop works

I want to do the equivalent of: for i in `ls -1`; do echo $i | mv $i `sed 's/profile/account/'`; done with xargs ls -1 | xargs -I{} mv {} `echo {} | sed 's/profile/account/'` But the sed after the pipe within backticks is ignored. Anyone know why…
bucabay
  • 5,235
  • 2
  • 26
  • 37
-1
votes
1 answer

Multiple downloads with wget at the same time

I have a link.txt with multiple links for download,all are protected by the same username and password. My intention is to download multiple files at the same time, if the file contains 5 links, to download all 5 files at the same time. I've tried…
Cesar
  • 9
  • 2