Skip to content

Instantly share code, notes, and snippets.

View vijinho's full-sized avatar

Vijay vijinho

  • England
View GitHub Profile
@vijinho
vijinho / directory-tree-clone.sh
Last active January 6, 2025 11:23
Clone a directory tree structure without the files
#!/bin/bash
# Function to show help
usage() {
echo "Usage: $0 [-h] -s <source> -d <destination>"
echo " -h, --help Show this help message and exit."
echo " -s, --source Specify the source directory or file."
echo " -d, --destination Specify the destination directory."
return 1
}
@vijinho
vijinho / disk-set-sleep-time.sh
Last active January 6, 2025 11:14
Clear standby mode and set the disk sleep-time in Linux
#!/bin/bash
# Function to check if a device file exists and is an HDD
is_valid_device() {
if ! test -b "$DEVICE"; then
echo "Error: '$DEVICE' is not a valid block device."
return 1
fi
if ! grep -q "$DEVICE" /proc/partitions; then
@vijinho
vijinho / files-by-type.php
Created May 7, 2019 14:34
list files by type
#!/usr/bin/php
<?php
/**
* files-by-type.php - get metadata from files readable with exiftool
* and presents options for renaming
* creates cache files, metadata.ser
*
* https://www.sno.phy.queensu.ca/~phil/exiftool/#filename
* see https://www.sno.phy.queensu.ca/~phil/exiftool/exiftool_pod.html
*
@vijinho
vijinho / pdf-rename-auto.php
Created May 6, 2019 14:21
automatically rename PDF files found as: year - title - author(s)
<?php
/**
* get-rename.php - get metadata from files readable with exiftool
* and presents options for renaming
* creates cache files, metadata.ser
*
* https://www.sno.phy.queensu.ca/~phil/exiftool/#filename
* see https://www.sno.phy.queensu.ca/~phil/exiftool/exiftool_pod.html
*
* relies on command-line tools, tested on MacOS.
@vijinho
vijinho / calibre-rename-jdupes.php
Created May 5, 2019 22:53
Find/remove duplicate files in subfolders and move/rename files exported from calibre ebook application folder in OPF files.
<?php
/**
* get-rename.php - get metadata from files readable with exiftool
* and presents options for renaming
* creates cache files, metadata.ser
*
* https://www.sno.phy.queensu.ca/~phil/exiftool/#filename
* see https://www.sno.phy.queensu.ca/~phil/exiftool/exiftool_pod.html
*
* relies on command-line tools, tested on MacOS.
@vijinho
vijinho / pdf-linearize.php
Last active August 17, 2023 16:00
use qpdf to linearize a bunch of pdf files
<?php
/**
* pdf-linearize.php - linearize PDFs
* WARNING: May run extremely slowly due to very large file sizes generated on pdf2ps
*
* relies on command-line tools, tested on ubuntu.
*
* @license GPLv3 (http://www.gnu.org/licenses/gpl-3.0.html)
*/
@vijinho
vijinho / pdf-rename.php
Last active May 3, 2019 00:17
Finds a list of files readable with exiftool (used for PDFs mainly) and present renaming/view options for MacOS
<?php
/**
* get-rename.php - get metadata from files readable with exiftool
* and presents options for renaming
* creates cache files, metadata.ser
*
* https://www.sno.phy.queensu.ca/~phil/exiftool/#filename
* see https://www.sno.phy.queensu.ca/~phil/exiftool/exiftool_pod.html
*
* relies on command-line tools, tested on MacOS.
@vijinho
vijinho / get_exiftool_metadata.php
Last active April 25, 2019 20:35
Get the exif(tool) metadata for a file
<?php
/**
* get-metadata.php - get metadata from files readable with exiftool
* creates 2 cache files, metadata.ser and metadata.old.ser
* where old.ser is the old version of metadata.ser for comparison
*
* https://www.sno.phy.queensu.ca/~phil/exiftool/#filename
* see https://www.sno.phy.queensu.ca/~phil/exiftool/exiftool_pod.html
*
* relies on command-line tools, tested on MacOS.
@vijinho
vijinho / pdf_rename_metadata.php
Last active April 25, 2019 11:31
get metadata from file using exiftool https://www.sno.phy.queensu.ca/~phil/exiftool/#filename and compare to previous metadata file to see savings of filesize
<?php
/**
* pdf_rename_metadata.php - get metadata from files readable with exiftool and rename
* creates 2 cache files, metadata.ser and metadata.old.ser
* where old.ser is the old version of metadata.ser for comparison
*
* https://www.sno.phy.queensu.ca/~phil/exiftool/#filename
* see https://www.sno.phy.queensu.ca/~phil/exiftool/exiftool_pod.html
*
* relies on command-line tools, tested on MacOS.
<?php
/**
* pdf-compress.php - re-compress PDFs, shrinking if possible
* WARNING: May run extremely slowly due to very large file sizes generated on pdf2ps
*
* relies on command-line tools, tested on ubuntu.
*
* @license GPLv3 (http://www.gnu.org/licenses/gpl-3.0.html)
*/