常用shell命令

循环操作某个文件夹下所有文件夹

#!/bin/bsh
cur_dir=`pwd`
# for i in `ls $cur_dir`
for i in `ls $cur_dir -d */ | cut -f1 -d'/'` # 过滤文件夹
do
    cd $cur_dir/$i;
    echo "$cur_dir/$i";
    make clean;
done

docker 清理操作

#!/bin/bash

# 函数:清理容器
_containers_clear() {    
    for container_id in $2
    do
        docker $1 $container_id
    done
    echo "_containers_clear done"
}

container_ps_info=$(docker ps)
echo "********** container_ps_a_info: **********\n${container_ps_info}"
container_ps_a_info=$(docker ps -a)
echo "********** container_ps_a_info: **********\n${container_ps_a_info}"
# 获取所有容器ID
container_ids=$(docker ps -a -q)
echo "********** container_ids: **********\n${container_ids}"

# 根据命令行参数执行对应的操作
if [ "$1" = "stop" ]; then
    echo "docker stop all"
    _containers_clear "$1" "$container_ids"
elif [ "$1" = "rm" ]; then
    echo "docker rm all"
    _containers_clear "$1" "$container_ids"
else
    echo "查看容器信息成功!"
fi

你可能感兴趣的:(shell)