Skip to main content

Useful Server Commands

  • List sizes of all files and folders in current directory:du -sh *
  • Delete all files and folders in current directory:rm -rf *
  • Find all .trash folders in the /home directory:find /home -type d -name .trash
  • Find and delete all .trash folders in the /home directory:find /home -type d -name .trash | xargs rm -rf
  • Find all .zip files greater than 100mb in the /home directory:find /home -type f -size +100M -iname \*.zip
  • Find all .tar.gz files greater than 100mb in the /home directory:find /home -type f -size +100M -iname \*.tar.gz

Magento

Magento Server Commands

  • Clean magento logs:php -f /home/[CPANELUSER]/public_html/shell/log.php clean
  • Delete all backups:rm -rf /home/[CPANELUSER]/public_html/var/backups/*
  • Delete cache:rm -rf /home/[CPANELUSER]/public_html/var/cache/*
  • Delete all logs:rm -rf /home/[CPANELUSER]/public_html/var/log/*
  • Delete image cache:rm -rf /home/[CPANELUSER]/public_html/media/catalog/product/cache/*
  • Find all media import folders:find /home -path "*/media/import" -type d
  • Find and delete all media import folders:find /home -path "*/media/import" -type d | xargs rm -rf

Cleaning Magento Databases

Open up your MySQL editor and type the following SQL command in. This will clear all the unneccessary logs that Magento holds. Please remember to change the names of each table to include any table prefixes you may have

 SET foreign_key_checks = 0;
 TRUNCATE dataflow_batch_export;
 TRUNCATE dataflow_batch_import;
 TRUNCATE log_customer;
 TRUNCATE log_quote;
 TRUNCATE log_summary;
 TRUNCATE log_summary_type;
 TRUNCATE log_url;
 TRUNCATE log_url_info;
 TRUNCATE log_visitor;
 TRUNCATE log_visitor_info;
 TRUNCATE log_visitor_online;
 TRUNCATE report_viewed_product_index;
 TRUNCATE report_compared_product_index;
 TRUNCATE report_event;
 TRUNCATE index_event;
 TRUNCATE catalog_compare_item;
 SET foreign_key_checks = 1;

Image Resizing/Compression Script

This is a bash script that resizes and/or compresses images. It was initially built to free up space on the server but can also be used to compress images to decrease load times and bandwidth usage. By default, it compresses images to 60% and resizes images to max 1200×1200 (keeping aspect ratio the same). You are able to compress or resize separately.

Installation

  • Make sure ImageMagik is installed (on cPanel: Software >> Install an RPM)
  • Upload/create a file called imagetools.sh with the below code in it
  • Make file executable:chmod +x imagetools.sh
  • Move to /usr/bin:mv imagetools.sh /usr/bin/
#Script will take folder name as parameter
#Find all files
#Check if a file is image
    #If image then check if size is > 1200 width
        #If yes then resize/compress
 
option=$1
path=$2
files=`find $path -type f -exec file {} \; | awk -F: '{if ($2 ~ /image/) print $1}'`;

while read file; do
    owner=`ls -al "$file" | awk '{print $3}'`;
    group=`ls -al "$file" | awk '{print $4}'`;
    perms=`stat -c '%a' "$file"`;

    if [ "$option" == "resize" ]; then
        w=`identify "$file" | cut -f 3 -d ' ' | sed 's/x.*//'`;
        if [ $w -gt 1200 ]; then
            echo 'Resizing Image : '$file;
            mogrify -resize 1200x1200 "$file";
        fi; 
    fi; 
         
    if [ "$option" == "compress" ]; then
        echo 'Compressing Image : '$file;
        convert -quality 60 "$file" "$file";
    fi; 

    chown "$owner":"$group" "$file";
    chmod "$perms" "$file";
done <<< "$files"

Usage

  • To compress images to 60%:imagetools.sh compress /[FOLDERPATH]
  • To resize images to 1200x1200px type:imagetools.sh resize /[FOLDERPATH]

Usage with Magento

  • Resize product images:imagetools.sh resize /home/[CPANELUSER]/public_html/media/catalog/product/
  • Compress product images:imagetools.sh compress /home/[CPANELUSER]/public_html/media/catalog/product/

Usage with WordPress

  • Resize uploaded images:imagetools.sh resize /home/[CPANELUSER]/public_html/wp-content/uploads/
  • Compress uploaded images:imagetools.sh compress /home/[CPANELUSER]/public_html/wp-content/uploads/