Search
 
SCRIPT & CODE EXAMPLE
 

SHELL

bash 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

PREVIOUS NEXT
Code Example
Shell :: install docker centos 7 
Shell :: automatically clean package cache in Arch Linux 
Shell :: poetry add library 
Shell :: create group in linux command example 
Shell :: command to uninstall windows store 
Shell :: linux zip file 
Shell :: how to restore deleted branch in git 
Shell :: flushbar flutter 
Shell :: install stylelint 
Shell :: change resolution of a video 
Shell :: linux check if a group exist or not 
Shell :: zip file linux 
Shell :: linux unique lines 
Shell :: linux change permissions recursive only directories 
Shell :: command line of linux os 
Shell :: how to install wsl 2 
Shell :: bash "=~" example 
Shell :: tar extract command windows 
Shell :: brew show package info 
Shell :: git config global username and email 
Shell :: bash list 
Shell :: exit branch git 
Shell :: sed replace all until match in line 
Shell :: Bash dir in loop 
Shell :: docker login dockerhub 
Shell :: redis scan keys and print values shell 
Shell :: git modify repository remote url 
Shell :: sngrep printed lines correctly 
Shell :: renaming a file in linux 
Shell :: debian build with ccache 
ADD CONTENT
Topic
Content
Source link
Name
1+4 =