前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >自动删除当前目录及其子目录下的所有PetaLinux工程的build目录下的临时文件,释放2TB硬盘空间

自动删除当前目录及其子目录下的所有PetaLinux工程的build目录下的临时文件,释放2TB硬盘空间

作者头像
hankfu
发布2022-09-30 08:26:50
6590
发布2022-09-30 08:26:50
举报
文章被收录于专栏:hank

服务器报告硬盘没有空间。

执行脚本peta-del-build-temp.sh,自动删除当前目录及其子目录下的所有PetaLinux工程的build目录下的临时文件,最后从历年遗留的100多个工程中释放了2TB硬盘空间。

peta-del-images-unused.sh 内容如下:

代码语言:javascript
复制
#!/bin/bash
# hankf@amd.com

echo -e "\nBegin to run script: $0"

# $1: target-petalinux-image-directory
if [ "$1" = "" ]; then
    echo "Invalid target directory."
    echo "Usage: $0 target-petalinux-image-directory."
fi

echo "Check petalinux image directory: $1"
ls -l -h $1

if [ ! -f  $1/u-boot.elf ]; then 
    echo "Not PetaLinux project image directory, No u-boot.elf."
    echo "Exit."
    exit 1
fi 

if [ ! -f  $1/system.dtb ]; then 
    echo "Not PetaLinux project image directory, No system.dtb."
    echo "Exit."
    exit 1
fi 

# array definition, work for /bin/bash, does not work for /bin/sh
array_image_type_remove=( 
.cpio
.ext2
.ext3
.ext4
.jffs2
.tar
.bin
.bz2
.gz
.u-boot
Image
vmlinux
)

# Get array elements number
image_type_remove_length=${#array_image_type_remove[@]}

# C-language style loop
for (( i=0; i<$image_type_remove_length; i++))
{
    image_remove=$1/*${array_image_type_remove[i]}
    echo "Remove No.$i image: $image_remove";
    rm -rf $image_remove    
}

echo "Files in petalinux image directory: $1 after deleting."
ls -l -h $1

echo -e "Complete script: $0"

peta-del-build-temp-inner.sh 内容如下:

hankf@amd.com

代码语言:javascript
复制
#!/bin/bash
# hankf@amd.com

echo -e "\nBegin to run script: $0"

if [ "$1" = "" ]; then
    echo "Invalid target directory."
    echo "Usage: $0 target-petalinux-build-directory."
fi

echo "Check petalinux build directory: $1"
ls -l $1

# array definition, work for /bin/bash, does not work for /bin/sh
dir_array_check=( 
cache 
conf
downloads
misc
sstate-cache
tmp
../build/downloads
../build/sstate-cache
../build/tmp
../components/plnx_workspace/device-tree/
../project-spec/
../project-spec/configs/
../project-spec/hw-description/
../project-spec/meta-user/conf
../project-spec/meta-user/recipes-bsp/
)

# Get array elements number
dir_array_check_length=${#dir_array_check[@]}

# C-language style loop
for (( i=0; i<$dir_array_check_length; i++))
{
    CHECK_DIR=$1/${dir_array_check[i]}
    echo "Check No.$i directory: $CHECK_DIR";
    if [ ! -d  $CHECK_DIR ]; then 
        echo "Not PetaLinux project build directory. No directory: $CHECK_DIR. "
        echo "Exit."
        exit 1
    fi 
}

echo "It is PetaLinux project build directory."

echo "Delete PetaLinux temp files."
rm -rf $1/../build/cache/*
rm -rf $1/../build/conf/*
rm -rf $1/../build/downloads/*
rm -rf $1/../build/misc/*
rm -rf $1/../build/sstate-cache/*
rm -rf $1/../build/tmp/*

# Delete unused image too.
peta-del-images-unused.sh  $1/../images/linux/
peta-del-images-unused.sh  $1/../pre-built/linux/images/

echo -e "Complete script: $0"

peta-del-build-temp.sh 内容如下:

代码语言:javascript
复制
#!/bin/bash
# hankf@amd.com


echo -e "\nBegin to run script: $0"

find -name "build" | xargs -n 1 peta-del-build-temp-inner.sh 

echo -e "Complete script: $0"
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2022-09-08,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • hankf@amd.com
相关产品与服务
对象存储
对象存储(Cloud Object Storage,COS)是由腾讯云推出的无目录层次结构、无数据格式限制,可容纳海量数据且支持 HTTP/HTTPS 协议访问的分布式存储服务。腾讯云 COS 的存储桶空间无容量上限,无需分区管理,适用于 CDN 数据分发、数据万象处理或大数据计算与分析的数据湖等多种场景。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档