使用git bash
拷贝文件夹及其所有子文件夹中的所有*.CPP文件内容到一个文件20200111before.cpp.all中
#!/bin/bash
rm 20200111before.cpp.all
find . -type f | grep cpp$ | xargs -d"\n" cat >> 20200111before.cpp.all
拷贝文件夹及其所有子文件夹中的所有*.CPP文件名到一个文件20200111before.cpp.list中
#!/bin/bash
find . -type f | grep cpp$ | cat > 20200111before.cpp.list
拷贝文件夹及其所有子文件夹中的所有*.CPP文件内容到一个文件“当前日期时间.cpp.all"中
#!/bin/bash
#201111xsz
#read -s -n1 -p "按任意键继续 ... "
tmnow=`date +"%Y%m%d-%H%M%S"`
tgFolder="../xdx-cpp-bk"${tmnow}
echo " >will all cpp files to "${tgFolder}
echo " yes|[no]"
read kp
echo "your input : ${kp} "
if [ "${kp}" == "yes" ]; then
mkdir ${tgFolder}
#find . -type f | grep cpp$ | xargs -d"\n" -i cp {} ${tgFolder}
#cp 加参数 -p, 可以保持源文件的时间属性。否则新文件为当前时间
find . -type f | grep cpp$ | xargs -d"\n" -i -t cp -p {} ${tgFolder}
echo " >cpp files copied to ${tgFolder}"
else
echo "SKIPPED"
fi
if [ "0" == " skip following lines" ]; then
###############################################
xargs -p 参数,-t 参数
使用xargs命令以后,由于存在转换参数过程,有时需要确认一下到底执行的是什么命令。
-p参数打印出要执行的命令,询问用户是否要执行。
$ echo 'one two three' | xargs -p touch
touch one two three ?...
上面的命令执行以后,会打印出最终要执行的命令,让用户确认。用户输入y以后(大小写皆可),才会真正执行。
-t参数则是打印出最终要执行的命令,然后直接执行,不需要用户确认。
###############################################
BASH中用 read 实现“按任意键继续”
read -s -n1 -p "按任意键继续 ... "
-s 指输入的字符屏幕上不可件,应该说可见,但由于和终端的背景色相同,故不可见了
-n1 看到n后那个“1”了没,表示仅接收1个字符,按回车键也属于一个字符
-p是指后面可加用“ ”括起来的提示符
L_end:
fi
删除文件夹及其所有子文件夹中的所有.git, .vscode 等文件夹及 .in, .out等文件
#!/bin/bash
#201111xsz
#read -s -n1 -p "按任意键继续 ... "
echo " delete all .git folder and .in/.out/.pdf/.ppt/.pptx files"
echo " yes|[no]?"
read kp
if [ ${kp} == "yes" ]; then
find . -type d -name .git | xargs -d"\n" rm -f -R
find . -type d -name .vscode | xargs -d"\n" rm -f -R
#echo delete all .in/.out .n .pdf .ppt/.pptx files
find . -type f | grep .in| xargs -d"\n" -t rm -f -R
find . -type f | grep .out| xargs -d"\n" -t rm -f -R
find . -type f | grep .1| xargs -d"\n" -t rm -f -R
find . -type f | grep .2| xargs -d"\n" -t rm -f -R
find . -type f | grep .3| xargs -d"\n" -t rm -f -R
find . -type f | grep .4| xargs -d"\n" -t rm -f -R
find . -type f | grep .pdf| xargs -d"\n" -t rm -f -R
find . -type f | grep .ppt| xargs -d"\n" -t rm -f -R
find . -type f | grep .pptx| xargs -d"\n" -t rm -f -R
else
echo " skipped"
fi
来源:oschina
链接:https://my.oschina.net/SamXIAO/blog/3158614