bin: utilities for cleaning up files
This commit is contained in:
parent
5c17af6d6f
commit
db1e39b9e8
|
@ -21,7 +21,7 @@ find "$dir" -maxdepth 2 -not -name ".stfolder" -empty -printf "Removing empty %p
|
|||
find -L -maxdepth 2 -type l -printf "Removing broken symlink %p\n" -delete
|
||||
|
||||
highlight "e :: recursively remove empty folders and files"
|
||||
[[ $1 =~ "e" ]] && find -empty -not -name ".stfolder" -empty -printf "Removing empty %p\n" -delete
|
||||
[[ $1 =~ "e" ]] && find \( -name ".stfolder" -o -name ".*keep" -o -name ".git" \) -prune -o -empty -printf "Removing empty %p\n" -exec rm -d {} +
|
||||
|
||||
for k in "${!_clean_map[@]}"; do
|
||||
folder="${_clean_map[$k]}"
|
||||
|
@ -49,9 +49,10 @@ if [[ $1 =~ "d" ]]; then
|
|||
-type d \( -name 'cache' $(echo $DIRS_GENERATED | sed 's|-x \([^ ]\+\)|-o -name \1|g') \) \
|
||||
-print -exec rm $i -r {} + -prune
|
||||
echo -n " " && highlight "build directories"
|
||||
find \( -name ".git" -o -path "*/mixxx/build" -o -name "Leaflet" -o -name "www" -o -name "src" \) \
|
||||
find \( -name ".git" -o -path "*/mixxx/build" -o -name "app" -o -name "Leaflet" -o -name "www" -o -name "src" \) \
|
||||
-prune -o -name "build" -type d \
|
||||
-print -exec rm -rI {} + -prune
|
||||
# TODO consider gitignore / use git clean
|
||||
fi
|
||||
highlight "g :: clean gradle caches"
|
||||
if [[ $1 =~ "g" ]]; then
|
||||
|
@ -61,7 +62,7 @@ fi
|
|||
|
||||
highlight "c :: clean electron caches"
|
||||
[[ $1 =~ "c" ]] && find "$dir$(expr "${XDG_CONFIG_HOME/$HOME}" \| "/.config")" \
|
||||
-type d -name "*Cache" -print -exec rm $i -r {} + -prune
|
||||
-type d -name "*Cache*" -print -exec rm $i -r {} + -prune
|
||||
|
||||
if test -f "/var/log/apt/history.log"; then
|
||||
aptclean_cur=$(cat "/var/log/apt/history.log" | wc -l)
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
#!/bin/sh
|
||||
# Find and remove sizeable files
|
||||
find -size +5M -print -exec rm -I {} +
|
||||
find -size +${1:-50}M -exec rm -vi {} +
|
||||
|
|
|
@ -1,3 +1,12 @@
|
|||
#!/bin/sh
|
||||
# Remove one level of folders
|
||||
find -mindepth 1 -maxdepth 1 -exec sh -c 'mv -nv {}/* . && rm -dv {}' \;
|
||||
#!/bin/sh -e
|
||||
# Flatten folder hierarchy
|
||||
# Args: depth
|
||||
find -mindepth 2 -maxdepth ${depth:-2} -depth -type d "$@" | while read folder; do
|
||||
newname="$(echo "$folder" | sed 's|^./||;s|/|_|g')"
|
||||
mv -v "$folder" "$newname"
|
||||
parent="$(dirname "$folder")"
|
||||
test "$(basename "$folder")" = "$(basename "$parent")" &&
|
||||
rm -d "$parent" &&
|
||||
mv -v "$newname" "$parent"
|
||||
done
|
||||
find -maxdepth ${depth:-2} -empty -type d -delete
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
#!/bin/sh -e
|
||||
# Delete files under current or given path which exist elsewhere as listed in the locate database
|
||||
# Matches first by name, then by checksum (currently inefficiently via md5)
|
||||
case "$1" in ([0-9]) size=$1; shift;; esac
|
||||
find "$@" -size +${size:-5}M -type f -exec sh -c "IFS=$'\n'"'
|
||||
case $1 in ([0-9]|[0-9][0-9]) threshold=$1; shift;; esac
|
||||
find "$@" -size +${threshold:-50}M -type f -exec sh -c "IFS=$'\n'"'
|
||||
filepath="{}"
|
||||
target="$(basename "$filepath" | synct-unarchive)"
|
||||
highlight "$filepath"
|
||||
for existing in $(locate -b "$target")
|
||||
do test "$(realpath "$target")" != "$(realpath "$existing")" -a -f "$existing" -a "$(md5sum "$existing" | cut -d\ -f1)" = "$(md5sum "$filepath" | cut -d\ -f1)" && echo "Found duplicate at $existing" && rm -vi "$filepath" && break
|
||||
do test "$(realpath "$target")" != "$(realpath "$existing")" -a -f "$existing" && test "$(md5sum "$existing" | cut -d\ -f1)" = "$(md5sum "$filepath" | cut -d\ -f1)" && echo "Found duplicate at $existing" && rm -vi "$filepath" && break
|
||||
done' \;
|
||||
|
|
Loading…
Reference in New Issue