GNU/Linux Command Line
Permission denied errors on settings.php
chmod ug+w web/sites/defaultLong-running process
ssh user@server
tmux
sh long-running-command.sh
CTRL-b > d [detach]
exit
ssh user@server
tmux attachSearch for a file with fzf and open with Vim
vi `fzf`Change files in a directory
rename 's/ /-/g' * && rename 'y/A-Z/a-z/' *(replace spaces with hyphens and upper case with lower case)
Add a .doc file extension to all files in a directory
rename 's/(.*)/$1.doc/' *Fix quotation marks
sed -i 's/“/"/g' file && sed -i 's/”/"/g' file && sed -i "s/’/'/g" file && sed -i "s/‘/'/g" fileUpload ssh keys to a server
ssh-copy-id -i ~/.ssh/id_rsa.pub user@server.orgGet my IP address
curl ifconfig.co/ipGet battery capacity
sudo tlp-stat -bRun a command as another user
sudo -u www-data ./occ preview:generate-all -vvvIn the current directory, delete files older than 60 days that don’t end in “15.sql.gz”
find . -not -name "*15.sql.gz" -mtime +60 -exec rm {} \;Resize an image
convert logo.png -resize 300 logo.pngOptimize an image
[crop image, if necessary]
jpegoptim image.jpg
cwebp -q 60 image.jpg -o image.webpGet image info
file logo.pngAdd text to an image
convert image.jpg -pointsize 64 -font "LMMono12-Regular" -fill white -undercolor Black -annotate +220+70 'Yoga\nRocks!' image-text.jpgMake a list of ImageMagick font names that can be added to images
convert -list font | grep Font > /tmp/fontsConvert webp to jpg
dwebp image.webp -o output.pngCreate a QR code
qrencode -s 6 -l H -o "matthewtift.png" "https://matthewtift.com"Create an ico from a image file
icotool -o favicon.ico -c input.pngCrop and resize all images in a directory
mogrify -resize 1280x720^ -gravity center -extent 1280x720 *.jpg(gravity could also take values like North, NorthWest, or East)
Resize an image, keep aspect ratio, and fill blank space
convert input.jpg -resize 1280x720 -background white -gravity center -extent 1280x720 output.jpgRename all .jpg files in a directory sequentially
ls | grep "\.jpg$" | cat -n | while read n f; do mv "$f" `printf "image%03d.jpg" $n`; doneRename files in a directory starting with 15
num=15 && for file in *.mp3; do mv "$file" "sound-file-$(printf "%03d" $num).mp3"; let num=$num+1; donePrepend all .mp3 files in a directory with a 3-digit number
ls | grep "\.mp3$" | cat -n | while read n f; do mv "$f" `printf "%03d-$f" $n`; doneUpdate the title of a PDF
exiftool -Title="New Title" /path/to/filename.pdfAdd a signature to a PDF
xournal document.pdf
tools >> image >> click in document >> select imagePassword protect a PDF
pdftk source.pdf output destination.pdf user_pw PROMPTSend a notification (pop-up) after a process is complete
drush mim migrate_nodes; notify-send "Node migration complete"Spin up a Drupal 8 site
cd /var/www
mkdir drupal && cd drupal && curl -sSL https://ftp.drupal.org/files/projects/drupal-8.9.12.tar.gz | tar -xz --strip-components=1
php ./core/scripts/drupal quick-start standardDrupal core workflow
wget http://drupal.org/issue.patch
git apply --index issue.patch
[hack]
git diff > interdiff.txt
git diff HEAD > new.patchCreate a patch file that removes a binary file in Git
rm image.png
git diff --binary > issue.patchCompare files changed in my branch to master
git diff master my-branch --name-onlyUpdate default browser in Debian
sudo update-alternatives --config x-www-browserConvert Unix timestamp on the command line
date -d @$TIMESTAMPGet current time in something like PBS Changelog format
date -u +%Y-%m-%dT%H:%M:%S.%NFind and edit
grep -rl 'hook_expire_cache_alter' . | xargs gvim -pFind and replace
grep -rl 'OLD_TEXT' . | xargs sed -i 's/OLD_TEXT/NEW_TEXT/g'Download high quality audio from YouTube (best quality is 0)
youtube-dl --extract-audio --audio-format wav --audio-quality 0 URLCrop/cut a video
9 minutes and 20 seconds of a video starting at 1 minute and 30 seconds
ffmpeg -i input.mp4 -ss 00:01:30 -t 00:09:20 part1.mp4
[or]
ffmpeg -i input.mp4 -ss 00:01:30 -to 00:10:50 part1.mp414 minutes and 20 seconds of the top left part of a video, starting at 18 seconds
ffmpeg -i video1996041126.mp4 -ss 00:00:18 -to 00:14:38 -filter:v "crop=640:360:0:0" output.mp4Crop the left half of a Zoom video starting at 7 seconds and ending at 30:25:
ffmpeg -i LF2023-12-17.mp4 -ss 00:00:07 -to 00:30:25 -filter:v "crop=1600:960:0:0" output.mp4Combine audio with one file with the video from other file
ffmpeg -i INPUT_FILE.mp4 -i AUDIO.mp3 -c:v copy -c:a copy -map 0:v:0 -map 1:a:0 OUTPUT_FILE.mp4Get “Date Taken” times of JPGs in a directory
exiv2 *.JPG | grep "Image timestamp"Change “Date Taken” times of JPGs in a directory
exiftool "-AllDates=2002:01:01 04:00:00" *.JPGFind Files 100-999M
du -h | grep '[0-9]\{3\}M'Make PDFs searchable
ocrmypdf file.pdf file.pdfPHP
Log arrays with logger in Drupal 8
\Drupal::logger('Matthew')->notice('<pre><code>' . print_r($variable, TRUE) . '</code></pre>');Debug JS in PHP code
echo "<script type='text/javascript'> alert(" . print_r($var) . "); </script>";Pass array as command line argument
php -r "print json_encode(array('node/*/edit' =>
'128M', 'node/add/type' => '128M'));" |
drush vset --format=json page_memory_limit -Export var_dump json responses to a file to open with Firefox
$fp = fopen('/tmp/results.json', 'w');
fwrite($fp, json_encode($response));
fclose($fp);MySQL
Get Size of All MySQL Databases
SELECT table_schema "DB Name",
Round(Sum(data_length + index_length) / 1024 / 1024, 1) "DB Size in MB"
FROM information_schema.tables
GROUP BY table_schema;Stop Drupal cron using MySQL (via drush)
drush sqlq "DELETE FROM semaphore WHERE name = 'cron';"Delete all files in a Drupal database
TRUNCATE file_managed;
TRUNCATE file_usage;Vim
Count words in Vim
g > CTRL-gWrap text
gwwDelete blank lines in Vim
:g/^$/dVim special characters (didigraphs)
CTRL-k a - (ā)
CTRL-k a ! (à)
CTRL-k n . (ṅ)
CTRL-k e ' (é)
CTRL-k u - (ū)
CTRL-k u : (ü)
CTRL-k D G (°, the degree character)Paste into the Vim command line
CTRL-r +Remove ^M characters at end of lines
%s/[CTRL-V CTRL-M]//gJump to the class under the cursor
CTRL-]Jump back
CTRL-tSurround 1 word with a single quote
viwS'Surround 2 words (separated by a space) with asterisks
v3iwS*Swap text around equal sign
:%s/\([^=]*\)\s\+=\s\+\([^;]*\)/\2 = \1Generate number lines
Insert "0. " for each line that needs a number
"CTRL-V" to select each line
"g CTRL-a" to replace the numbers with a sequenceFormat XML
! xmllint --format -