Cod*_*eIt 2 linux ubuntu copy copy-paste file
我有一个包含*.cpp.So类型文件的目录.我想复制目录中的每个文件并使用它将其粘贴到同一目录中
cp -a *.cpp
Run Code Online (Sandbox Code Playgroud)
可以选择在粘贴时删除.cpp.这可能吗?
这是一个简单的bash脚本.此脚本假定文件名仅包含一个"." 基于此的角色和分裂.
#!/bin/sh
for f in *.cpp; do
#This line splits the file name on the delimiter "."
baseName=`echo $f | cut -d "." -f 1`
newExtension=".new"
cp $f $baseName$newExtension
done
Run Code Online (Sandbox Code Playgroud)
您可以通过 bash 参数扩展来完成此操作,如 bash 手册中所述:
${parameter%%word} 删除匹配的后缀模式。该单词被扩展以产生一个模式,就像路径名扩展一样。如果模式与参数扩展值的尾部部分匹配,则扩展的结果是具有最短匹配模式(“%”情况)或最长匹配模式(“%”)的参数扩展值。 %'' 情况)已删除。
...
for i in *.cpp
do
cp -a $i ${i%%.cpp}
done
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1784 次 |
| 最近记录: |