#!/bin/bash
file_dir="$HOME/file_dir"
#检查目录是否存在
if [ -d "$file_dir" ]
then
read -p "是否清空?" choice
case "$choice" in
[Yy])
rm -r "${file_dir}"
echo "目录已清空"
;;
*)
echo "无效操作"
exit 0
;;
esac
else
mkdir -p "$file_dir"
fi
#!/bin/bash
# 定义目标目录
FILE_DIR="$HOME/file_dir"
DIR_DIR="$HOME/dir_dir"
# 输入源路径
read -p "请输入要处理的绝对路径: " source_path
# 检查源路径是否存在且为目录
if [ ! -d "$source_path" ]
then
echo "错误路径"
exit 1
fi
count_file=0
count_dir=0
for item in "$source_path"
do
if [ -f "$item" ]
then
# 拷贝普通文件
cp "$item" "$FILE_DIR/"
((count_file++))
elif [ -d "$i" ]
then
(( count_dir++))
cp "$item" "$FILE_DIR"
fi
fi
done
# 输出统计结果
echo "操作完成!"
echo "拷贝的普通文件数量: $count_file"
echo "拷贝的目录数量: $count_dir"