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

作者:付汉杰 hankf@amd.com,文章来源:博客园

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

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

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

#!/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

#!/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 内容如下:

#!/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"

最新文章

最新文章