2

Suppose I have a directory structure like this:

projects/ project1/ src/ node_modules/ dir1/ dir2/ dir3/ file project2/ node_modules/ dir4/ 

Starting from projects/ I want to delete the contents of all node_modules/ directories, but I do not want to delete the node_modules/ itself, leaving it empty, without folders or files inside.

In the example above the items dir1, dir2, dir3, file and dir4 would be deleted.

1 Answer 1

5

The following will delete all files and directories within a path matching node_modules:

find . -path '*/node_modules/*' -delete 

If you would like to check what will be deleted first, then omit the -delete action.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.