Image optimisation – bulk

Image optimisation – bulk

Tools used to optimise images within a folder/sub-folder:¬†optipng, jpegoptim To install these tools use the following commands: Centos yum install epel-release yum update yum install -y optipng jpegoptim Debian/Ubuntu apt install -y optipng jpegoptim To use the the tools in a recursive way use the following bash script: #!/bin/bash ################## USAGE ########################### # ./optimiseImages.sh /full/path/to/folder OR # ./optimiseImages.sh /full/path/to/folder > opt.log ################## END USAGE ####################### folderPathOriginal=$1 function optiomiseImages(){ folderPath=$1 for file in “$folderPath”/* do if [ -d “${file}” ] ;…

Read More Read More

Rudimentary file scan

Rudimentary file scan

This is a block of bash script which checks files (php,phtml) for potential malware, this is by no means perfect and it will probably come up with a lot of false positives but it will give you a general idea of what is happening in your code. Basically the script will check a folder for php/phtml files which use the following statements : eval – used to evaluate php code coming from a string mysql_query – runs a direct query…

Read More Read More

Copy files through multiple gateways

Copy files through multiple gateways

Script to copy files over multiple gateways This will be used if the destination server is only accessible through another server/multiple servers Example:¬† We want to move a website folder from server A to server D, but server C is the only server who has access to server D, and server A only has direct access to server B. In order to have access to server D we need to connect from server A to server B, and from server…

Read More Read More

Delete large amounts of files

Delete large amounts of files

Script to remove large number of files (amount > ARG_MAX) Create a script file with whatever name you want, let’s say “removefiles.sh” and put in the following content: #!/bin/bash folderPath=$1 a=$(du -sk $folderPath | awk ‘{print$1}’) while [ $a -gt 0 ]; do for file in $(ls -p $folderPath | grep -v / | tail -1000) do rm -rf “${folderPath}/${file}” done echo “Last file deleted was: ${file}” if [ $a -le 50000 ]; then a=$(ls $folderPath | wc -l) echo…

Read More Read More

Linux aliases

Linux aliases

Aliases in linux are placeholders for longer commands to enable you to type faster without remembering the full syntax of a command. Aliases are defined usually in a file called .bash_aliases and included by default on some distributions of linux if not the following command will include them if it’s added in .bashrc/.bash_profile if [ -n “$BASH_VERSION” ]; then # include .bash_aliases if it exists if [ -f “$HOME/.bash_aliases” ]; then . “$HOME/.bash_aliases” fi fi Alias structure alias name=value alias…

Read More Read More

%d bloggers like this: