Kom*_*NET 5 ls pipe xargs filter mv
ls -lrt |grep 'Jun 30th' | awk '{print $9}' | xargs mv -t /destinationFolder
Run Code Online (Sandbox Code Playgroud)
我正在尝试从特定日期或模式或创建用户移动文件。如果没有该选项,它就无法正常工作-t。
有人可以解释一下xargs -n移动-t命令吗?
从mv手册页
-t, --target-directory=DIRECTORY
move all SOURCE arguments into DIRECTORY
Run Code Online (Sandbox Code Playgroud)
mv的默认行为是将所有内容移至最后一个参数,因此当执行xargs命令
时,它会尝试将所有内容移至通过管道传输到 xargs 的最后一个参数。您明确表示将其移至此处。mv /destinationFolder pipedArgs-t-t
从xargs手册页
-n max-args
Use at most max-args arguments per command line. Fewer than max-args arguments will be used if the size (see the -s option) is exceeded, unless the -x option is given, in which case xargs will exit.
Run Code Online (Sandbox Code Playgroud)
通常xargs会将所有参数一次传递给命令。例如
echo 1 2 3 4 |xargs echo
1 2 3 4
Run Code Online (Sandbox Code Playgroud)
执行
echo 1 2 3 4
Run Code Online (Sandbox Code Playgroud)
尽管
echo 1 2 3 4 |xargs -n 1 echo
Run Code Online (Sandbox Code Playgroud)
执行
echo 1
echo 2
echo 3
echo 4
Run Code Online (Sandbox Code Playgroud)