当前位置:网站首页>Using skills of xargs -- the way to build a dream
Using skills of xargs -- the way to build a dream
2022-06-24 08:44:00 【The road to dream】
Unix Commands have arguments , Some commands are acceptable ” The standard input (stdin)” As a parameter . Pipeline command (|) The role of , Is to convert the standard output of the command on the left to standard input , The command provided to the right is used as a parameter . although , stay Unix Most commands in the system do not accept standard input as parameters , You can only enter parameters directly on the command line , This makes it impossible to pass parameters with pipeline commands . such as , What we use everyday echo Command does not accept pipeline parameters . and xargs Role of command , Is to convert standard input to command line parameters .
Be careful :xargs The following default is echo command , So it can be used alone
Help information
xargs --help
Usage: xargs [OPTION]... COMMAND INITIAL-ARGS...
Run COMMAND with arguments INITIAL-ARGS and more arguments read from input.
Mandatory arguments to long options are mandatory for short options too.
Non-mandatory arguments are indicated by [square brackets]
-0, --null Items are separated by a null, not whitespace.
Disables quote and backslash processing
-a, --arg-file=FILE Read arguments from FILE, not standard input
-d, --delimiter=CHARACTER Input items are separated by CHARACTER, not by
blank space. Disables quote and backslash
processing
-E END If END occurs as a line of input, the rest of
the input is ignored.
-e [END], --eof[=END] Equivalent to -E END if END is specified.
Otherwise, there is no end-of-file string
--help Print a summary of the options to xargs.
-I R same as --replace=R (R must be specified)
-i,--replace=[R] Replace R in initial arguments with names
read from standard input. If R is
unspecified, assume {}
-L,-l, --max-lines=MAX-LINES Use at most MAX-LINES nonblank input lines per
command line
-l Use at most one nonblank input line per
command line
-n, --max-args=MAX-ARGS Use at most MAX-ARGS arguments per command
line
-P, --max-procs=MAX-PROCS Run up to max-procs processes at a time
-p, --interactive Prompt before running commands
--process-slot-var=VAR Set environment variable VAR in child
processes
-r, --no-run-if-empty If there are no arguments, run no command.
If this option is not given, COMMAND will be
run at least once.
-s, --max-chars=MAX-CHARS Limit commands to MAX-CHARS at most
--show-limits Show limits on command-line length.
-t, --verbose Print commands before executing them
--version Print the version number
-x, --exit Exit if the size (see -s) is exceeded
Example :
Basic use :
# Convert standard input to command line arguments
echo "hello rumenz" | xargs echo
# grep Accept pipeline parameters
cat /etc/passwd | grep root
# echo The command does not accept pipeline parameters
echo "hello rumenz" | echo
Parameters :
-d Specify the separator , By default, space division is used
# Space as separator
echo "one two three" | xargs mkdir
# Specify tab as separator
echo -e "a\tb\tc" | xargs -d "\t" echo
-p Print out the command to be executed and ask the user whether to execute
echo 'one two three' | xargs -p touch
-0 To express with null As a separator
find The command has a special parameter -print0, Used to specify the list of files to output null As a separator
find /path -type f -print0 | xargs -0 rm
# Specify how many lines to use as a command line parameter
xargs -L 1 find -name "*.txt"
-n Specify how many items to use as command line arguments at a time
echo {0..9} | xargs -n 2 echo
# Specify an alternate string for each command line parameter
# Pass command line parameters to multiple commands
cat foo.txt
one
two
three
cat foo.txt | xargs -I {} sh -c 'echo {}; mkdir {}'
one
two
three
ls
one two three
# Convert multi line input to single line input
> cat rumenz.txt
1 2 3 4
5 6
7 8 9
> cat rumenz.txt | xargs
1 2 3 4 5 6 7 8 9
# Convert single line text to multiple lines
> cat rumenz.txt
1 2 3 4 5 6 7 8 9
> cat rumenz.txt | xargs -n 3
1 2 3
4 5 6
7 8 9
# Specify the delimiter for line conversion
> echo "rumenz:123:rumenz:456:rumenz:789" | xargs -d : -n 2
rumenz 123
rumenz 456
rumenz 789
# xargs and find combination
find . -type f -name "*.txt" -print | xargs rm -f
# Download files in bulk
cat rumenz.txt | xargs wget -c边栏推荐
- Three ways to uninstall Symantec Endpoint Protection Symantec
- Fundamentals of 3D mathematics [17] inverse square theorem
- 相机投影矩阵计算
- String to Base64
- Battle history between redis and me under billion level traffic
- 解析互联网广告术语 CPM、CPC、CPA、CPS、CPL、CPR 是什么意思
- Use cpulimit to free up your CPU
- Vscode install the remote -wsl plug-in to connect to the local WSL
- OpenCV to realize the basic transformation of image
- Xiaohei ai4code code baseline nibble 1
猜你喜欢

Distributed | how to make "secret calls" with dble

【关于运维和网工的差别,一文说透】

5 minutes, excellent customer service chat handling skills
![[micro services ~nacos] Nacos service providers and service consumers](/img/b7/47ecd6979ccfeb270261681d6130be.png)
[micro services ~nacos] Nacos service providers and service consumers

ZUCC_ Principles of compiling language and compilation_ Experiment 0607 grammar analysis ll analysis

小黑ai4code代码baseline啃食1

ZUCC_编译语言原理与编译_实验03 编译器入门

ZUCC_ Principles of compiling language and compilation_ Experiment 05 regular expression, finite automata, lexical analysis

Detailed explanation of Base64 coding and its variants (to solve the problem that the plus sign changes into a space in the URL)

New technology practice, encapsulating the permission application library step by step with the activity results API
随机推荐
Pyqt common system events
利用sonar做代码检查
JS merge multiple objects and remove duplicates
MATLAB Camera Calibrator相机标定
Live broadcast appointment: growth of Mengxin Product Manager
PHP代码加密的几种方案
Video Fusion communication has become an inevitable trend of emergency command communication. How to realize it based on easyrtc?
Introduction to data platform
ZUCC_编译语言原理与编译_实验05 正则表达式、有限自动机、词法分析
rsync做文件备份
Qmenu response in pyqt
一文详解|增长那些事儿
5 minutes, excellent customer service chat handling skills
中国芯片独角兽公司
Using sonar for code checking
2021-06-25: a batch of strings consisting only of lowercase letters (a~z) are put
ZUCC_ Principles of compiling language and compilation_ Experiment 08 parsing LR parsing
ZUCC_ Principles of compiling language and compilation_ Experiment 01 language analysis and introduction
IIS build wordpress5.7 manually
成为IEEE学生会员