Title: WordPress CLI Command Assistance
Last modified: December 5, 2023

---

# WordPress CLI Command Assistance

 *  [development14](https://wordpress.org/support/users/development14/)
 * (@development14)
 * [2 years, 6 months ago](https://wordpress.org/support/topic/wordpress-cli-command-assistance/)
 * Hi All
 * I need to run a wordpress CLI command to delete the images and meta data from
   3 folders in wp-uploads.
   The folders are wp-uploads/2021/05, wp-uploads/2021/
   06, and wp-uploads/2021/07.Would someone be able to send through the command 
   that I need to run?Previously I was referred to the following command, but this
   deletes all postswp post delete –force $(wp post list –post_type=’attachment’–
   format=ids)Many Thanks in advance for your assistance

Viewing 4 replies - 1 through 4 (of 4 total)

 *  [Harsh Gajipara](https://wordpress.org/support/users/harshgajipara/)
 * (@harshgajipara)
 * [2 years, 6 months ago](https://wordpress.org/support/topic/wordpress-cli-command-assistance/#post-17256645)
 * Hi [@development14](https://wordpress.org/support/users/development14/),
   To delete
   specific images and their metadata from certain folders in the wp-uploads directory
   using WP-CLI, you can use a combination of WP-CLI commands with Unix commands.
   WP-CLI doesn’t have a built-in command specifically for deleting media files 
   by directory or folder, so we’ll need to use a workaround.Here’s an example command
   you can use:
 *     ```wp-block-code
       cd /path/to/your/wordpress/installation/wp-content/uploads
   
       # Delete images and metadata in wp-uploads/2021/05
       wp media delete $(wp media list --field=ID --path=2021/05)
   
       # Delete images and metadata in wp-uploads/2021/06
       wp media delete $(wp media list --field=ID --path=2021/06)
   
       # Delete images and metadata in wp-uploads/2021/07
       wp media delete $(wp media list --field=ID --path=2021/07)
       ```
   
 * Make sure to replace /path/to/your/wordpress/installation/ with the actual path
   to your WordPress installation directory.
 * Thanks!
 *  Thread Starter [development14](https://wordpress.org/support/users/development14/)
 * (@development14)
 * [2 years, 6 months ago](https://wordpress.org/support/topic/wordpress-cli-command-assistance/#post-17259612)
 * Thank you Harsh, that’s great, will run those shortly and keep you posted
 *  Thread Starter [development14](https://wordpress.org/support/users/development14/)
 * (@development14)
 * [2 years, 6 months ago](https://wordpress.org/support/topic/wordpress-cli-command-assistance/#post-17259641)
 * Hi Harsh, I believe I have the correct path to folder, but it says that the file
   isn’t found?
   I have navigated to the folders /uploads/, /2021/ and /05/ but none
   of them have worked?
 * Here is the message I have received each time?
 * wp media delete $(wp media list –field=ID –path=2021/05)
 * -bash: /home/inekyjxs/wp-cli/bin/wp: No such file or directory
 * -bash: /home/inekyjxs/wp-cli/bin/wp: No such file or directory
 * /home/serverusername/public_html/wp-content/uploads is the path I am in
 *  Thread Starter [development14](https://wordpress.org/support/users/development14/)
 * (@development14)
 * [2 years, 6 months ago](https://wordpress.org/support/topic/wordpress-cli-command-assistance/#post-17262797)
 * [@harshgajipara](https://wordpress.org/support/users/harshgajipara/) In case 
   you get a chance to reply, thanks again for your initial post

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘WordPress CLI Command Assistance’ is closed to new replies.

## Tags

 * [wp-cli](https://wordpress.org/support/topic-tag/wp-cli/)

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 4 replies
 * 2 participants
 * Last reply from: [development14](https://wordpress.org/support/users/development14/)
 * Last activity: [2 years, 6 months ago](https://wordpress.org/support/topic/wordpress-cli-command-assistance/#post-17262797)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
