The command find . -type f -name '*.jpg' -delete deletes everything within the current directory and recursively deletes the files from there.

What needs to be updated within this command so that it just removes all files within a specified directory e.g. /users/user/desktop?


The find command takes its first argument(s) as director(ies) in which to perform its action.

A single dot . represents the current directory.  (Two dots .. represents the parent directory.)  That means your command deletes all files with a .jpg suffix in (and under) the current directory.

To delete all files with a .jpg suffix in another directory, for example, /Users/username/Desktop, you'll simply use

find /Users/username/Desktop -type f -name '*.jpg' -delete
This will also affect all sub-directories.

Add option -maxdepth to limit sub-directory levels. The command

find /Users/username/Desktop -maxdepth 1 -type f -name '*.jpg' -delete
deletes files with the jpg extension from the Desktop folder only; it doesn't access folders inside (below) the Desktop.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.