当前位置: 首页 > news >正文

linux_c3.5

文件分类

1

#!/bin/bash

dir_path="$HOME/file_dir"

# 判断目录是否存在
if [ -d "$dir_path" ]
then
    echo "目录$dir_path存在"
    read -p "是否要清空该目录?(Y/N): " choice

    # 根据用户输入进行判断
    if [ "$choice" == "Y" ]
    then
        echo "正在清空目录$dir_path..."
        rm -rf "$dir_path"/*
        echo "目录已清空"
    else
        echo "退出脚本"
        exit
    fi
else
    echo "目录$dir_path不存在,正在创建..."
    mkdir "$dir_path"
    echo "目录已创建"
fi

2

#!/bin/bash

dir_path="$HOME/dir_dir"

# 判断目录是否存在
if [ -d "$dir_path" ]
then
    echo "目录$dir_path存在"
    read -p "是否要清空该目录?(Y/N): " choice

    # 根据用户输入进行判断
    if [ "$choice" == "Y" ]
    then
        echo "正在清空目录$dir_path..."
        rm -rf "$dir_path"/*
        echo "目录已清空"
    else
        echo "退出脚本"
        exit
    fi
else
    echo "目录$dir_path不存在,正在创建..."
    mkdir "$dir_path"
    echo "目录已创建"
fi

3

#!/bin/bash

read -p "请输入指定路径(最好是绝对路径):" input_path

# 检查路径是否存在
if [ ! -d "$input_path" ]
then
    echo "错误:指定路径不存在或不是一个目录!"
    exit
fi

# 定义目标目录路径
file_dir="$HOME/file_dir"
dir_dir="$HOME/dir_dir"

# 创建目标目录
mkdir "$file_dir"
mkdir "$dir_dir"

# 初始化计数器
file_count=0
dir_count=0

# 遍历
for i in "$input_path"/*
do
    if [ -f "$item" ]
    then
        # 普通文件,拷贝到file_dir
        cp "$i" "$file_dir"
        file_count=$((file_count + 1))
    elif [ -d "$i" ]
    then
        # 目录文件,拷贝到dir_dir
        cp -r "$i" "$dir_dir"
        dir_count=$((dir_count + 1))
    fi
done

echo "拷贝了$file_count个普通文件到$file_dir"
echo "拷贝了$dir_count个目录文件到$dir_dir"

相关文章:

  • PDF 分割工具
  • C++中`const int*` 与 `int* const` 的区别及记忆技巧
  • Swift系列01-Swift语言基本原理与设计哲学
  • 基于 Docker 的跨平台镜像构建与增量更新实战指南
  • leetcode349 两个数组的交集
  • 算法精讲——树(一):DFS 的奇妙探险之旅
  • Linux 运维安全加固策略:实战指南
  • Docker Desktop 4.38 安装与配置全流程指南(Windows平台)
  • π0源码解析——一个模型控制7种机械臂:对开源VLA sota之π0源码的全面分析,含我司的部分落地实践
  • LabVIEW中实现FFT并提取幅值与相位
  • 立即释放 Mac 空间!Duplicate File Finder 8 重复文件高速清理工具
  • Docker Desktop常见问题记录
  • CentOS7安装MySQL5.7到指定数据目录
  • 低代码开发平台(Low-Code)简要介绍
  • 客户端的ip和端口的发送,存储位置和服务端的ip和端口的绑定
  • MySQL知识点总结(二十)
  • 【Python项目】基于深度学习的车辆特征分析系统
  • pytest结合allure
  • 中级系统运维工程师
  • 【江科大STM32】TIM输入捕获模式PWMI模式测频率
  • 爱客crm下载/seo案例分享
  • 大兴西红门网站建设/北京seo方法
  • wordpress简化注册/seo推广营销靠谱
  • 广安网站制作设计/醴陵网站制作
  • 福田企业的网站建设公司好吗/谷歌google官网
  • 网站建设公司那家好/广告宣传费用一般多少