Using busybox's find to delete recursively some files

How can I find and delete all .jpg? -delete doesn't seem to work...

[/share/Multimedia/Music] # find . -name '*.jpg' -delete
BusyBox v1.01 (2015.01.25-18:47+0000) multi-call binary

Usage: find [PATH...] [EXPRESSION]

Search for files in a directory hierarchy.  The default PATH is
the current directory; default EXPRESSION is '-print'

EXPRESSION may consist of:
    -follow     Dereference symbolic links.
    -name PATTERN   File name (leading directories removed) matches PATTERN.
    -print      Print (default and assumed).
    -type X     Filetype matches X (where X is one of: f,d,l,b,c,...)
    -perm PERMS Permissions match any of (+NNN); all of (-NNN); or exactly (NNN)
    -mtime TIME Modified time is greater than (+N); less than (-N); or exactly (N) days

You seem to be using Busybox find, not GNU find. While Busybox find is supposed to support -delete, the version with Ubuntu doesn't seem to.

$ busybox find --help
BusyBox v1.21.1 (Ubuntu 1:1.21.0-1ubuntu1) multi-call binary.

Usage: find [PATH]... [OPTIONS] [ACTIONS]

Search for files and perform actions on them.
First failed action stops processing of current file.
Defaults: PATH is current directory, action is '-print'

    -follow     Follow symlinks
    -xdev       Don't descend directories on other filesystems
    -maxdepth N Descend at most N levels. -maxdepth 0 applies
            actions to command line arguments only
    -mindepth N Don't act on first N levels
    -depth      Act on directory *after* traversing it

Actions:
    ( ACTIONS ) Group actions for -o / -a
    ! ACT       Invert ACT's success/failure
    ACT1 [-a] ACT2  If ACT1 fails, stop, else do ACT2
    ACT1 -o ACT2    If ACT1 succeeds, stop, else do ACT2
            Note: -a has higher priority than -o
    -name PATTERN   Match file name (w/o directory name) to PATTERN
    -iname PATTERN  Case insensitive -name
    -path PATTERN   Match path to PATTERN
    -ipath PATTERN  Case insensitive -path
    -regex PATTERN  Match path to regex PATTERN
    -type X     File type is X (one of: f,d,l,b,c,...)
    -perm MASK  At least one mask bit (+MASK), all bits (-MASK),
            or exactly MASK bits are set in file's mode
    -mtime DAYS mtime is greater than (+N), less than (-N),
            or exactly N days in the past
    -mmin MINS  mtime is greater than (+N), less than (-N),
            or exactly N minutes in the past
    -newer FILE mtime is more recent than FILE's
    -inum N     File has inode number N
    -user NAME/ID   File is owned by given user
    -group NAME/ID  File is owned by given group
    -size N[bck]    File size is N (c:bytes,k:kbytes,b:512 bytes(def.))
            +/-N: file size is bigger/smaller than N
    -links N    Number of links is greater than (+N), less than (-N),
            or exactly N
    -prune      If current file is directory, don't descend into it
If none of the following actions is specified, -print is assumed
    -print      Print file name
    -print0     Print file name, NUL terminated
    -exec CMD ARG ; Run CMD with all instances of {} replaced by
            file name. Fails if CMD exits with nonzero

I don't know why you are using Busybox find, but try using /usr/bin/find instead. Or -exec rm {} + (no support for -execdir either) or the xargs solution that Rinzwind suggests.


find . -type f -name "*.jpg" -exec rm -vf {} +

This will remove "files" (and not "directories") ending on ".jpg".

Mind though: you should NOT do this as root. A mistake in the command can kill your system and when not using root would error out on a permissions error.

There is no way back from this unless you created a backup.

If you do a

find . -type f -name "*.jpg" | more 

you will get a list of the files about to be deleted (the | more will show you the result in pages).


find . type f -name "*.jpg" -print0 | xargs -0 rm

works too. Same principle: the results are piped to the xargs command that does an rm for every file found.