0

I want to remove all the folders and files but except one. I have a Ubuntu server and I tried several methods and none of them worked.

This is my folder structure.

app
app/public
app/public/uploads
app/public/css
app/models
file.txt

I want to keep the app/public/uploads and delete all other files and folders.

These are the methods I tried:

find . -maxdepth 1 ! -name 'public/uploads' ! -name '.*' | xargs rm -rf

find . ! -name 'public/uploads' -type f -exec rm -f {} +
0

You can do this by using the command rm -r !(app/public/uploads). Let me know if this works.

Source:

  • I tired but it's not working – Achintha Samindika Mar 31 '16 at 9:52
  • This is working for me, try getting into app/public and use the command – manjesh23 Mar 31 '16 at 9:53

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.