ex42.sh
来自「Shall高级编程」· Shell 代码 · 共 31 行
SH
31 行
#!/bin/bash# copydir.sh# Copy (verbose) all files in current directory ($PWD)#+ to directory specified on command line.E_NOARGS=65if [ -z "$1" ] # Exit if no argument given.then echo "Usage: `basename $0` directory-to-copy-to" exit $E_NOARGSfi ls . | xargs -i -t cp ./{} $1# ^^ ^^ ^^# -t is "verbose" (output command line to stderr) option.# -i is "replace strings" option.# {} is a placeholder for output text.# This is similar to the use of a curly bracket pair in "find."## List the files in current directory (ls .),#+ pass the output of "ls" as arguments to "xargs" (-i -t options),#+ then copy (cp) these arguments ({}) to new directory ($1). ## The net result is the exact equivalent of#+ cp * $1#+ unless any of the filenames has embedded "whitespace" characters.exit 0
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?