I use php to convert pdf to jpeg but sometimes it’s very slow. So, the solution is to use poppler and use pdftoppm directly to shell.
Category Archives: Linux
exec and exec_shell in php
If you are using blanks in filenames or any other special character then you need to use escapeshellarg.
https://stackoverflow.com/questions/43513228/php-shell-exec-failed-due-to-some-specific-character
Also, exec and exec_shell are returning status and string of the last command executed (read docs) but it’s somewhat hard to understand when it’s true or false. I didn’t manage to use === operator to check logical expressions returned from the ran command.
https://stackoverflow.com/questions/41212053/php-shell-exec-and-exec-returning-false-when-ran
Also,for pdf merging use:
https://stackoverflow.com/questions/2507766/merge-convert-multiple-pdf-files-into-one-pdf
Rsync exclude include
rsync -av --include '*.md' --include '*/' --exclude '*' --prune-empty-dirs src/ dst/
https://unix.stackexchange.com/questions/741904/rsync-to-exclude-everything-except-specific-files
PDF to JPEG
If you need to convert pdf to jpg I was working with php but it might be slow, obviously. But if you are using linux shell then it’s easier and faster.
72 dpi (web) = 595 X 842 pixels
300 dpi (print) = 2480 X 3508 pixels
600 dpi (print) = 4960 X 7016 pixels
Merge pdf with single command in linux
Poppler has one command to merge all pdfs from folder:
pdfunite *.pdf out.pdf
https://stackoverflow.com/questions/2507766/merge-convert-multiple-pdf-files-into-one-pdf
Change character in filename linux bash
I’m figuring this out for some time. It’s not that I can’t read but most of the time when trying out bash stuff you can make more damage then good to your system so you have to be really really easy.
Now, this one here makes the difference. I had a job to change & in many many many files in different directories and subdirectories and after trying many scripts this one came up working just fine and fast.
find . -type f -exec rename 's/string1/string2/g' {} +
If you want to target specific filename extension then you need to add:
find . -type f -name "*.webp" -exec rename 's/&/-/g' {} +
It was taken from here:
https://unix.stackexchange.com/questions/416018/how-to-replace-a-string-in-all-folder-and-file-names
Biggest folders in current path
If you need to find what is the biggest folders in current path in linux then this is the command:
du -sh * 2>/dev/null | sort -h
It needs couple of seconds to calculate (if you have slow io vps or hdd) and this is what you get:
root@vps3345:/home/nick/web# du -sh * 2>/dev/null | sort -h
713M alle.ch
1.1G moji.com
1.6G rab.de
1.8G zoek.nl
2.5G al.at
5.4G mojia.si
7.6G a.co.uk
11G sle.cz
13G akceer.com
Linux screen
About linux screen program. Really nice to have it but usually when I find some article about using some linux software, there are always some missing pieces and then I have to search google again and again and that’s not good.
Type:
screen -> it opens up new screen window and you are in it
ctrl +a is for switching windows
ctrl+a c is for creating new screen window
Now to close it (detach) use:
ctrl+a d
To list all current screens:
screen -ls
To reattach to it use:
screen -r (number)
To close it use:
screen -XS (number) quit
Here are references:
https://linuxize.com/post/how-to-use-linux-screen/
https://askubuntu.com/questions/356006/kill-a-screen-session
Delete everything multiple files Linux
If you want to find and delete some files from your drive then use this command:
find . -type f ! \( -name "*thumb.jpg" -o -name "*1200w.jpg" \) -exec rm -rf {} \;
Explanation: https://unix.stackexchange.com/questions/78376/in-linux-how-to-delete-all-files-except-the-pattern-txt
https://unix.stackexchange.com/questions/50612/how-to-combine-2-name-conditions-in-find
Adding IP address – failover ip
First edit : nano /etc/network/interfaces
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
source /etc/network/interfaces.d/*
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
#allow-hotplug eno1
#iface eno1 inet dhcp
auto eno1
iface eno1 inet static
address 195.154.242.173
netmask 255.255.255.255
gateway 195.154.242.1
auto eno1:0
iface eno1:0 inet static
address 51.158.26.20
netmask 255.255.255.255
And that’s all there is actually.
Use this as a reference.
https://documentation.online.net/en/dedicated-server/network/ip-failover/ip-failover