↑ ↓ select, Enter open, Esc close

Convert images to WebP recursively

Caution: This command changes the system. Understand what it does before you run it.

Adjust the values, the command updates live
user@server
find /var/www/vhosts/example.com/httpdocs/wp-content/uploads -type f \( -iname '*.jpg' -o -iname '*.jpeg' -o -iname '*.png' \) -exec sh -c 'for f; do [ -e "$f.webp" ] || cwebp -quiet -q 80 "$f" -o "$f.webp"; done' sh {} +

Converts each JPEG and PNG to WebP and saves the result as bild.jpg.webp next to the original. Existing WebP files are skipped, so running it again only processes new images. WebP is usually much smaller than JPEG, which improves load time and LCP.

Note: cwebp is part of the webp package. The web server or a plugin has to take care of serving the files. When run as root, the new files belong to root, so better run it as the webspace user.

Also searched as

  • bulk convert jpg to webp linux
  • convert all images to webp command line
  • generate webp for wordpress uploads
  • cwebp recursive conversion

Read first, then run.

The commands on myline.de act directly on servers, files and databases. A wrong path or placeholder can delete data irreversibly or make a server unreachable.

  • All commands are provided without warranty and are not tested on every system.
  • Understand what a command does before running it, and check every placeholder.
  • Make a backup first and, if possible, try it on a test system.
  • You run commands at your own risk. Liability for damages is excluded to the extent permitted by law.