Announcement

Collapse
No announcement yet.

HOWTO : Cleaning old KDE thumbnails

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    HOWTO : Cleaning old KDE thumbnails

    Removing old thumbnails

    KDE and KDE programs (Konqueror/Dolphin/Gwenview...) generate preview thumbnails in the ~/.thumbnails. When you move or delete original file, KDE just forgets that there is already a thumbnail. There are no cache size limit / expiration date for these thumbnails. These old thumbnails became obsolete disk space waste.

    Earlier:
    Topic: KDE thumbnail generator running wild ?
    http://kubuntuforums.net/forums/inde...opic=3081086.0


    Setting expiration date (deleting old):

    Make script file (thumbsaway):
    Code:
    #!/bin/sh
    
    #remove older than 30 days
    find /home/user/.thumbnails/ -mtime +30 -exec rm -f {} \;
    Note
    user = your username

    Put it in the /etc/cron.daily/. anacron should execute these scripts once a day.

    Set permissions:
    Code:
    sudo chmod -v 755 /etc/cron.daily/thumbsaway
    From UNIX permissions and chmod tutorial
    http://www.unixcities.com/howto/index3.html
    So, 755 is a terse way to say 'I don't mind if other people read or run this file, but only I should be able to modify it' and 777 means 'everyone has full access to this file'

    Links:

    Clean your KDE thumbnail directory
    http://www.kenschutte.com/clean_thumbnail_dir/

    Chmod Wiki
    http://en.wikipedia.org/wiki/Chmod

    UNIX permissions and chmod tutorial
    http://www.unixcities.com/howto/index3.html

    HowTo Chmod
    http://wiki.mybboard.net/index.php/HOWTO_Chmod

    HOWTO use cron
    http://gentoo-wiki.com/HOWTO_use_cron

    An A-Z Index of the Linux BASH command line
    http://www.ss64.com/bash/

    Alphabetical Directory of Linux Commands
    http://www.oreillynet.com/linux/cmd/
    Before you edit, BACKUP !

    Why there are dead links ?
    1. Thread: Please explain how to access old kubuntu forum posts
    2. Thread: Lost Information

    #2
    Re: HOWTO : Cleaning old KDE thumbnails

    Using ImageMagick's identify command to screen obsolete thumbnails.

    man identify:
    identify(1) identify(1)

    NAME
    identify - describes the format and characteristics of one or more
    image files.

    SYNOPSIS
    identify [options] input-file

    OVERVIEW
    The identify program is a member of the ImageMagick(1) suite of tools.
    It describes the format and characteristics of one or more image files.
    It also reports if an image is incomplete or corrupt. The information
    returned includes the image number, the file name, the width and height
    of the image, whether the image is colormapped or not, the number of
    colors in the image, the number of bytes in the image, the format of
    the image (JPEG, PNM, etc.), and finally the number of seconds it took
    to read and process the image. Many more attributes are available with
    the verbose option.

    For more information about the identify command, point your browser to
    file:///usr/share/doc/imagemagick/www/identify.html or
    http://www.imagemagick.org/script/identify.php.
    This script simply checks is there original file. If not, it removes thumbnail picture. There is also expiration check for the thumbnails.

    Code:
    #!/bin/sh
    
    # Expiration age of thumbnails (days).
    EXPIRE=30
    # Path to thumbnails
    THUMB=/home/<user>/.thumbnails
    
    DLIST=`ls -1 $THUMB`
    
    for D in $DLIST
    do
     FLIST=`find $THUMB/$D/ -name "*.png" -exec ls {} \;`
     for F in $FLIST
     do
    #  Parsing ImageMagick's output.
       O=`identify -verbose $F | grep -v "Thumbnail of file:" | grep "file:"| sed s/"Thumb::URI:"//g | sed s/"file:\/\/"//g`
       if [ -f $O ];
    #    Original file exist.
        then
    #     Removing expired thumbnail.
          find $F -mtime +$EXPIRE -exec rm -f {} \;
    #    Original file does not exist.
        else
    #     Removing obsolete thumbnail.
          rm -f $F
       fi
     done
    done
    Note
    <user> is your username.


    Update. A bit better (?) version:

    Using extract command to screen obsolete thumbnails.

    Code:
    #!/bin/sh
    
    # Expiration age of thumbnails (days).
    EXPIRE=30
    # Path to thumbnails
    THUMB=/home/<user>/.thumbnails
    
    DLIST=`ls -1 $THUMB`
    
    for D in $DLIST
    do
     FLIST=`find $THUMB/$D/ -name "*.png" -exec ls {} \;`
     for F in $FLIST
     do
    #  parsing extracts's output.
       O=`extract $F | grep "file:"| sed s/"unknown - file:\/\/"//g | sed s/"%20"/" "/g`
       if [ -f "$O" ];
    #    Original file exist.
        then
    #     Removing expired thumbnail.
          find $F -mtime +$EXPIRE -exec rm -f {} \;
    #    Original file does not exist.
        else
    #     Removing obsolete thumbnail.
          rm -f $F
       fi
     done
    done
    man extract
    NAME
    extract - determine meta-information about a file

    SYNOPSIS
    extract [ -abdfghLnrsvV ] [ -B language ] [ -H hash-algorithm ] [ -l library ] [ -p type ] [ -x type ] file ...
    Package: extract
    displays meta-data from files of arbitrary type

    Similar to the well-known "file" command, extract can display meta-data from a
    file and print the results to stdout...

    Anacron will do the check if you drop the script in the /etc/cron.daily. Other places: FAQ: How to start programs when KDE starts or stops


    Tools for cleaning:

    kleansweep - File cleaner for KDE
    File cleaner for KDE
    KleanSweep allows you to reclaim disk space by finding unneeded files.
    It can search for files basing on several criterias; you can seek for:
    - empty files
    - empty directories
    - backup files
    - broken symbolic links
    - broken executables (executables with missing libraries)
    - dead menu entries (.desktop files pointing to non-existing executables)
    - duplicated files
    - orphaned files -- files not found in RPM (for rpm-based distros, e.g.
    Fedora Core, Suse) or DPKG (for dpkg based distros, e.g. Debian and Ubuntu)
    database
    - obsolete thumbnails (thumbnails conforming to freedesktop.org standard,
    pointing to non-existing images)

    Homepage: http://linux.bydg.org/~yogin/
    Cleaning up a Ubuntu GNU/Linux system
    http://www.ubuntugeek.com/cleaning-u...in-ubuntu.html


    Links

    Introduction to ImageMagick
    http://www.imagemagick.org/script/index.php

    ImageMagic:Command-line Tools:Identify
    http://www.imagemagick.org/script/identify.php

    "Argument list too long": Beyond Arguments and Limitations
    http://www.linuxjournal.com/article/6060

    /bin/rm annoying limitation: Argument list too long
    http://www.ducea.com/2006/05/24/binr...list-too-long/
    Before you edit, BACKUP !

    Why there are dead links ?
    1. Thread: Please explain how to access old kubuntu forum posts
    2. Thread: Lost Information

    Comment


      #3
      Re: HOWTO : Cleaning old KDE thumbnails

      Using Anacron

      About anacron
      http://en.wikipedia.org/wiki/Anacron


      1) Simply put executable /1/ script file in the /etc/cron.daily, /etc/cron.weekly or /etc/cron.monthly.
      2) Touch the script file:
      Code:
      sudo touch /etc/cron.daily/scriptfile
      man touch:
      TOUCH(1) User Commands TOUCH(1)

      NAME
      touch - change file timestamps

      SYNOPSIS
      touch [OPTION]... FILE...

      DESCRIPTION
      Update the access and modification times of each FILE to the current
      time.

      Mandatory arguments to long options are mandatory for short options
      too.

      -a change only the access time

      -c, --no-create
      do not create any files

      -d, --date=STRING
      parse STRING and use it instead of current time

      Testing scripts with anacron

      man anacron:
      ANACRON(8) Anacron Users’ Manual ANACRON(8)

      NAME
      anacron - runs commands periodically

      SYNOPSIS
      anacron [-s] [-f] [-n] [-d] [-q] [-t anacrontab] [-S spooldir] [job]
      ...
      anacron [-S spooldir] -u [-t anacrontab] [job] ...
      anacron [-V|-h]
      anacron -T [-t anacrontab]

      DESCRIPTION
      Anacron can be used to execute commands periodically, with a frequency
      specified in days. Unlike cron(8), it does not assume that the machine
      is running continuously. Hence, it can be used on machines that aren’t
      running 24 hours a day, to control daily, weekly, and monthly jobs that
      are usually controlled by cron.

      When executed, Anacron reads a list of jobs from a configuration file,
      normally /etc/anacrontab (see anacrontab(5)). This file contains the
      list of jobs that Anacron controls.

      Test run:
      Code:
      sudo anacron -f -d
      -f Force execution of the jobs, ignoring the timestamps.
      -d Don’t fork to the background. In this mode, Anacron will output
      informational messages to standard error, as well as to syslog.
      The output of jobs is mailed as usual.

      Anacron messages in the log:
      Code:
      grep anacron /var/log/syslog
      Anacron keeps timestamps in the /var/spool/anacron/. If you remove cron.daily, cron.weekly or cron.monthly files from there, anacron will execute daily, weekly or monthly scripts at the next startup.


      /1/ To make script executable:
      Dolphin/Konqueror, right click script > Properties > Permissions > is executable.
      or
      Code:
      chmod +x /path/to/script.sh
      man chmod
      CHMOD(1) User Commands CHMOD(1)

      NAME
      chmod - change file access permissions

      SYNOPSIS
      chmod [OPTION]... MODE[,MODE]... FILE...
      chmod [OPTION]... OCTAL-MODE FILE...
      chmod [OPTION]... --reference=RFILE FILE...

      DESCRIPTION
      This manual page documents the GNU version of chmod. chmod changes the
      permissions of each given file according to mode, which can be either a
      symbolic representation of changes to make, or an octal number repre‐
      senting the bit pattern for the new permissions.

      Links:

      chmod Tutorial
      http://catcode.com/teachmod/

      18.4. Configure the /etc/cron.daily/tripwire.verify script
      http://www.faqs.org/docs/securing/chap18sec147.html
      Before you edit, BACKUP !

      Why there are dead links ?
      1. Thread: Please explain how to access old kubuntu forum posts
      2. Thread: Lost Information

      Comment

      Working...
      X