'How to delete all files and folders in a directory besides 3 files using terminal
I am trying to delete all the files and folders in a specific location on my Raspberry Pi except for .env, ., and ...
This seems to work:
find ~/my/app/here/. ! -name '.env' -type f,d -exec rm -rf {} +
With the exception of getting a message after saying that rm: refusing to remove '.' or '..' directory: skipping '/home/pi/my/app/here/.'
How would I be able to delete everything in that folder except for my .env without getting the message above, or add . and .. into my command?
Solution 1:[1]
Looks like I figured out the answer to my own question...
find ~/my/app/here/. ! -name '.env' ! -name '.' ! -name '..' -type f,d -delete
I was unaware that you could tag on multiple ! -name 'whatever' to each other, but it makes sense.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | scapegoat17 |
