0

I need to recurse a directory and delete all the files with js and map extensions.

what i currently have that does not work is

find . -name *.js -or -name *.map | xargs rm

Anything obvious wrong with this command?

4
  • firstly, debug in a safe way. Change xargs rm to xargs echo and validate your output. Secondly, try the actual command from the command line before you go and alias it. So run that find command in the shell and see what you get. You should see the names of all the files that it finds. If empty, you have issues with the filenames or no files. Commented Oct 12, 2017 at 22:34
  • find command is the problem, it returns nothing. I should not have included the alias at all. I will update the question Commented Oct 12, 2017 at 22:35
  • Find command works in my shell on files ending in .py of which I have lots. The issue is not the command, but rather what it is working on. Commented Oct 12, 2017 at 22:36
  • 1
    Until now I hadn't realized that -o can also be written as -or (same for -a and -and). But the longer forms seem to be GNU extensions, not mandated by POSIX, so it might be safer to use -o. Commented Oct 12, 2017 at 22:44

1 Answer 1

3

The shell is probably expanding the arguments to find. Quote them:

find . \( -name '*.js' -or -name '*.map' \) -delete
Sign up to request clarification or add additional context in comments.

1 Comment

Note that (depending on your shell and settings) the original command will likely work if there happen to be no matching files in the current directory.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.