我这里有这条线,find "$directory" -name "*.sh" -print0 | xargs -0 cp -t ~/bckup
它支持所有以 .sh 结尾的东西。我将如何为多个文件扩展名执行此操作?我尝试了引号、括号和 $ 的不同组合。他们都没有工作=\
我还想将某些文件扩展名备份到不同的文件夹中,但我不确定如何在文件名中搜索特定扩展名。
这是我的整个代码以防万一:
#!/bin/bash
collect()
{
find "$directory" -name "*.(sh|c)" -print0 | xargs -0 cp -t ~/bckup #xargs handles files names with spaces. Also gives error of "cp: will not overwrite just-created" even if file didn't exist previously
}
echo "Starting log"
timelimit=10
echo "Please enter the directory that you would like to collect.
If no input in 10 secs, default of /home will be selected"
read -t $timelimit directory
if [ ! -z "$directory" ] #if directory doesn't have a length of 0
then
echo -e "\nYou want to copy $directory." #-e is so the \n will work and it won't show up as part of the string
else
directory=/home/
echo "Time's up. Backup will be in $directory"
fi
if [ ! -d ~/bckup ]
then
echo "Directory does not exist, creating now"
mkdir ~/bckup
fi
collect
echo "Finished collecting"
exit 0