linux shell cp通配符,cp和mv中的linux通配符用法

我们来谈谈通配符如何工作一分钟.

cp *.txt foo

如果存在与该glob匹配的任何文件,则实际上不会使用参数* .txt调用cp.相反,它运行如下:

cp a.txt b.txt c.txt foo

同样,像

mv *.txt *.old

…不可能知道该怎么做,因为当它被调用时,它看到的是:

mv a.txt b.txt c.txt *.old

或者更糟糕的是,如果您已经有一个名为z.old的文件,它会看到:

mv a.txt b.txt c.txt z.old

因此,您需要使用不同的工具.考虑:

# REPLACES: mv /data/*/Sample_*/logs/*_Data_time.err /data/*/Sample_*/logs/*_Data_time_orig.err

for f in /data/*/Sample_*/logs/*_Data_time.err; do

mv "$f" "${f%_Data_time.err}_Data_time_orig.err"

done

# REPLACES: cp /data/*/Sample_*/scripts/*.sh /data/*/Sample_*/scripts/*_orig.sh

for f in /data/*/Sample_*/scripts/*.sh; do

cp "$f" "${f%.sh}_orig.sh"

done

# REPLACES: sh /data/*/Sample_*/scripts/*_orig.sh

for f in /data/*/Sample_*/scripts/*_orig.sh; do

if [[ -e "$f" ]]; then

# honor the script's shebang and let it choose an interpreter to use

"$f"

else

# script is not executable, assume POSIX sh (not bash, ksh, etc)

sh "$f"

fi

done

在添加新名称之前,它使用parameter expansion去除旧名称的尾部.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值