Last active
May 1, 2022 01:54
-
-
Save jspaezp/ebc3db61415a3134a8390eeab744e117 to your computer and use it in GitHub Desktop.
script to clean old files from the mass spec computer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# To use, save this script in the directory you want to clean, | |
# name it "clean_files.bash" | |
# open bash in the directory | |
# run $ bash clean_files.bash | |
# This will generate a list of all the deleted files. | |
## THIS PROCESS IS NOT REVERSIBLE !!!!!!!!!!!!!!!!!!!! | |
## THIS PROCESS IS NOT REVERSIBLE !!!!!!!!!!!!!!!!!!!! | |
## THIS PROCESS IS NOT REVERSIBLE !!!!!!!!!!!!!!!!!!!! | |
## THIS PROCESS IS NOT REVERSIBLE !!!!!!!!!!!!!!!!!!!! | |
## THIS PROCESS IS NOT REVERSIBLE !!!!!!!!!!!!!!!!!!!! | |
## THIS PROCESS IS NOT REVERSIBLE !!!!!!!!!!!!!!!!!!!! | |
## Run only if you are sure ... | |
current_time=$(date "+%Y.%m.%d") | |
echo "Current Time : $current_time" | |
new_fileName=deleted_files.${current_time}.txt | |
echo "The list of the deleted files will be in: ${new_fileName}" | |
echo "Calculating file sizes to be deleted, this might be slow ... go for a coffee..." | |
echo "Size to be deleted on Files" | |
find -mmin +1051200 \ | |
-regextype posix-extended -regex \ | |
'.*\.(pdResult|byspec2|mzML|blib|pep.xml|pin|pout)$' \ | |
-type f -exec du -bc {} + | \ | |
grep total$ | \ | |
cut -f1 | \ | |
awk '{ total += $1 }; END { print total }' | \ | |
numfmt --to=iec-i --suffix=B --padding=7 | |
echo "Size to be deleted on folders" | |
find -mmin +1051200 \ | |
-regextype posix-extended -regex \ | |
'.*/(p0|combined/search|combined/andromeda|.Rproj.user|.RData)$' \ | |
-type d -exec du -bc {} + | \ | |
grep total$ | \ | |
cut -f1 | \ | |
awk '{ total += $1 }; END { print total }' | \ | |
numfmt --to=iec-i --suffix=B --padding=7 | |
# Prompt for confirmation before actually deleting stuff ... | |
read -p "Are you sure? (y/n)" -n 1 -r | |
echo "" # (optional) move to a new line | |
if [[ ! $REPLY =~ ^[Yy]$ ]] | |
then | |
exit 1 | |
fi | |
set -x | |
set -e | |
# This secttion deleted partial searches from PD | |
find . -type f -mmin +1051200 -regextype posix-extended -regex ".*.pdResult$" | |
find . -type f -mmin +1051200 -regextype posix-extended -regex ".*\.pdResult$" -delete -print |& tee --append ${new_fileName} | |
# This for byonic results | |
find . -type f -mmin +1051200 -regextype posix-extended -regex ".*\.byspec2$" -delete -print |& tee --append ${new_fileName} | |
# This secttion deleted partial searches from open source search engines | |
find . -type f -mmin +1051200 -regextype posix-extended -regex ".*\.mzML$" -delete -print |& tee --append ${new_fileName} | |
find . -type f -mmin +1051200 -regextype posix-extended -regex ".*\.blib$" -delete -print |& tee --append ${new_fileName} | |
find . -type f -mmin +1051200 -regextype posix-extended -regex ".*\.pep.xml$" -delete -print |& tee --append ${new_fileName} | |
find . -type f -mmin +1051200 -regextype posix-extended -regex ".*\.pin$" -delete -print |& tee --append ${new_fileName} | |
find . -type f -mmin +1051200 -regextype posix-extended -regex ".*\.pout$" -delete -print |& tee --append ${new_fileName} | |
# -type d finds only directories | |
# This section will delete old partial maxquant search results | |
find . -type d -mmin +1051200 -regextype posix-extended -regex ".*/p0$" -prune -exec rm -vr {} \; |& tee --append ${new_fileName} | |
find . -type d -mmin +1051200 -regextype posix-extended -regex ".*/combined/search$" -prune -exec rm -vr {} \; |& tee --append ${new_fileName} | |
find . -type d -mmin +1051200 -regextype posix-extended -regex ".*/combined/andromeda$" -prune -exec rm -vr {} \; |& tee --append ${new_fileName} | |
# This section deletes R projects | |
find . -type d -mmin +1051200 -regextype posix-extended -regex ".*/\.Rproj.user$" -prune -exec rm -vr {} \; |& tee --append ${new_fileName} | |
find . -type f -mmin +1051200 -regextype posix-extended -regex ".*/\.RData$" -delete -print |& tee --append ${new_fileName} | |
# This removes empty directories | |
find . -type d -empty -mmin +1051200 -delete -print |& tee --append ${new_fileName} | |
echo "Done deleting stuff" | |
wc -l ${new_fileName} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment