5

I am looking to free some space by clearing out the thumbnail cache from terminal.

Inside the ~/.cache/thumbnails folder, I see 3 folders:

  1. fail
  2. large
  3. normal

Is it safe to clear out all three folders?

3 Answers 3

7

In Ubuntu 14.04 thumbnails are stored in ~/.cache/thumbnails while in Ubuntu 12.04 is stored in ~/.thumbnails.

Simply you can delete everything in there including those directories without being afraid of something bad will happen. This will just reset your thumbnails, causing them to be recreated according to the global settings.

2
  • Gotcha, thanks for confirming. Will do. I'll accept the answer once this time limit elapses. Cheers! Jun 2, 2015 at 6:16
  • @esteemed.squire you are welcome
    – Maythux
    Jun 2, 2015 at 6:28
0

You could schedule deleting your thumbnail files by editing your crontab with the command crontab -e and adding a line such as 30 09 * * * find /home/yourname/.cache/thumbnails/ -maxdepth 3 -type f -delete as suggested by "troller" here.

0

A little command line script, then!

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .