L’idée :
maj du système
sudo apt-get update && sudo apt-get -y upgrade
ghostscript
sudo apt install ghostscript -y
pdktk
sudo apt-get install pdftk -y
Tout en conservant une taille raisonnable, et en une seule ligne de commande
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/default -dNOPAUSE -dQUIET -dBATCH -dDetectDuplicateImages -dCompressFonts=true -r150 -sOutputFile=output.pdf input01.pdf input02.pdf input03.pdf
Le ficher output.pdf enregistré au même endroit que les fichiers sources sera le résultat de l’opération.
Pour créer un PDF avec les pages 1, 2, 4 et 5 d’un PDF de plusieurs pages :
$ pdftk myoldfile.pdf cat 1 2 4 5 output mynewfile.pdf
Note
les options cat et output sont spécifiques à pdftk :
Pour préciser une page range :
$ pdftk myoldfile.pdf cat 1-2 4-5 output mynewfile.pdf
Pour splitter chaque page en un fichier pdf spécifique :
$ pdftk myoldfile.pdf burst
Par défaut les fichiers seront nommés pg_0001.pdf, pg_0002.pdf, etc.
gs -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=setting -sOutputFile=output.pdf input.pdf
Summary of -dPDFSETTINGS:
Reference: https://www.ghostscript.com/doc/current/VectorDevices.htm#PSPDF_IN:
https://stackoverflow.com/questions/2507766/merge-convert-multiple-pdf-files-into-one-pdf
https://linuxcommando.blogspot.com/2013/02/splitting-up-is-easy-for-pdf-file.html
L’idée :
maj du système
sudo apt-get update && sudo apt-get -y upgrade
installer ImageMagick
sudo apt install imagemagick -y
L’exemple ci-dessous ajoute 2 filigranes sur le document (un bleu et un rouge) :
convert -size 140x80 xc:none -fill '#FF0000' -draw "text 10,10 'Vive les shadocks'" \
-gravity SouthEast -fill '#0000FF' -draw "text 5,5 'Document Libre'" miff:- \
| composite -tile - $SOURCE.jpeg $DESTINATION.jpeg
for folder in */; do 7z a -mx4 -mmt "${folder%/}.7z" "$folder"; done
## count empty dirs only
find /path/ -type d -empty
## count empty files only
find /path/ -type f -empty
## count empty dirs only
find /path/ -type d -empty | wc -l
## count empty files only
find /path/ -type f -empty | wc -l
## Delete empty directories
find /path/ -type d -empty -delete
## Delete empty files
find /path/ -type -f -empty -delete
The following script will take all *.mkv
files within your selected folder and move them into a folder based on their name. Note that this does not go into subfolders within the starting/selected folder.
cd /path/to/your/movies/files/
find . -maxdepth 1 -type f -iname "*.mkv" -exec sh -c 'mkdir "${1%.*}" ; mv "${1%}" "${1%.*}" ' _ {} \;
for %i in (*) do md "%~ni"
This will create a folder for every file in the directory.
for %i in (*) do move "%i" "%~ni"
This will move all of your files into the new directories.
If you need to clean up empty directories, this command will do that:
for /f "usebackq delims=" %d in ("dir /ad/b/s | sort /R") do rd "%d"
Alternatively in Windows you can run the following script in Powershell to iterate over each file in a directory, and move it to a folder with the same name.
Get-ChildItem -File
| ForEach-Object {
$dir = New-Item -ItemType Directory -Name $_.BaseName -Force
$_ | Move-Item -Destination $dir
}
Delete folders recursively:
find /path/to/source/ -name 'nameOfTheDirectory' -exec rm -rf {} \;
This will do it recursively for you:
find /path/to/base/dir/* -type d -ctime +10 -exec rm -rf {} \;
Explanation:
source: https://stackoverflow.com/questions/13868821/shell-script-to-delete-directories-older-than-n-days
find . -not -path '*/.*'
Excellent tuto sur les différences entre les arguments atime, ctime et mtime :
https://www.unix.com/tips-and-tutorials/20526-mtime-ctime-atime.html