从 Ubuntu 14.04 上的终端清除缩略图缓存

从 Ubuntu 14.04 上的终端清除缩略图缓存

我希望通过清除终端的缩略图缓存来释放一些空间。

在文件夹内~/.cache/thumbnails,我看到 3 个文件夹:

  1. 失败
  2. 大的
  3. 普通的

清除所有三个文件夹安全吗?

答案1

在 Ubuntu 14.04 中缩略图存储在 中,~/.cache/thumbnails而在 Ubuntu 12.04 中存储在 中~/.thumbnails

您可以简单地删除其中的所有内容,包括那些目录,而不必担心会发生不好的事情。这只会重置您的缩略图,并根据全局设置重新创建它们。

答案2

您可以通过编辑定时任务使用命令crontab -e并添加一行,如30 09 * * * find /home/yourname/.cache/thumbnails/ -maxdepth 3 -type f -delete“troller”所建议的那样这里

答案3

那么,是一个小的命令行脚本!

#!/bin/bash
# Checked with https://www.shellcheck.net/

set -o nounset

user=             # user to clean
do_it=            # nonempty to actually run remove commands
cmdline_user=     # user given on cmdline (if any)

# ---
# Option processing
# ---

processOptions() {

   # We use bash regular expressions, which are "grep" regular expressions; see "man grep"
   # or "man 7 regex"
   # In that case, the string on the right MUST NOT be enclosed in single or double quotes,
   # otherwise it becomes a literal string

   local param=       # Current parameter
   local use_user=    # Set to nonempty if a user argument is expected in the next PARAM

   local unknown=     # Accumulates unknown PARAMS
   local print_help=  # Set to nonempty if help requested

   for param in "$@"; do   

      # Process arguments that are separate from their option

      if [[ -n $use_user ]]; then
         cmdline_user=$param
         use_user=""
         continue
      fi

      # Process option

      if [[ $param == '--do' ]]; then
         # set global variable
         do_it=YES
         continue
      fi

      if [[ $param =~ --user(=.+)? ]]; then
         if [[ $param =~ --user=(.+)? ]]; then
            # set global variable
            cmdline_user=$(echo "$param" | cut --delimiter="=" --fields=2)
         else 
            # expecting value
            use_user=1
         fi
         continue
      fi

      if [[ $param == '--help' || $param == '-h' ]]; then
         print_help=1
         break
      fi

      # if we are here, we encountered something unknown in PARAM
      # if UNKNOWN is already set, add a comma for separation

      if [[ -n $unknown ]]; then
         unknown="$unknown,"
      fi

      unknown="${unknown}${param}"

   done

   if [[ -n $unknown ]]; then
      echo "Unknown parameters '$unknown'" >&2
      print_help=1
   fi

   if [[ -n $print_help ]]; then
      echo "--user=... to explicitly give user to clean" >&2
      echo "--do       to actually perform operations instead of just printing them" >&2
      exit 1
   fi

}

processOptions "$@"

# The user to handle is either myself or it comes from the command line

if [[ -n $cmdline_user ]]; then
   user=$cmdline_user
else
   user=$(whoami)
fi

# Does the user actually exist? If so get the home dir 

if ! record=$(getent passwd "$user"); then
   echo "Could not get passwd entry of user '$user' -- exiting" >&2
   exit 1
fi

zehome=$(echo "$record" | cut -f6 -d:)

if [[ ! -d "$zehome" ]]; then
   echo "Home directory of user '$user' is '$zehome' but that directory does not exist -- exiting" >&2
   exit 1
fi

# ********
# Path to actually clean out, configure as needed
# ********

clean[0]="$zehome/.cache/thumbnails"
clean[1]="$zehome/.kde/share/apps/okular/docdata"

# Run operations. Depending on "do_it", it's done or not!

for dir in "${clean[@]}"; do   
   if [[ ! -d "$dir" ]]; then
      echo "(Directory '$dir' does not exist or may not be a directory -- skipping that directory)" >&2
   else
      if [[ -z $do_it ]]; then
         echo "Would run: /bin/rm -r \"$dir\""
      else
         echo "Running: /bin/rm -r \"$dir\""
         /bin/rm -r "$dir"
      fi
   fi
done

相关内容