Search
 
SCRIPT & CODE EXAMPLE
 

SHELL

xargs linux

echo 'one two three' | xargs mkdir
ls
one two three
Comment

bash how to use xargs

# Basic syntax:
<command_1> | xargs <command_2>
# Where:
#	- the stdout of command_1 gets piped to xargs which executes command_2 on
#		every space, tab, or new-line-delimited input
# Note:
#	- this is similar to find..exec, but xargs is faster and more versatile
# 	- xargs allows tools like rm to accept standard input as arguments

# Example usage 1:
# Say you want to change the permissions of all directories and subdirectories
# of the current directory. You can run:
find . -type d | xargs chmod 777
# Note:
# 	- the -t flag causes xargs to print each command that will be executed
#		to the terminal, which is useful for debugging
#	- the -p flag will print the command to be executed and prompt the
# 		user to run it, which is also useful for debugging

# Example usage 2 (somewhat advanced):
find . -maxdepth 2 -type f -iname "*name*" | xargs -I {} sh -c "grep -l word1 $(grep -l word2 {})"
# Where:
#	- the find command identifies all files in the current directory and
#		subdirectories up to a depth of 1 that contain "name" in their
#		file name in a case-insensitive manner and pipes them to xargs
#	- -I specifies a string that will be replaced by the stdin when found (which
#		is useful for controlling where the piped content appears in the
#		xargs command)
#	- sh -c runs the shell command in quotes which can be used to do command
#		substitution in xargs
Comment

linux xargs

# xargs
## -d assign delimiter (defaul is blank char or 
)
xargs -d :
Comment

PREVIOUS NEXT
Code Example
Shell :: vim cut 
Shell :: how to cat only the first ten lines of a file linux 
Shell :: kubectl describe to yaml 
Shell :: Jenkins ssh credentials in pipeline 
Shell :: windows server 2016 install chrome 
Shell :: npm install 
Shell :: Git create a new repository on the command line 
Shell :: how to uninstall cuda 
Shell :: git get back to most recent commit 
Shell :: how to install powershell 
Shell :: mdem ubuntu add user to sudo 
Shell :: update time in linux 
Shell :: Install MySQL FreeBSD 
Shell :: linux add user with home directory 
Shell :: chown a file 
Shell :: mac redis cli 
Shell :: ubuntu clone git repository 
Shell :: ssh permissions are too open 
Shell :: sudo gem install cocoapods-deintegrate cocoapods-clean 
Shell :: set forked repo as upstream 
Shell :: rename all files starting with in linux 
Shell :: raspberry pi remote desktop 
Shell :: atom vs sublime 
Shell :: url_launcher 
Shell :: pdf file 30mb 
Shell :: how to update kali linux 2022 
Shell :: git rebase onto 
Shell :: cartesian product file shell 
Shell :: Invariant Violation: requireNativeComponent: "RNCWebView" was not found in the UIManager. 
Shell :: show pghba 
ADD CONTENT
Topic
Content
Source link
Name
6+6 =